From 014c92bddef7437ee783e166207adb3f12fc447b Mon Sep 17 00:00:00 2001 From: John Whitington Date: Tue, 18 Apr 2023 17:09:21 +0100 Subject: [PATCH] more --- cpdfannot.ml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cpdfannot.ml b/cpdfannot.ml index c9f17c3..9869e7b 100644 --- a/cpdfannot.ml +++ b/cpdfannot.ml @@ -209,11 +209,20 @@ let set_annotations_json pdf i = (* Find largest negative objnumber. Then add number of annot objects. *) match json with | `List entries -> + (* Renumber the PDF so everything has bigger object numbers than that. *) let maxobjnum = - fold_left max min_int (map (fun e -> match e with `List (`Int i::_) -> abs i | _ -> error "Bad annots JSON entry") entries) + fold_left + max + min_int + (map (fun e -> match e with `List (`Int i::_) -> abs i | _ -> error "Bad annots entry") entries) in - (* Renumber the PDF so everything has bigger object numbers than that. *) - Printf.printf "maxobjnum = %i\n" maxobjnum; + let pdf_objnums = + map fst (list_of_hashtbl pdf.Pdf.objects.Pdf.pdfobjects) + in + 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 () | _ -> error "Bad Annotations JSON file"