diff --git a/cpdftweak.ml b/cpdftweak.ml index 4e2ba3d..0136df7 100644 --- a/cpdftweak.ml +++ b/cpdftweak.ml @@ -231,9 +231,6 @@ let append_page_content_page fast s before pdf n page = let append_page_content s before fast range pdf = Cpdfpage.process_pages (Cpdfutil.ppstub (append_page_content_page fast s before pdf)) pdf range - -(* 1. Extend remove_dict_entry with search term - 2. Implement replace_dict_entry by analogy to remove_dict_entry *) let rec dict_entry_single_object f pdf = function | (Pdf.Dictionary d) -> f (Pdf.recurse_dict (dict_entry_single_object f pdf) d) | (Pdf.Stream {contents = (Pdf.Dictionary dict, data)}) -> @@ -279,6 +276,19 @@ let print_dict_entry pdf key = Pdf.objselfmap (dict_entry_single_object f pdf) pdf; pdf.Pdf.trailerdict <- dict_entry_single_object f pdf pdf.Pdf.trailerdict +(* For cpdflib. *) +let get_dict_entries pdf key = + let es = ref [] in + let f d = + match Pdf.lookup_direct pdf key d with + | Some v -> es := Cpdfjson.json_of_object ~clean_strings:true pdf (fun _ -> ()) false false v::!es; d + | None -> d + in + Pdf.objselfmap (dict_entry_single_object f pdf) pdf; + pdf.Pdf.trailerdict <- dict_entry_single_object f pdf pdf.Pdf.trailerdict; + let arr = `List (rev !es) in + (Pdfio.bytes_of_string (Cpdfyojson.Safe.to_string arr)) + let remove_clipping_ops pdf resources content = let ops = Pdfops.parse_operators pdf resources content in let rec process a = function diff --git a/cpdftweak.mli b/cpdftweak.mli index d25f567..c89b26e 100644 --- a/cpdftweak.mli +++ b/cpdftweak.mli @@ -24,6 +24,9 @@ val replace_dict_entry : Pdf.t -> string -> Pdf.pdfobject -> Pdf.pdfobject optio (** Print a dictionary entry. *) val print_dict_entry : Pdf.t -> string -> unit +(** Get dictionary entries in JSON format *) +val get_dict_entries : Pdf.t -> string -> Pdfio.bytes + (** Remove clipping. *) val remove_clipping : Pdf.t -> int list -> Pdf.t