From 15842dbd36f94f2ab125be3a4ceefded7a0cab95 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Mon, 22 Jan 2024 16:36:37 +0000 Subject: [PATCH] Adds -shift-boxes --- Changes | 1 + cpdfcommand.ml | 20 +++++++++++++++++++- cpdfmanual.tex | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index 4ceabea..5d82c56 100644 --- a/Changes +++ b/Changes @@ -20,6 +20,7 @@ o Build PDF files from JBIG2 streams, including globals o Reprocess images within PDFs to further compress them o Extract streams to disk o Explore PDFs by printing objects +o Shift page boxes with -shift-boxes Extended features: diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 77e11ce..a5468e9 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -118,6 +118,7 @@ type op = | PadMultiple of int | PadMultipleBefore of int | Shift + | ShiftBoxes | Scale | ScaleToFit | ScaleContents of float @@ -260,6 +261,7 @@ let string_of_op = function | PadMultiple _ -> "PadMultiple" | PadMultipleBefore _ -> "PadMultipleBefore" | Shift -> "Shift" + | ShiftBoxes -> "ShiftBoxes" | Scale -> "Scale" | ScaleToFit -> "ScaleToFit" | ScaleContents _ -> "ScaleContents" @@ -907,7 +909,7 @@ let banned banlist = function | Rotateby _ | Upright | VFlip | HFlip | Impose _ | Chop _ -> mem Pdfcrypt.NoAssemble banlist | TwoUp|TwoUpStack|RemoveBookmarks|AddRectangle|RemoveText| - Draft|Shift|Scale|ScaleToFit|RemoveAttachedFiles| + Draft|Shift|ShiftBoxes | Scale|ScaleToFit|RemoveAttachedFiles| RemoveAnnotations|RemoveFonts|Crop|RemoveCrop|Trim|RemoveTrim|Bleed|RemoveBleed|Art|RemoveArt| CopyBox|MediaBox|HardBox _|SetTrapped|SetUntrapped|Presentation| BlackText|BlackLines|BlackFills|CopyFont _|StampOn _|StampUnder _|StampAsXObject _| @@ -1201,6 +1203,10 @@ let setshift s = setop Shift (); args.coord <- s +let setshiftboxes s = + setop ShiftBoxes (); + args.coord <- s + let setscale s = setop Scale (); args.coord <- s @@ -2171,6 +2177,9 @@ and specs = ("-shift", Arg.String setshift, " -shift \"dx dy\" shifts the chosen pages"); + ("-shift-boxes", + Arg.String setshiftboxes, + " -shift \"dx dy\" shifts the chosen pages"); ("-rotate", Arg.Int setrotate, " Set rotation of pages to 0, 90, 180, 270"); @@ -4183,6 +4192,15 @@ let go () = let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in let dxdylist = Cpdfcoord.parse_coordinates pdf args.coord in write_pdf false (Cpdfpage.shift_pdf ~fast:args.fast dxdylist pdf range) + | Some ShiftBoxes -> + let pdf = get_single_pdf args.op false in + let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in + let dxdylist = Cpdfcoord.parse_coordinates pdf args.coord in + let dx, dy = match dxdylist with (a, b)::_ -> a, b | _ -> 0.0, 0.0 in + Printf.printf "dx = %f, dy = %f\n" dx dy; + let f (xmin, xmax, ymin, ymax) = (xmin +. dx, xmax +. dx, ymin +. dy, ymax +. dy) in + let fpage _ p = Cpdfpage.change_boxes f pdf p in + write_pdf false (Cpdfpage.process_pages (Pdfpage.ppstub fpage) pdf range) | Some Scale -> let pdf = get_single_pdf args.op false in let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in diff --git a/cpdfmanual.tex b/cpdfmanual.tex index 4a32394..1e0dc85 100644 --- a/cpdfmanual.tex +++ b/cpdfmanual.tex @@ -16,6 +16,7 @@ %Document -extract-stream - check enc %Document -obj - check enc %Document -merge-no-struct-trees in merge and collate +%Document -shift-boxes \documentclass{book} % Edit here to produce cpdfmanual.pdf, cpdflibmanual.pdf, pycpdfmanual.pdf, % dotnetcpdflibmanual.pdf, jcpdflibmanual.pdf jscpdflibmanual.pdf etc.