diff --git a/cpdfcommand.ml b/cpdfcommand.ml index ce03543..2c5e930 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -3566,7 +3566,7 @@ let write_json output pdf = (* 1. Get list of indirects of all OCGs from the /OCProperties, and their textual names * 2. Calculate a change list to coalesce them - * 3. Remove any changed ones from the /OCGs and /Order in /OCProperties + * 3. Remove any changed ones from the /OCGs and /Order and /ON and /OFF in /OCProperties * 4. Do the changes to all indirect references in the whole pdf *) (*FIXME Pre-existing nulls - what to do? *) let ocg_coalesce pdf = @@ -3599,14 +3599,14 @@ let ocg_coalesce pdf = end | _ -> failwith "Malformed or missing /OCGs" in - iter (fun (num, name) -> Printf.printf "%i = %s\n" num name) number_name_pairs; + (*iter (fun (num, name) -> Printf.printf "%i = %s\n" num name) number_name_pairs;*) let changes = let cf (_, name) (_, name') = compare name name' in let sets = collate cf (List.stable_sort cf number_name_pairs) in flatten (option_map (function [] -> None | (hnum, _)::t -> Some (map (function (tnum, _) -> (tnum, hnum)) t)) sets) in - Printf.printf "\nChanges are:\n"; - List.iter (fun (f, t) -> Printf.printf "%i -> %i\n" f t) changes; + (*Printf.printf "\nChanges are:\n"; + List.iter (fun (f, t) -> Printf.printf "%i -> %i\n" f t) changes;*) let new_ocproperties = let remove_from_array key nums dict = match Pdf.lookup_direct pdf key dict with @@ -3627,17 +3627,18 @@ let ocg_coalesce pdf = | _ -> failwith "No /D dict in OCGProperties" in let nums = map fst changes in - Printf.printf "\nto remove:\n"; - List.iter (Printf.printf "%i ") nums; + (*Printf.printf "\nto remove:\n"; + List.iter (Printf.printf "%i ") nums;*) remove_from_array "/OCGs" nums (remove_from_array_inside_d "/ON" nums (remove_from_array_inside_d "/OFF" nums (remove_from_array_inside_d "/Order" nums ocpdict))) in - flprint (Pdfwrite.string_of_pdf new_ocproperties); + (*flprint (Pdfwrite.string_of_pdf new_ocproperties);*) let ocp_objnum = Pdf.addobj pdf new_ocproperties in - let new_catalog = Pdf.add_dict_entry (Pdf.catalog_of_pdf pdf) "/OCProperties" (Pdf.Indirect ocp_objnum) in - pdf.Pdf.trailerdict <- Pdf.add_dict_entry pdf.Pdf.trailerdict "/Root" new_catalog; + let new_catalog = Pdf.addobj pdf (Pdf.add_dict_entry (Pdf.catalog_of_pdf pdf) "/OCProperties" (Pdf.Indirect ocp_objnum)) in + pdf.Pdf.trailerdict <- Pdf.add_dict_entry pdf.Pdf.trailerdict "/Root" (Pdf.Indirect new_catalog); + pdf.Pdf.root <- new_catalog; Pdf.objselfmap (Pdf.renumber_object_parsed pdf (hashtable_of_dictionary changes)) pdf; pdf