From e3ea45d5e2a31b535e3663fe6d84e9d747e42473 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Mon, 5 Feb 2024 14:01:16 +0000 Subject: [PATCH] Scaffolding for -chop-h, -chop-v --- cpdfchop.ml | 4 ++++ cpdfchop.mli | 2 ++ cpdfcommand.ml | 20 +++++++++++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/cpdfchop.ml b/cpdfchop.ml index fa966fb..8b3d534 100644 --- a/cpdfchop.ml +++ b/cpdfchop.ml @@ -67,3 +67,7 @@ let chop ~x ~y ~columns ~btt ~rtl pdf range = pages) in Pdfpage.change_pages ~changes true pdf pages_out + + +let chop_hv ~is_h ~p ~columns pdf range = + pdf diff --git a/cpdfchop.mli b/cpdfchop.mli index 3bf8803..4e93861 100644 --- a/cpdfchop.mli +++ b/cpdfchop.mli @@ -2,3 +2,5 @@ (** Chop a page into pieces. *) val chop : x:int -> y:int -> columns:bool -> btt:bool -> rtl:bool -> Pdf.t -> int list -> Pdf.t + +val chop_hv : is_h:bool -> p:float -> columns:bool -> Pdf.t -> int list -> Pdf.t diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 487fb89..591d754 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -231,6 +231,7 @@ type op = | Draw | Composition of bool | Chop of int * int + | ChopHV of bool * float | ProcessImages | ExtractStream of int | PrintObj of int @@ -372,6 +373,7 @@ let string_of_op = function | Draw -> "Draw" | Composition _ -> "Composition" | Chop _ -> "Chop" + | ChopHV _ -> "ChopHV" | ProcessImages -> "ProcessImages" | ExtractStream _ -> "ExtractStream" | PrintObj _ -> "PrintObj" @@ -903,7 +905,7 @@ let banned banlist = function | Decrypt | Encrypt | CombinePages _ -> true (* Never allowed *) | AddBookmarks _ | PadBefore | PadAfter | PadEvery _ | PadMultiple _ | PadMultipleBefore _ | Merge | Split | SplitOnBookmarks _ | SplitMax _ | Spray | RotateContents _ | Rotate _ - | Rotateby _ | Upright | VFlip | HFlip | Impose _ | Chop _ -> + | Rotateby _ | Upright | VFlip | HFlip | Impose _ | Chop _ | ChopHV _ -> mem Pdfcrypt.NoAssemble banlist | TwoUp|TwoUpStack|RemoveBookmarks|AddRectangle|RemoveText| Draft|Shift|ShiftBoxes | Scale|ScaleToFit|RemoveAttachedFiles| @@ -1648,6 +1650,12 @@ let setchop s = let x, y = Cpdfcoord.parse_coordinate empty s in setop (Chop (int_of_float x, int_of_float y)) () +let setchopv x = + setop (ChopHV (false, x)) () + +let setchoph y = + setop (ChopHV (true, y)) () + let setreplacedictentry s = setop (ReplaceDictEntry s) () @@ -2311,6 +2319,12 @@ and specs = ("-chop", Arg.String setchop, " Chop x by y"); + ("-chop-h", + Arg.Float setchoph, + " Chop horizontally"); + ("-chop-v", + Arg.Float setchopv, + " Chop horizontally"); ("-chop-columns", Arg.Unit (fun () -> args.impose_columns <- true), " Chop in columns rather than rows"); @@ -4446,6 +4460,10 @@ let go () = let pdf = get_single_pdf args.op false in let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in write_pdf false (Cpdfchop.chop ~x ~y ~columns:args.impose_columns ~btt:args.impose_btt ~rtl:args.impose_rtl pdf range) + | Some (ChopHV (is_h, p)) -> + let pdf = get_single_pdf args.op false in + let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in + write_pdf false (Cpdfchop.chop_hv ~is_h ~p ~columns:args.impose_columns pdf range) | Some ProcessImages -> let pdf = get_single_pdf args.op false in let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in