diff --git a/cpdfcommand.ml b/cpdfcommand.ml index c236f5c..9e09a5b 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -3593,6 +3593,11 @@ let print_version () = flprint ("cpdf " ^ (if agpl then "AGPL " else "") ^ "Version " ^ string_of_int major_version ^ "." ^ string_of_int minor_version ^ "." ^ string_of_int minor_minor_version ^ " " ^ version_date ^ "\n") +let replace_obj pdf objspec obj = + let split_chain str = map (fun x -> "/" ^ x) (tl (String.split_on_char '/' str)) in + let chain = split_chain objspec in + Pdf.replace_chain pdf chain obj + (* Main function *) let go () = check_bookmarks_mistake (); @@ -4637,7 +4642,7 @@ let go () = | Some (ReplaceObj (a, b)) -> let pdf = get_single_pdf args.op false in let pdfobj = Cpdfjson.object_of_json (Cpdfyojson.Safe.from_string b) in - Pdf.replace_obj pdf a pdfobj; + replace_obj pdf a pdfobj; write_pdf false pdf | Some (Verify standard) -> begin match standard with diff --git a/cpdfdraw.ml b/cpdfdraw.ml index e2e1d4c..da05783 100644 --- a/cpdfdraw.ml +++ b/cpdfdraw.ml @@ -770,7 +770,7 @@ let write_structure_tree pdf st = ("/K", Pdf.Array items)]) in Pdf.addobj_given_num pdf (struct_tree_root, st); - Pdf.replace_chain pdf ["/Root"] ("/StructTreeRoot", Pdf.Indirect struct_tree_root) + Pdf.replace_chain pdf ["/Root"; "/StructTreeRoot"] (Pdf.Indirect struct_tree_root) let draw ~struct_tree ~fast ~underneath ~filename ~bates ~batespad range pdf drawops = (*Printf.printf "%s\n" (string_of_drawops drawops);*) diff --git a/cpdfimage.ml b/cpdfimage.ml index 4804e07..db6530b 100644 --- a/cpdfimage.ml +++ b/cpdfimage.ml @@ -533,7 +533,7 @@ let image_of_input ?subformat ?title ~process_struct_tree fobj i = Pdf.addobj_given_num pdf (figure, Pdf.Dictionary [("/K", Pdf.Array [Pdf.Integer 0]); ("/P", Pdf.Indirect document); ("/S", Pdf.Name "/Figure"); ("/Alt", Pdf.String title)]); Pdf.addobj_given_num pdf (str, Pdf.Dictionary [("/Namespaces", Pdf.Array [Pdf.Indirect namespace]); ("/Type", Pdf.Name "/StructTreeRoot"); ("/K", Pdf.Array [Pdf.Indirect document]); ("/ParentTree", Pdf.Indirect parent_tree)]); - Pdf.replace_chain pdf ["/Root"] ("/StructTreeRoot", (Pdf.Indirect str)) + Pdf.replace_chain pdf ["/Root"; "/StructTreeRoot"] (Pdf.Indirect str) end else if process_struct_tree || subformat = Some Cpdfua.PDFUA1 then begin @@ -543,7 +543,7 @@ let image_of_input ?subformat ?title ~process_struct_tree fobj i = Pdf.addobj_given_num pdf (parent_tree, Pdf.Dictionary [("/Nums", Pdf.Array [Pdf.Integer 1; Pdf.Array [Pdf.Indirect figure]])]); Pdf.addobj_given_num pdf (figure, Pdf.Dictionary [("/K", Pdf.Array [Pdf.Integer 0]); ("/P", Pdf.Indirect str); ("/S", Pdf.Name "/Figure"); ("/Alt", Pdf.String title)]); Pdf.addobj_given_num pdf (str, Pdf.Dictionary [("/Type", Pdf.Name "/StructTreeRoot"); ("/K", Pdf.Array [Pdf.Indirect figure]); ("/ParentTree", Pdf.Indirect parent_tree)]); - Pdf.replace_chain pdf ["/Root"] ("/StructTreeRoot", (Pdf.Indirect str)) + Pdf.replace_chain pdf ["/Root"; "/StructTreeRoot"] (Pdf.Indirect str) end; let ops = (if structinfo then [Pdfops.Op_BDC ("/Figure", Pdf.Dictionary [("/MCID", Pdf.Integer 0)])] else []) diff --git a/cpdfmetadata.ml b/cpdfmetadata.ml index 1c9d159..da474eb 100644 --- a/cpdfmetadata.ml +++ b/cpdfmetadata.ml @@ -471,7 +471,7 @@ let language pdf = | _ -> None let set_language pdf s = - Pdf.replace_chain pdf ["/Root"] ("/Lang", (Pdf.String s)) + Pdf.replace_chain pdf ["/Root"; "/Lang"] (Pdf.String s) let output_xmp_info ?(json=ref [("none", `Null)]) encoding pdf = let notjson = !json = [("none", `Null)] in diff --git a/cpdftexttopdf.ml b/cpdftexttopdf.ml index fc6358d..a2fb388 100644 --- a/cpdftexttopdf.ml +++ b/cpdftexttopdf.ml @@ -171,6 +171,6 @@ let typeset ~process_struct_tree ?subformat ?title ~papersize ~font ~fontsize te if subformat = Some Cpdfua.PDFUA2 then Pdf.Indirect document else Pdf.Array topks in Pdf.addobj_given_num pdf (str, Pdf.Dictionary (stns @ [("/Type", Pdf.Name "/StructTreeRoot"); ("/K", k); ("/ParentTree", Pdf.Indirect parent_tree)])); - Pdf.replace_chain pdf ["/Root"] ("/StructTreeRoot", (Pdf.Indirect str)) + Pdf.replace_chain pdf ["/Root"; "/StructTreeRoot"] (Pdf.Indirect str) end; pdf diff --git a/cpdfua.ml b/cpdfua.ml index 11d108e..895e7d2 100644 --- a/cpdfua.ml +++ b/cpdfua.ml @@ -1610,8 +1610,8 @@ let create_pdfua1 title pagesize pages = let pdf = Cpdfmetadata.create_metadata pdf in Cpdfmetadata.set_language pdf "en-US"; let pdf = Cpdfmetadata.set_viewer_preference ("/DisplayDocTitle", Pdf.Boolean true, 0) pdf in - Pdf.replace_obj pdf "/Root/MarkInfo/Marked" (Pdf.Boolean true); - Pdf.replace_obj pdf "/Root/StructTreeRoot/Type" (Pdf.Name "/StructTreeRoot"); + Pdf.replace_chain pdf ["/Root"; "/MarkInfo"; "/Marked"] (Pdf.Boolean true); + Pdf.replace_chain pdf ["/Root"; "/StructTreeRoot"; "/Type"] (Pdf.Name "/StructTreeRoot"); let pdf = {pdf with Pdf.major = 1; Pdf.minor = 7} in mark pdf; pdf @@ -1622,8 +1622,8 @@ let create_pdfua2 title pagesize pages = let pdf = Cpdfmetadata.create_metadata pdf in Cpdfmetadata.set_language pdf "en-US"; let pdf = Cpdfmetadata.set_viewer_preference ("/DisplayDocTitle", Pdf.Boolean true, 0) pdf in - Pdf.replace_obj pdf "/Root/MarkInfo/Marked" (Pdf.Boolean true); - Pdf.replace_obj pdf "/Root/StructTreeRoot/Type" (Pdf.Name "/StructTreeRoot"); + Pdf.replace_chain pdf ["/Root"; "/MarkInfo"; "/Marked"] (Pdf.Boolean true); + Pdf.replace_chain pdf ["/Root"; "/StructTreeRoot"; "/Type"] (Pdf.Name "/StructTreeRoot"); let pdf = {pdf with Pdf.major = 2; Pdf.minor = 0} in mark2 2024 pdf; pdf