Add -bates-at-range

This commit is contained in:
John Whitington 2015-07-26 12:31:43 +01:00
parent 87998ea7ec
commit db170b428b
5 changed files with 34 additions and 5 deletions

12
cpdf.ml
View File

@ -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
| [] -> ""

View File

@ -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:

View File

@ -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 =

Binary file not shown.

View File

@ -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