diff --git a/cpdf.ml b/cpdf.ml index 9b68401..62db932 100644 --- a/cpdf.ml +++ b/cpdf.ml @@ -2063,10 +2063,26 @@ let rec insert_after_many_changes isbefore padsize offset range = function let print_changes = List.iter (fun (f, t) -> Printf.printf "%i --> %i\n" f t) -let pad_with_pdf range pdf isbefore padfile = - (* 1. Split the input pdf around the range, taking account of isbefore *) - (* 2. Build a merge after "a p b p c p" or before "p a p b p c" *) - pdf +let pad_with_pdf (range : int list) (pdf : Pdf.t) (isbefore : bool) (padfile : Pdf.t) = + let range = List.sort compare (setify range) in + let merged = + Pdfmerge.merge_pdfs + false false ["a"; "b"] [pdf; padfile] [ilist 1 (Pdfpage.endpage pdf); ilist 1 (Pdfpage.endpage padfile)] + in + let original_pages, padpages = + cleave (Pdfpage.pages_of_pagetree merged) (Pdfpage.endpage pdf) + in + let newpages = + List.map + (fun (pagenum, page) -> + if mem pagenum range then + (if isbefore then padpages @ [page] else [page] @ padpages) + else + [page]) + (combine (indx original_pages) original_pages) + in + (* FIXME Provide ~changes here? *) + Pdfpage.change_pages false merged (flatten newpages) let pad padwith range pdf isbefore = match padwith with diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 4a3fe67..1e9cbde 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -3787,7 +3787,12 @@ let go () = | [] -> [] | l -> if last l = Pdfpage.endpage pdf then all_but_last l else l in - write_pdf false (Cpdf.padafter range pdf) + let padwith = + match args.padwith with + None -> None + | Some filename -> Some (pdfread_pdf_of_file None None filename) + in + write_pdf false (Cpdf.padafter ?padwith range pdf) | Some (PadMultiple n) -> let pdf = get_single_pdf args.op false in write_pdf false (Cpdf.padmultiple n pdf) diff --git a/cpdfmanual.tex b/cpdfmanual.tex index d775f7c..7b674ec 100644 --- a/cpdfmanual.tex +++ b/cpdfmanual.tex @@ -3,6 +3,7 @@ %FIXME: Document %PageDiv2 %FIXME: Document new bookmark format %FIXME: Fix docs on -fit-window and friends +%FIXME: Document new -pad-with (for -pad-before, -pad-after, -pad-every) \documentclass{book} \usepackage{palatino} \usepackage{microtype}