From b124c8362df8cc475e46ce80599dbb75b14bd8e7 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Fri, 21 Apr 2023 16:22:57 +0100 Subject: [PATCH] more --- cpdfannot.ml | 18 ++++++++++++------ cpdfbookmarks.ml | 2 +- cpdfjson.ml | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/cpdfannot.ml b/cpdfannot.ml index b512ae4..5f4803a 100644 --- a/cpdfannot.ml +++ b/cpdfannot.ml @@ -150,7 +150,7 @@ let get_annotations_json pdf = (** Set annotations from JSON, keeping any existing ones. *) let set_annotations_json pdf i = let module J = Cpdfyojson.Safe in - let content = Pdfio.string_of_bytes (Pdfio.bytes_of_input i 0 i.Pdfio.in_channel_length) in + let content = Pdfio.string_of_input i in let json = J.from_string content in (* Find largest negative objnumber. Then add number of annot objects. *) match json with @@ -169,11 +169,17 @@ let set_annotations_json pdf i = let change_table = hashtable_of_dictionary (map2 (fun f t -> (f, t)) pdf_objnums (ilist (maxobjnum + 1) (maxobjnum + length pdf_objnums))) in - let pdf = Pdf.renumber change_table pdf in - (* 1. Rewrite all serial numbers in all places (annots and extra objects?) *) - (* 2. Add all the negative numbered objects straight to the file *) - (* 3. Add all the actual annotations to the /Annots array on each page *) - () + let pdf' = Pdf.renumber change_table pdf in + pdf.root <- pdf'.root; + pdf.objects <- pdf'.objects; + pdf.trailerdict <- pdf'.trailerdict; + (* 1. Extract the extra objects, and add them to the file *) + let extras = + () + in + (* 2. Extract the annotation objects, and rewrite their destinations from page numbers to pages, add them to file *) + (* 3. Add the annots entries to each file *) + () | _ -> error "Bad Annotations JSON file" let copy_annotations range frompdf topdf = () diff --git a/cpdfbookmarks.ml b/cpdfbookmarks.ml index e4ad6ca..550fc1c 100644 --- a/cpdfbookmarks.ml +++ b/cpdfbookmarks.ml @@ -103,7 +103,7 @@ let parse_bookmark_file_json verify pdf i = match i.Pdfio.caml_channel with | Some ch -> J.from_channel ch | None -> - let content = Pdfio.string_of_bytes (Pdfio.bytes_of_input i 0 i.Pdfio.in_channel_length) in + let content = Pdfio.string_of_input i in J.from_string content in let marks = marks_of_json pdf json in diff --git a/cpdfjson.ml b/cpdfjson.ml index 792ea0e..a556bcd 100644 --- a/cpdfjson.ml +++ b/cpdfjson.ml @@ -573,7 +573,7 @@ let of_input i = | Some ch -> pdf_of_json (J.from_channel ch) | None -> - let content = Pdfio.string_of_bytes (Pdfio.bytes_of_input i 0 i.Pdfio.in_channel_length) in + let content = Pdfio.string_of_input i in pdf_of_json (J.from_string content) with e -> error (Printexc.to_string e)