diff --git a/Changes b/Changes index e5e98c9..3d04563 100644 --- a/Changes +++ b/Changes @@ -1,7 +1,9 @@ 2.5 (Upcoming 2022) -o -debug-force now properly documented as -decrypt-force -o Switch to Yojson +o New operation -impose for document imposition +o New option -collate to collate page during merges +o Option -debug-force now properly documented as -decrypt-force +o Switch to Yojson for faster/better JSON input/output o Can read as well as write PDFs in JSON format with -j o Environment variable CPDF_REPRODUCIBLE_DATES for testing o Environment variable CPDF_DEBUG for -debug diff --git a/cpdf.ml b/cpdf.ml index 2dfd20b..5c92f55 100644 --- a/cpdf.ml +++ b/cpdf.ml @@ -2860,22 +2860,32 @@ let impose_pages n x y columns rtl btt center margin spacing linewidth mediabox' (* FIXME impose to use cropbox by default? See what happens with cropbox above. Clarify? Also point to hardbox. *) let impose ~x ~y ~fit ~columns ~rtl ~btt ~center ~margin ~spacing ~linewidth ~fast pdf = - Printf.printf + (*Printf.printf "impose: x = %f, y = %f, fit = %b, columns = %b, rtl = %b, btt = %b, center = %b, margin = %f, spacing = %f, linewidth = %f, fast = %b\n" - x y fit columns rtl btt center margin spacing linewidth fast; - let n = int_of_float x * int_of_float y in + x y fit columns rtl btt center margin spacing linewidth fast;*) + let endpage = Pdfpage.endpage pdf in + let ix = int_of_float x in + let iy = int_of_float y in + let n, ix, iy = + if ix = 0 && iy = 0 then error "impose-xy: both dimensions cannot be zero" else + if ix = 0 then (endpage, endpage, 1) + else if iy = 0 then (endpage, 1, endpage) + else (ix * iy, ix, iy) + in let firstpage = hd (Pdfpage.pages_of_pagetree pdf) in let mediabox' = if fit then Pdf.Array [Pdf.Real 0.; Pdf.Real 0.; Pdf.Real x; Pdf.Real y] else let _, _, w, h = Pdf.parse_rectangle firstpage.Pdfpage.mediabox in - Pdf.Array [Pdf.Real 0.; Pdf.Real 0.; Pdf.Real (w *. x); Pdf.Real (h *. y)] + if x = 0.0 then Pdf.Array [Pdf.Real 0.; Pdf.Real 0.; Pdf.Real (w *. float_of_int endpage); Pdf.Real h] + else if y = 0.0 then Pdf.Array [Pdf.Real 0.; Pdf.Real 0.; Pdf.Real w; Pdf.Real (h *. float_of_int endpage)] + else Pdf.Array [Pdf.Real 0.; Pdf.Real 0.; Pdf.Real (w *. x); Pdf.Real (h *. y)] in - let pagenums = ilist 1 (Pdfpage.endpage pdf) in + let pagenums = ilist 1 endpage in let pdf = upright pagenums pdf in let pages = Pdfpage.pages_of_pagetree pdf in let pagesets = splitinto n pages in let renumbered = map (Pdfpage.renumber_pages pdf) pagesets in - let pages' = map (impose_pages n x y columns rtl btt center margin spacing linewidth mediabox' fast pdf) renumbered in + let pages' = map (impose_pages n (float_of_int ix) (float_of_int iy) columns rtl btt center margin spacing linewidth mediabox' fast pdf) renumbered in let changes = map (fun x -> (x, (x + (n - 1)) / n)) pagenums in Pdfpage.change_pages ~changes true pdf pages' diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 0b7f62e..2c264b7 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -4033,6 +4033,7 @@ let go () = | Some Impose fit -> let pdf = get_single_pdf args.op false in let x, y = Cpdfcoord.parse_coordinate pdf args.coord in + if not fit && (x < 0.0 || y < 0.0) then error "Negative imposition parameters not allowed." else write_pdf false (Cpdf.impose x y fit args.impose_columns args.impose_rtl args.impose_btt args.impose_center args.impose_margin args.impose_spacing args.impose_linewidth args.fast pdf) diff --git a/cpdfmanual.tex b/cpdfmanual.tex index 1b92232..c167227 100644 --- a/cpdfmanual.tex +++ b/cpdfmanual.tex @@ -1,7 +1,7 @@ %Document the new JSON format, -j and new -output-json options %Document -decrypt-force %Document -collate -%Document -impose and friends +%Document -impose and friends (inc. 0-w, 0-h for long ones) \documentclass{book} % Edit here to produce cpdfmanual.pdf, cpdflibmanual.pdf, pycpdfmanual.pdf etc.