Added -pad-mutliple-before

This commit is contained in:
John Whitington 2019-07-01 15:35:17 +01:00
parent 3d595a14de
commit 476c5fda5d
3 changed files with 16 additions and 3 deletions

View File

@ -2156,6 +2156,7 @@ let padbefore ?padwith range pdf =
pad padwith (map pred range) pdf true pad padwith (map pred range) pdf true
let padmultiple n pdf = 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 pages = Pdfpage.pages_of_pagetree pdf in
let len = length pages in let len = length pages in
let pages_to_add = if len / n * n = len then 0 else n - (len mod n) 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.mediabox = (select len pages).Pdfpage.mediabox;
Pdfpage.resources = Pdf.Dictionary []; Pdfpage.resources = Pdf.Dictionary [];
Pdfpage.rotate = (select len pages).Pdfpage.rotate; Pdfpage.rotate = (select len pages).Pdfpage.rotate;
Pdfpage.rest = (select len pages).Pdfpage.rest} Pdfpage.rest = Pdf.Dictionary []}
pages_to_add pages_to_add
in in
let changes = map (fun x -> (x, x)) (ilist 1 (length pages)) 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 else
pdf pdf

View File

@ -92,6 +92,7 @@ type op =
| PadAfter | PadAfter
| PadEvery of int | PadEvery of int
| PadMultiple of int | PadMultiple of int
| PadMultipleBefore of int
| Shift | Shift
| Scale | Scale
| ScaleToFit | ScaleToFit
@ -205,6 +206,7 @@ let string_of_op = function
| PadAfter -> "PadAfter" | PadAfter -> "PadAfter"
| PadEvery _ -> "PadEvery" | PadEvery _ -> "PadEvery"
| PadMultiple _ -> "PadMultiple" | PadMultiple _ -> "PadMultiple"
| PadMultipleBefore _ -> "PadMultipleBefore"
| Shift -> "Shift" | Shift -> "Shift"
| Scale -> "Scale" | Scale -> "Scale"
| ScaleToFit -> "ScaleToFit" | ScaleToFit -> "ScaleToFit"
@ -636,7 +638,7 @@ let banned banlist = function
| Decrypt | Encrypt | CombinePages _ -> true (* Never allowed *) | Decrypt | Encrypt | CombinePages _ -> true (* Never allowed *)
(* ISO says Noextract no longer relevent, due to accessibility concerns *) (* ISO says Noextract no longer relevent, due to accessibility concerns *)
(*| ExtractText | ExtractImages | ExtractFontFile -> mem Pdfcrypt.NoExtract banlist*) (*| ExtractText | ExtractImages | ExtractFontFile -> mem Pdfcrypt.NoExtract banlist*)
| AddBookmarks _ | PadBefore | PadAfter | PadEvery _ | PadMultiple _ | AddBookmarks _ | PadBefore | PadAfter | PadEvery _ | PadMultiple _ | PadMultipleBefore _
| Merge | Split | SplitOnBookmarks _ | RotateContents _ | Rotate _ | Merge | Split | SplitOnBookmarks _ | RotateContents _ | Rotate _
| Rotateby _ | Upright | VFlip | HFlip | SetPageLayout _ | Rotateby _ | Upright | VFlip | HFlip | SetPageLayout _
| SetPageMode _ | HideToolbar _ | HideMenubar _ | HideWindowUI _ | SetPageMode _ | HideToolbar _ | HideMenubar _ | HideWindowUI _
@ -1433,6 +1435,9 @@ let setpadwith filename =
let setpadmultiple i = let setpadmultiple i =
args.op <- Some (PadMultiple i) args.op <- Some (PadMultiple i)
let setpadmultiplebefore i =
args.op <- Some (PadMultipleBefore i)
let setfast () = let setfast () =
args.fast <- true args.fast <- true
@ -1971,6 +1976,9 @@ and specs =
("-pad-multiple", ("-pad-multiple",
Arg.Int setpadmultiple, Arg.Int setpadmultiple,
" Pad the document to a multiple of n pages"); " 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", ("-list-annotations",
Arg.Unit (setop ListAnnotations), Arg.Unit (setop ListAnnotations),
" List annotations"); " List annotations");
@ -3980,6 +3988,9 @@ let go () =
| Some (PadMultiple n) -> | Some (PadMultiple n) ->
let pdf = get_single_pdf args.op false in let pdf = get_single_pdf args.op false in
write_pdf false (Cpdf.padmultiple n pdf) 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 -> | Some Draft ->
let pdf = get_single_pdf args.op false in let pdf = get_single_pdf args.op false in
let range = parse_pagespec pdf (get_pagespec ()) in let range = parse_pagespec pdf (get_pagespec ()) in

View File

@ -15,6 +15,7 @@
%FIXME: Document new -create-metadata %FIXME: Document new -create-metadata
%FIXME: Document -remove-clipping %FIXME: Document -remove-clipping
%FIXME: Document new -list-spot-colours %FIXME: Document new -list-spot-colours
%FIXME: Document new -pad-multiple-before
\documentclass{book} \documentclass{book}
\usepackage{palatino} \usepackage{palatino}