Continuing with audit and fixes for used of Pdfpage.change_pages
This commit is contained in:
parent
060ae4d851
commit
e92fdeafef
46
cpdf.ml
46
cpdf.ml
|
@ -2327,7 +2327,7 @@ let stamp relative_to_cropbox position topline midline fast scale_to_fit isover
|
||||||
let over_firstpage_pdf =
|
let over_firstpage_pdf =
|
||||||
match Pdfpage.pages_of_pagetree over with
|
match Pdfpage.pages_of_pagetree over with
|
||||||
| [] -> error "empty PDF"
|
| [] -> error "empty PDF"
|
||||||
| h::_ -> Pdfpage.change_pages true over [h]
|
| h::_ -> Pdfpage.change_pages ~changes:[(1, 1)] true over [h]
|
||||||
in
|
in
|
||||||
let merged =
|
let merged =
|
||||||
Pdfmerge.merge_pdfs
|
Pdfmerge.merge_pdfs
|
||||||
|
@ -2351,19 +2351,16 @@ let stamp relative_to_cropbox position topline midline fast scale_to_fit isover
|
||||||
pageseqs
|
pageseqs
|
||||||
under_pages
|
under_pages
|
||||||
in
|
in
|
||||||
let changed = Pdfpage.change_pages true merged (new_pages @ [last new_pages]) in
|
let changed =
|
||||||
(* we use new_pages @ new_pages here to preserve the number of pages
|
let changes =
|
||||||
* so that Pdfpage.change_pages can do its renumbering properly.
|
List.map (fun x -> (x, x)) (ilist 1 (length new_pages))
|
||||||
* Otherwise things like outlines are lost. TODO: Fix
|
in
|
||||||
* Pdfpage.change_pages properly. For now, we just use
|
Pdfpage.change_pages ~changes true merged new_pages
|
||||||
* Pdfpage.pdf_of_pages afterward to chop it. *)
|
in
|
||||||
let cut =
|
let new_refnumbers = Pdf.page_reference_numbers changed in
|
||||||
Pdfpage.pdf_of_pages ~retain_numbering:true changed (ilist 1 (length new_pages))
|
let changetable = hashtable_of_dictionary (List.combine marks_refnumbers new_refnumbers) in
|
||||||
in
|
let new_marks = map (change_bookmark changetable) marks in
|
||||||
let new_refnumbers = Pdf.page_reference_numbers cut in
|
Pdfmarks.add_bookmarks new_marks changed
|
||||||
let changetable = hashtable_of_dictionary (List.combine marks_refnumbers new_refnumbers) in
|
|
||||||
let new_marks = map (change_bookmark changetable) marks in
|
|
||||||
Pdfmarks.add_bookmarks new_marks cut
|
|
||||||
|
|
||||||
(* Combine pages from two PDFs. For now, assume equal length. *)
|
(* Combine pages from two PDFs. For now, assume equal length. *)
|
||||||
|
|
||||||
|
@ -2373,14 +2370,21 @@ let equalize_pages under over =
|
||||||
let length_under = Pdfpage.endpage under in
|
let length_under = Pdfpage.endpage under in
|
||||||
let length_over = Pdfpage.endpage over in
|
let length_over = Pdfpage.endpage over in
|
||||||
if length_over > length_under then
|
if length_over > length_under then
|
||||||
under,
|
let changes =
|
||||||
(Pdfpage.change_pages true over (take (Pdfpage.pages_of_pagetree over) length_under))
|
List.map (fun x -> (x, x)) (ilist 1 length_under)
|
||||||
|
in
|
||||||
|
(under,
|
||||||
|
(Pdfpage.change_pages
|
||||||
|
~changes true over (take (Pdfpage.pages_of_pagetree over) length_under)))
|
||||||
else if length_under > length_over then
|
else if length_under > length_over then
|
||||||
under,
|
let changes =
|
||||||
Pdfpage.change_pages true
|
List.map (fun x -> (x, x)) (ilist 1 length_over)
|
||||||
over
|
in
|
||||||
(Pdfpage.pages_of_pagetree over @
|
(under,
|
||||||
(many (Pdfpage.blankpage Pdfpaper.a4) (length_under - length_over)))
|
Pdfpage.change_pages
|
||||||
|
~changes true over
|
||||||
|
(Pdfpage.pages_of_pagetree over @
|
||||||
|
(many (Pdfpage.blankpage Pdfpaper.a4) (length_under - length_over))))
|
||||||
else
|
else
|
||||||
under, over
|
under, over
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue