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 62919e9..36de6a2 100644 Binary files a/cpdfmanual.pdf and b/cpdfmanual.pdf differ diff --git a/cpdfmanual.tex b/cpdfmanual.tex index 1c175e5..b05c1a9 100644 --- a/cpdfmanual.tex +++ b/cpdfmanual.tex @@ -1,12 +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