diff --git a/cpdfannot.ml b/cpdfannot.ml index bef91a0..cc2f7b2 100644 --- a/cpdfannot.ml +++ b/cpdfannot.ml @@ -1,4 +1,4 @@ -(** A loose JSON equivalent of XFDF. *) +(** A loose JSON equivalent of XFDF for annotations. *) open Pdfutil open Cpdferror @@ -29,8 +29,10 @@ let list_annotations range encoding pdf = (* New, JSON style *) let rewrite_destination f d = match d with - | Pdf.Array (Pdf.Indirect i::r) -> + | Pdf.Array (Pdf.Indirect i::r) -> (* out *) Pdf.Array (Pdf.Integer (f i)::r) + | Pdf.Array (Pdf.Integer i::r) -> (* in *) + Pdf.Array (Pdf.Indirect (f i)::r) | x -> x let rewrite_destinations f pdf annot = @@ -127,7 +129,7 @@ let get_annotations_json pdf range = in let header = `List - [`Int 0; + [`Int ~-1; Cpdfjson.json_of_object ~utf8:true ~clean_strings:true pdf (fun _ -> ()) ~no_stream_data:false ~parse_content:false (Pdf.Dictionary ["/CPDFJSONannotformatversion", Pdf.Integer 1])] @@ -187,9 +189,8 @@ let set_annotations_json pdf i = (fun pagenum page -> let forthispage = flatten (keep (function (p, _, _)::t when p = pagenum -> true | _ -> false) annotsforeachpage) in iter - (fun (pnum, i, o) -> - let pageobjnum = match lookup pnum pageobjnummap with Some x -> x | None -> 0 in - let f = fun pnum -> if pageobjnum = 0 then pnum else pageobjnum in + (fun (_, i, o) -> + let f = fun pnum -> match lookup pnum pageobjnummap with Some x -> x | None -> pnum in Pdf.addobj_given_num pdf (i, rewrite_destinations f pdf (Cpdfjson.object_of_json o))) forthispage; if forthispage = [] then page else diff --git a/cpdfmanual.pdf b/cpdfmanual.pdf index 53c6214..5a39437 100644 Binary files a/cpdfmanual.pdf and b/cpdfmanual.pdf differ diff --git a/cpdfmanual.tex b/cpdfmanual.tex index 8fdd2e4..c18b0ef 100644 --- a/cpdfmanual.tex +++ b/cpdfmanual.tex @@ -2858,7 +2858,7 @@ annotations on the selected pages to standard output. Each annotation is precede ] \end{verbatim}} -\noindent Extra objects required for annotations, but which are not annotations themselves are also extracted. They omit the page number, being just a pair of the object number and annotation. The CPDFJSON format is described on page \pageref{cpdfjson}. +\noindent Extra objects required for annotations, but which are not annotations themselves are also extracted. They omit the page number, being just a pair of the object number and object. The CPDFJSON format is described on page \pageref{cpdfjson}. \section{Setting annotations}