From c122df5dc592b0d4f9364f728ad31dfd80248608 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Tue, 8 Jun 2021 16:58:35 +0100 Subject: [PATCH] ocg list split --- cpdf.ml | 12 +++++++++--- cpdf.mli | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cpdf.ml b/cpdf.ml index 07d7c3f..7a3ec84 100644 --- a/cpdf.ml +++ b/cpdf.ml @@ -4459,8 +4459,9 @@ let ocg_coalesce pdf = pdf.Pdf.root <- new_catalog; Pdf.objselfmap (Pdf.renumber_object_parsed pdf (hashtable_of_dictionary changes)) pdf -let ocg_list pdf = - match Pdf.lookup_direct pdf "/OCProperties" (Pdf.catalog_of_pdf pdf) with +let ocg_get_list pdf = + let l = ref [] in + begin match Pdf.lookup_direct pdf "/OCProperties" (Pdf.catalog_of_pdf pdf) with None -> () | Some ocpdict -> match Pdf.lookup_direct pdf "/OCGs" ocpdict with @@ -4469,10 +4470,15 @@ let ocg_list pdf = (function Pdf.Indirect i -> (match Pdf.lookup_direct pdf "/Name" (Pdf.lookup_obj pdf i) with - Some (Pdf.String s) -> Printf.printf "%s\n" s | _ -> ()) + Some (Pdf.String s) -> l := s::!l | _ -> ()) | _ -> ()) elts | _ -> () + end; + rev !l + +let ocg_list pdf = + List.iter (Printf.printf "%s\n") (ocg_get_list pdf) let ocg_rename f t pdf = Pdf.objselfmap diff --git a/cpdf.mli b/cpdf.mli index 32be12c..d7e4d0a 100644 --- a/cpdf.mli +++ b/cpdf.mli @@ -459,6 +459,8 @@ val append_page_content : string -> bool -> bool -> int list -> Pdf.t -> Pdf.t val ocg_coalesce : Pdf.t -> unit +val ocg_get_list : Pdf.t -> string list + val ocg_list : Pdf.t -> unit val ocg_rename : string -> string -> Pdf.t -> unit