From 476c5fda5d1bfb496cff9de7eb691dea312ff5a5 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Mon, 1 Jul 2019 15:35:17 +0100 Subject: [PATCH] Added -pad-mutliple-before --- cpdf.ml | 5 +++-- cpdfcommand.ml | 13 ++++++++++++- cpdfmanual.tex | 1 + 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/cpdf.ml b/cpdf.ml index fa5bd6d..191a426 100644 --- a/cpdf.ml +++ b/cpdf.ml @@ -2156,6 +2156,7 @@ let padbefore ?padwith range pdf = pad padwith (map pred range) pdf true let padmultiple n pdf = + let neg, n = n < 0, if n < 0 then -n else n in let pages = Pdfpage.pages_of_pagetree pdf in let len = length pages in let pages_to_add = if len / n * n = len then 0 else n - (len mod n) in @@ -2166,11 +2167,11 @@ let padmultiple n pdf = Pdfpage.mediabox = (select len pages).Pdfpage.mediabox; Pdfpage.resources = Pdf.Dictionary []; Pdfpage.rotate = (select len pages).Pdfpage.rotate; - Pdfpage.rest = (select len pages).Pdfpage.rest} + Pdfpage.rest = Pdf.Dictionary []} pages_to_add in let changes = map (fun x -> (x, x)) (ilist 1 (length pages)) in - Pdfpage.change_pages ~changes true pdf (pages @ blankpages) + Pdfpage.change_pages ~changes true pdf (if neg then blankpages @ pages else pages @ blankpages) else pdf diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 9f1e06c..f3756ce 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -92,6 +92,7 @@ type op = | PadAfter | PadEvery of int | PadMultiple of int + | PadMultipleBefore of int | Shift | Scale | ScaleToFit @@ -205,6 +206,7 @@ let string_of_op = function | PadAfter -> "PadAfter" | PadEvery _ -> "PadEvery" | PadMultiple _ -> "PadMultiple" + | PadMultipleBefore _ -> "PadMultipleBefore" | Shift -> "Shift" | Scale -> "Scale" | ScaleToFit -> "ScaleToFit" @@ -636,7 +638,7 @@ let banned banlist = function | Decrypt | Encrypt | CombinePages _ -> true (* Never allowed *) (* ISO says Noextract no longer relevent, due to accessibility concerns *) (*| ExtractText | ExtractImages | ExtractFontFile -> mem Pdfcrypt.NoExtract banlist*) - | AddBookmarks _ | PadBefore | PadAfter | PadEvery _ | PadMultiple _ + | AddBookmarks _ | PadBefore | PadAfter | PadEvery _ | PadMultiple _ | PadMultipleBefore _ | Merge | Split | SplitOnBookmarks _ | RotateContents _ | Rotate _ | Rotateby _ | Upright | VFlip | HFlip | SetPageLayout _ | SetPageMode _ | HideToolbar _ | HideMenubar _ | HideWindowUI _ @@ -1433,6 +1435,9 @@ let setpadwith filename = let setpadmultiple i = args.op <- Some (PadMultiple i) +let setpadmultiplebefore i = + args.op <- Some (PadMultipleBefore i) + let setfast () = args.fast <- true @@ -1971,6 +1976,9 @@ and specs = ("-pad-multiple", Arg.Int setpadmultiple, " Pad the document to a multiple of n pages"); + ("-pad-multiple-before", + Arg.Int setpadmultiplebefore, + " Pad the document at beginning to a multiple of n pages"); ("-list-annotations", Arg.Unit (setop ListAnnotations), " List annotations"); @@ -3980,6 +3988,9 @@ let go () = | Some (PadMultiple n) -> let pdf = get_single_pdf args.op false in write_pdf false (Cpdf.padmultiple n pdf) + | Some (PadMultipleBefore n) -> + let pdf = get_single_pdf args.op false in + write_pdf false (Cpdf.padmultiple (-n) pdf) | Some Draft -> let pdf = get_single_pdf args.op false in let range = parse_pagespec pdf (get_pagespec ()) in diff --git a/cpdfmanual.tex b/cpdfmanual.tex index b72a22f..47531f0 100644 --- a/cpdfmanual.tex +++ b/cpdfmanual.tex @@ -15,6 +15,7 @@ %FIXME: Document new -create-metadata %FIXME: Document -remove-clipping %FIXME: Document new -list-spot-colours +%FIXME: Document new -pad-multiple-before \documentclass{book} \usepackage{palatino}