This commit is contained in:
John Whitington 2023-04-21 16:22:57 +01:00
parent d596c381d4
commit b124c8362d
3 changed files with 14 additions and 8 deletions

View File

@ -150,7 +150,7 @@ let get_annotations_json pdf =
(** Set annotations from JSON, keeping any existing ones. *) (** Set annotations from JSON, keeping any existing ones. *)
let set_annotations_json pdf i = let set_annotations_json pdf i =
let module J = Cpdfyojson.Safe in 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 let json = J.from_string content in
(* Find largest negative objnumber. Then add number of annot objects. *) (* Find largest negative objnumber. Then add number of annot objects. *)
match json with match json with
@ -169,11 +169,17 @@ let set_annotations_json pdf i =
let change_table = let change_table =
hashtable_of_dictionary (map2 (fun f t -> (f, t)) pdf_objnums (ilist (maxobjnum + 1) (maxobjnum + length pdf_objnums))) hashtable_of_dictionary (map2 (fun f t -> (f, t)) pdf_objnums (ilist (maxobjnum + 1) (maxobjnum + length pdf_objnums)))
in in
let pdf = Pdf.renumber change_table pdf in let pdf' = Pdf.renumber change_table pdf in
(* 1. Rewrite all serial numbers in all places (annots and extra objects?) *) pdf.root <- pdf'.root;
(* 2. Add all the negative numbered objects straight to the file *) pdf.objects <- pdf'.objects;
(* 3. Add all the actual annotations to the /Annots array on each page *) 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" | _ -> error "Bad Annotations JSON file"
let copy_annotations range frompdf topdf = () let copy_annotations range frompdf topdf = ()

View File

@ -103,7 +103,7 @@ let parse_bookmark_file_json verify pdf i =
match i.Pdfio.caml_channel with match i.Pdfio.caml_channel with
| Some ch -> J.from_channel ch | Some ch -> J.from_channel ch
| None -> | 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 J.from_string content
in in
let marks = marks_of_json pdf json in let marks = marks_of_json pdf json in

View File

@ -573,7 +573,7 @@ let of_input i =
| Some ch -> | Some ch ->
pdf_of_json (J.from_channel ch) pdf_of_json (J.from_channel ch)
| None -> | 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) pdf_of_json (J.from_string content)
with with
e -> error (Printexc.to_string e) e -> error (Printexc.to_string e)