From db170b428b44bbb2e662b09f201900f15662bc9c Mon Sep 17 00:00:00 2001 From: John Whitington Date: Sun, 26 Jul 2015 12:31:43 +0100 Subject: [PATCH] Add -bates-at-range --- cpdf.ml | 12 ++++++++++++ cpdf.mli | 2 ++ cpdfcommand.ml | 21 +++++++++++++++++---- cpdfmanual.pdf | Bin 216573 -> 216574 bytes cpdfmanual.tex | 4 +++- 5 files changed, 34 insertions(+), 5 deletions(-) diff --git a/cpdf.ml b/cpdf.ml index 532b55c..ad2a08d 100644 --- a/cpdf.ml +++ b/cpdf.ml @@ -449,6 +449,18 @@ let rec validate_pagespec_inner n spec = let validate_pagespec spec = validate_pagespec_inner 100 spec +let rec parse_pagespec_without_pdf_inner n spec = + try + parse_pagespec_inner n (Pdf.empty ()) spec + with + PageSpecUnknownPage _ -> + if n < 500000 + then parse_pagespec_without_pdf_inner (n * 2) spec + else raise (Pdf.PDFError "PageSpecUnknownPage") + +let parse_pagespec_without_pdf spec = + parse_pagespec_without_pdf_inner 100 spec + (* Convert an integer list representing a set to a page specification, in order. *) let string_of_pagespec pdf = function | [] -> "" diff --git a/cpdf.mli b/cpdf.mli index 273548f..b05c977 100644 --- a/cpdf.mli +++ b/cpdf.mli @@ -78,6 +78,8 @@ val string_of_pagespec : Pdf.t -> int list -> string without supplying a PDF, and thus knowing how many pages there are in it. *) val validate_pagespec : string -> bool +val parse_pagespec_without_pdf : string -> int list + (** [name_of_spec printf marks pdf splitlevel spec n filename startpage endpage] makes format substitutions in [spec] to make an output file name: diff --git a/cpdfcommand.ml b/cpdfcommand.ml index d6a82a4..7d7fa6e 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -278,6 +278,7 @@ type input = input_kind * string * string * string * bool ref * int option (* input kind, range, user_pw, owner_pw, was_decrypted_with_owner, revision *) + type output_method = | NoOutputSpecified | Stdout @@ -536,6 +537,11 @@ let reset_arguments () = (* Do not reset original_filename or cpdflin or was_encrypted or * was_decrypted_with_owner or recrypt, since we want these to work across ANDs. *) +let get_pagespec () = + match args.inputs with + | (_, ps, _, _, _, _)::_ -> ps + | _ -> error "No range specified for input, or specified too late." + let string_of_permission = function | Pdfcrypt.NoEdit -> "No edit" | Pdfcrypt.NoPrint -> "No print" @@ -1067,6 +1073,14 @@ let setbatespad n = let setbates n = args.bates <- n +(* Calculate -bates automatically so that n is applied to the first page in the range *) +let setbatesrange n = + let first_page = + let range = Cpdf.parse_pagespec_without_pdf (get_pagespec ()) in + fold_left min max_int range + in + args.bates <- n + 1 - first_page + let setkeepversion () = args.keepversion <- true @@ -1593,6 +1607,9 @@ and specs = ("-bates", Arg.Int setbates, " Set the base bates number"); + ("-bates-at-range", + Arg.Int setbatesrange, + " Set the base bates number at first page in range"); ("-bates-pad-to", Arg.Int setbatespad, " Pad the bates number with leading zeroes to width"); @@ -2251,10 +2268,6 @@ let split_pdf enc 0 original_filename squeeze nobble spec pdf (splitinto chunksize (indx pdf_pages)) pdf_pages -let get_pagespec () = - match args.inputs with - | (_, ps, _, _, _, _)::_ -> ps - | _ -> error "get_pagespec" (* Copy a font from [frompdf] with name [fontname] on page [fontpage] to [pdf] on all pages in [range] *) let copy_font frompdf fontname fontpage range pdf = diff --git a/cpdfmanual.pdf b/cpdfmanual.pdf index 62919e983a0381fcb9b0887a3cf4aeeecd411b19..36de6a2ff2de37528a7e92e1f12f461ba64f3d81 100644 GIT binary patch delta 4334 zcma)(S3DaI*tW%rSShOZtUVJWgxIroQEJnHpv0aPTh(suQM6VmYLie~>`|?mwnB}d z>R&-o_4YgYPT%+7etyrvb#mSJRWZZgVutr)Ab>)CwlqK-9c($^y9S}}-H{B+iM4N+ zn(XkMTyPJ3*)Uf$=Z;TcuC8w0bzW#tE3E!{``hjF4-Srv6PzHyy(1#5 zRstl;#1{9yPTMK-!)9);;&IJJJmfVt6Od4=eDA1^9Q>E#{%Nzx%ui9f}rhTePe#H!Zvmnc{}GW`jbNC+qgl2AeYmShRxsX&UJ>J z-o%|LBI{t&QoV`w@9Sg->Bt}aW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1,14 @@ %FIXME: Document -no-embed-font and encoding switch %Documents bates enhancements +%Document -bates-at-range (must come after range given) and after -bates if +%given \documentclass{book} \usepackage{palatino} \usepackage{microtype} \usepackage{graphics} \usepackage[plainpages=false,pdfpagelabels,pdfborder=0 0 0]{hyperref} \usepackage{framed} -\newcommand{\smallgap}{\vspace{4mm}} +\newcommand{\smallgap}{\bigskip} \newcommand{\cpdf}{\texttt{cpdf}} \addtolength{\textwidth}{20mm} \usepackage{makeidx}\makeindex