Combine pages now used the new renamer

This commit is contained in:
John Whitington 2016-03-30 14:50:54 +01:00
parent a0ebbb6648
commit 5b6cb59725
1 changed files with 25 additions and 21 deletions

46
cpdf.ml
View File

@ -2289,19 +2289,28 @@ let equalize_pages under over =
let report_pdf_size pdf = let report_pdf_size pdf =
Pdf.remove_unreferenced pdf; Pdf.remove_unreferenced pdf;
Pdfwrite.pdf_to_file pdf "temp.pdf"; Pdfwrite.pdf_to_file_options ~preserve_objstm:false ~generate_objstm:false
~compress_objstm:false false None false pdf "temp.pdf";
let fh = open_in_bin "temp.pdf" in let fh = open_in_bin "temp.pdf" in
Printf.printf "Size %i bytes\n" (in_channel_length fh); Printf.printf "Size %i bytes\n" (in_channel_length fh);
flush stdout; flush stdout;
close_in fh close_in fh
let combine_pages (fast : bool) under over scaletofit swap equalize = let combine_pages (fast : bool) under over scaletofit swap equalize =
Printf.printf "combine_pages: fast = %b\n" fast; (*Printf.printf "combine_pages: fast = %b\n" fast;
flush stdout; flush stdout;
Printf.printf "Under size\n"; Printf.printf "Under size\n";
report_pdf_size under; report_pdf_size under;
Printf.printf "Over size\n"; Printf.printf "Over size\n";
report_pdf_size over; report_pdf_size over;*)
let prefix = Pdfpage.shortest_unused_prefix under in
(*Printf.printf "prefix was %s\n" prefix;*)
Pdfpage.add_prefix over prefix;
(*Printf.printf "added prefix\n";
Printf.printf "under now:\n";
report_pdf_size under;
Printf.printf "over now:\n";
report_pdf_size over;*)
let marks_under = Pdfmarks.read_bookmarks under in let marks_under = Pdfmarks.read_bookmarks under in
let marks_over = Pdfmarks.read_bookmarks over in let marks_over = Pdfmarks.read_bookmarks over in
let under, over = if equalize then equalize_pages under over else under, over in let under, over = if equalize then equalize_pages under over else under, over in
@ -2312,38 +2321,33 @@ let combine_pages (fast : bool) under over scaletofit swap equalize =
in let pageseqs_over = ilist 1 (Pdfpage.endpage over) in in let pageseqs_over = ilist 1 (Pdfpage.endpage over) in
let merged = let merged =
Pdfmerge.merge_pdfs false false ["a"; "b"] [under; over] [pageseqs_under; pageseqs_over] in Pdfmerge.merge_pdfs false false ["a"; "b"] [under; over] [pageseqs_under; pageseqs_over] in
Printf.printf "merged\n"; (*Printf.printf "merged\n";
flush stdout; flush stdout;
report_pdf_size merged; report_pdf_size merged;*)
let renamed_pdf =
Pdfpage.change_pages true
merged (Pdfpage.renumber_pages merged (Pdfpage.pages_of_pagetree merged))
in
Printf.printf "renamed\n";
flush stdout;
report_pdf_size renamed_pdf;
let under_pages, over_pages = let under_pages, over_pages =
cleave (Pdfpage.pages_of_pagetree renamed_pdf) under_length cleave (Pdfpage.pages_of_pagetree merged) under_length
in in
let new_pages = let new_pages =
map2 map2
(fun o u -> (fun o u ->
do_stamp false fast (BottomLeft 0.) false false scaletofit (not swap) renamed_pdf o u over) do_stamp
false fast (BottomLeft 0.) false false scaletofit (not swap)
merged o u over)
over_pages over_pages
under_pages under_pages
in in
Printf.printf "stamped\n"; (*Printf.printf "stamped\n";
flush stdout; flush stdout;*)
let r = let r =
let changed = Pdfpage.change_pages true renamed_pdf new_pages let changed = Pdfpage.change_pages true merged new_pages
in in
Printf.printf "pages changed\n"; (*Printf.printf "pages changed\n";
flush stdout; flush stdout;*)
Pdfmarks.add_bookmarks (marks_under @ marks_over) changed Pdfmarks.add_bookmarks (marks_under @ marks_over) changed
in in
report_pdf_size r; (*report_pdf_size r;
Printf.printf "bookmarks added\n"; Printf.printf "bookmarks added\n";
flush stdout; flush stdout;*)
r r
let nobble_page pdf _ page = let nobble_page pdf _ page =