mirror of
https://github.com/johnwhitington/cpdf-source.git
synced 2025-06-05 22:09:39 +02:00
more
This commit is contained in:
36
cpdfutil.ml
Normal file
36
cpdfutil.ml
Normal file
@@ -0,0 +1,36 @@
|
||||
open Pdfutil
|
||||
|
||||
(* These may move into CamlPDF at some point *)
|
||||
let process_xobject f pdf resources i =
|
||||
let xobj = Pdf.lookup_obj pdf i in
|
||||
match Pdf.lookup_direct pdf "/Subtype" xobj with
|
||||
| None -> raise (Pdf.PDFError "No /Subtype in Xobject")
|
||||
| Some (Pdf.Name "/Form") ->
|
||||
Pdf.getstream xobj;
|
||||
begin match xobj with
|
||||
| Pdf.Stream ({contents = Pdf.Dictionary dict, Pdf.Got bytes} as rf) ->
|
||||
begin match f pdf resources [Pdf.Stream rf] with
|
||||
| [Pdf.Stream {contents = (Pdf.Dictionary dict', data)}] ->
|
||||
let dict' =
|
||||
Pdf.remove_dict_entry
|
||||
(Pdf.Dictionary (mergedict dict dict'))
|
||||
"/Filter"
|
||||
in
|
||||
rf := (dict', data)
|
||||
| _ -> assert false
|
||||
end
|
||||
| _ -> assert false (* getstream would have complained already *)
|
||||
end
|
||||
| Some _ -> ()
|
||||
|
||||
let process_xobjects pdf page f =
|
||||
match Pdf.lookup_direct pdf "/XObject" page.Pdfpage.resources with
|
||||
| Some (Pdf.Dictionary elts) ->
|
||||
iter
|
||||
(fun (k, v) ->
|
||||
match v with
|
||||
| Pdf.Indirect i -> process_xobject f pdf page.Pdfpage.resources i
|
||||
| _ -> raise (Pdf.PDFError "process_xobject"))
|
||||
elts
|
||||
| _ -> ()
|
||||
|
Reference in New Issue
Block a user