Reworking of -copy-annotations
This commit is contained in:
parent
db170b428b
commit
32f62797b6
21
cpdf.ml
21
cpdf.ml
|
@ -2647,12 +2647,20 @@ let equalise_lengths a b =
|
|||
in
|
||||
a', b
|
||||
|
||||
(* \section{Copy annotations} *)
|
||||
let copy_annotations range frompdf topdf =
|
||||
let frompdf, topdf = equalise_lengths frompdf topdf in
|
||||
(* Copy annotations *)
|
||||
let copy_annotations_page topdf frompdf frompage topage =
|
||||
match Pdf.lookup_direct frompdf "/Annots" frompage.Pdfpage.rest with
|
||||
| Some ((Pdf.Array frompage_annots) as annots) ->
|
||||
Some (Pdf.Array frompage_annots as annots) ->
|
||||
(* Rewrite any annotation destinations to point to pages in the
|
||||
destination file. This prevents pages being copied, and ensures the
|
||||
links are correct *)
|
||||
List.iter
|
||||
(function
|
||||
x ->
|
||||
Printf.printf "Copying annotation %s which is\n%s\n"
|
||||
(Pdfwrite.string_of_pdf x)
|
||||
(Pdfwrite.string_of_pdf (Pdf.direct frompdf x)))
|
||||
frompage_annots;
|
||||
let objects_to_copy = Pdf.objects_referenced [] [] frompdf annots in
|
||||
iter
|
||||
(fun n ->
|
||||
|
@ -2671,7 +2679,9 @@ let copy_annotations range frompdf topdf =
|
|||
topdf, topage'
|
||||
| Some x -> topdf, topage
|
||||
| None -> topdf, topage
|
||||
in
|
||||
|
||||
let copy_annotations range frompdf topdf =
|
||||
let frompdf, topdf = equalise_lengths frompdf topdf in
|
||||
match Pdf.renumber_pdfs [frompdf; topdf] with
|
||||
| [frompdf; topdf] ->
|
||||
let frompdf_pages = Pdfpage.pages_of_pagetree frompdf
|
||||
|
@ -2685,6 +2695,7 @@ let copy_annotations range frompdf topdf =
|
|||
while not (isnull !frompdf_pages) do
|
||||
let frompdf_page = hd !frompdf_pages
|
||||
and topdf_page = hd !topdf_pages in
|
||||
Printf.printf "Page %i...\n" !pnum;
|
||||
let pdf', page =
|
||||
if mem !pnum range
|
||||
then copy_annotations_page !pdf frompdf frompdf_page topdf_page
|
||||
|
|
Loading…
Reference in New Issue