Fix link rewriting in -set-annotations

This commit is contained in:
John Whitington 2023-09-19 13:43:21 +01:00
parent a161cd035c
commit 268e80ea9e
3 changed files with 8 additions and 7 deletions

View File

@ -1,4 +1,4 @@
(** A loose JSON equivalent of XFDF. *) (** A loose JSON equivalent of XFDF for annotations. *)
open Pdfutil open Pdfutil
open Cpdferror open Cpdferror
@ -29,8 +29,10 @@ let list_annotations range encoding pdf =
(* New, JSON style *) (* New, JSON style *)
let rewrite_destination f d = let rewrite_destination f d =
match d with 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 (f i)::r)
| Pdf.Array (Pdf.Integer i::r) -> (* in *)
Pdf.Array (Pdf.Indirect (f i)::r)
| x -> x | x -> x
let rewrite_destinations f pdf annot = let rewrite_destinations f pdf annot =
@ -127,7 +129,7 @@ let get_annotations_json pdf range =
in in
let header = let header =
`List `List
[`Int 0; [`Int ~-1;
Cpdfjson.json_of_object ~utf8:true ~clean_strings:true pdf (fun _ -> ()) Cpdfjson.json_of_object ~utf8:true ~clean_strings:true pdf (fun _ -> ())
~no_stream_data:false ~parse_content:false ~no_stream_data:false ~parse_content:false
(Pdf.Dictionary ["/CPDFJSONannotformatversion", Pdf.Integer 1])] (Pdf.Dictionary ["/CPDFJSONannotformatversion", Pdf.Integer 1])]
@ -187,9 +189,8 @@ let set_annotations_json pdf i =
(fun pagenum page -> (fun pagenum page ->
let forthispage = flatten (keep (function (p, _, _)::t when p = pagenum -> true | _ -> false) annotsforeachpage) in let forthispage = flatten (keep (function (p, _, _)::t when p = pagenum -> true | _ -> false) annotsforeachpage) in
iter iter
(fun (pnum, i, o) -> (fun (_, i, o) ->
let pageobjnum = match lookup pnum pageobjnummap with Some x -> x | None -> 0 in let f = fun pnum -> match lookup pnum pageobjnummap with Some x -> x | None -> pnum in
let f = fun pnum -> if pageobjnum = 0 then pnum else pageobjnum in
Pdf.addobj_given_num pdf (i, rewrite_destinations f pdf (Cpdfjson.object_of_json o))) Pdf.addobj_given_num pdf (i, rewrite_destinations f pdf (Cpdfjson.object_of_json o)))
forthispage; forthispage;
if forthispage = [] then page else if forthispage = [] then page else

Binary file not shown.

View File

@ -2858,7 +2858,7 @@ annotations on the selected pages to standard output. Each annotation is precede
] ]
\end{verbatim}} \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} \section{Setting annotations}