Finished page label bug fixes

This commit is contained in:
John Whitington 2014-09-18 15:40:22 +01:00
parent 91b81da679
commit 0f3818bcc8
5 changed files with 22 additions and 24 deletions

BIN
blank.pdf

Binary file not shown.

16
cpdf.ml
View File

@ -3256,8 +3256,8 @@ let page1 labels =
let add_page_labels pdf style prefix startval range = let add_page_labels pdf style prefix startval range =
let ranges = map extremes (ranges_of_range [] [] range) let ranges = map extremes (ranges_of_range [] [] range)
and labels = Pdfpagelabels.read pdf in and labels = Pdfpagelabels.read pdf in
Printf.printf "We have %i existing labels\n" (List.length labels); (*Printf.printf "We have %i existing labels\n" (List.length labels);
Printf.printf "We have %i ranges to apply these labels to\n" (List.length ranges); Printf.printf "We have %i ranges to apply these labels to\n" (List.length ranges);*)
let labels = let labels =
if not (page1 labels) then if not (page1 labels) then
ref ref
@ -3268,8 +3268,8 @@ let add_page_labels pdf style prefix startval range =
else else
ref labels ref labels
in in
Printf.printf "Before adding, we have these labels:\n"; (*Printf.printf "Before adding, we have these labels:\n";
iter (fun x -> flprint (Pdfpagelabels.string_of_pagelabel x)) !labels; iter (fun x -> flprint (Pdfpagelabels.string_of_pagelabel x)) !labels;*)
iter iter
(function (s, e) -> (function (s, e) ->
let label = let label =
@ -3278,11 +3278,11 @@ let add_page_labels pdf style prefix startval range =
Pdfpagelabels.startpage = s; Pdfpagelabels.startpage = s;
Pdfpagelabels.startvalue = startval} Pdfpagelabels.startvalue = startval}
in in
Printf.printf "We are adding this label:\n"; (*Printf.printf "We are adding this label:\n";
flprint (Pdfpagelabels.string_of_pagelabel label); flprint (Pdfpagelabels.string_of_pagelabel label);*)
labels := Pdfpagelabels.add_label (Pdfpage.endpage pdf) !labels label e) labels := Pdfpagelabels.add_label (Pdfpage.endpage pdf) !labels label e)
ranges; ranges;
Printf.printf "After adding, we have these labels:\n"; (*Printf.printf "After adding, we have these labels:\n";
iter (fun x -> flprint (Pdfpagelabels.string_of_pagelabel x)) !labels; iter (fun x -> flprint (Pdfpagelabels.string_of_pagelabel x)) !labels;*)
Pdfpagelabels.write pdf !labels Pdfpagelabels.write pdf !labels

View File

@ -257,7 +257,7 @@ type args =
mutable uprightstamp : bool; mutable uprightstamp : bool;
mutable labelstyle : Pdfpagelabels.labelstyle; mutable labelstyle : Pdfpagelabels.labelstyle;
mutable labelprefix : string option; mutable labelprefix : string option;
mutable labeloffset : int option; mutable labelstartval : int;
mutable squeeze : bool} mutable squeeze : bool}
(* List of all filenames in any AND stage - this is used to check that we don't (* List of all filenames in any AND stage - this is used to check that we don't
@ -340,7 +340,7 @@ let args =
uprightstamp = false; uprightstamp = false;
labelstyle = Pdfpagelabels.DecimalArabic; labelstyle = Pdfpagelabels.DecimalArabic;
labelprefix = None; labelprefix = None;
labeloffset = None; labelstartval = 1;
squeeze = false} squeeze = false}
let reset_arguments () = let reset_arguments () =
@ -414,7 +414,7 @@ let reset_arguments () =
args.uprightstamp <- false; args.uprightstamp <- false;
args.labelstyle <- Pdfpagelabels.DecimalArabic; args.labelstyle <- Pdfpagelabels.DecimalArabic;
args.labelprefix <- None; args.labelprefix <- None;
args.labeloffset <- None; args.labelstartval <- 1;
args.squeeze <- false args.squeeze <- false
(* We don't reset args.do_ask and args.verbose, because they operate on all (* We don't reset args.do_ask and args.verbose, because they operate on all
parts of the AND-ed command line sent from cpdftk. *) parts of the AND-ed command line sent from cpdftk. *)
@ -1221,8 +1221,8 @@ let setlabelstyle s =
let setlabelprefix s = let setlabelprefix s =
args.labelprefix <- Some s args.labelprefix <- Some s
let setlabeloffset i = let setlabelstartval i =
args.labeloffset <- Some i args.labelstartval <- i
(* Parse a control file, make an argv, and then make Arg parse it. *) (* Parse a control file, make an argv, and then make Arg parse it. *)
let rec make_control_argv_and_parse filename = let rec make_control_argv_and_parse filename =
@ -1702,9 +1702,9 @@ and specs =
("-label-prefix", ("-label-prefix",
Arg.String setlabelprefix, Arg.String setlabelprefix,
" Set label prefix (default none)"); " Set label prefix (default none)");
("-label-offset", ("-label-startval",
Arg.Int setlabeloffset, Arg.Int setlabelstartval,
" Set label offset (default 1)"); " Set label start value (default 1)");
(* These items are for cpdftk *) (* These items are for cpdftk *)
("-update-info", Arg.String setupdateinfo, ""); ("-update-info", Arg.String setupdateinfo, "");
("-printf-format", Arg.Unit setprintfformat, ""); ("-printf-format", Arg.Unit setprintfformat, "");
@ -3468,10 +3468,8 @@ let go () =
| Some AddPageLabels -> | Some AddPageLabels ->
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
let offset = Cpdf.add_page_labels
match args.labeloffset with None -> 1 | Some x -> x pdf args.labelstyle args.labelprefix args.labelstartval range;
in
Cpdf.add_page_labels pdf args.labelstyle args.labelprefix offset range;
write_pdf false pdf write_pdf false pdf
| Some RemovePageLabels -> | Some RemovePageLabels ->
let pdf = get_single_pdf args.op false in let pdf = get_single_pdf args.op false in

Binary file not shown.

View File

@ -1568,7 +1568,7 @@ given page range.
\small\noindent\verb!cpdf -add-page-labels in.pdf -o out.pdf!\\ \small\noindent\verb!cpdf -add-page-labels in.pdf -o out.pdf!\\
\noindent\verb! [-label-style <style>]!\\ \noindent\verb! [-label-style <style>]!\\
\noindent\verb! [-label-prefix <string>]!\\ \noindent\verb! [-label-prefix <string>]!\\
\noindent\verb! [-label-offset <integer>]! \noindent\verb! [-label-startval <integer>]!
\end{framed} \end{framed}
\section{Listing Fonts} \section{Listing Fonts}
\index{fonts!listing} \index{fonts!listing}
@ -1802,10 +1802,10 @@ i, ii, iii, iv, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, A-0, A-1, A-2, A-3, A-4, A-5
\noindent\verb!cpdf -add-page-labels out.pdf 5-14 -o out.pdf!\\ \noindent\verb!cpdf -add-page-labels out.pdf 5-14 -o out.pdf!\\
\noindent\verb!cpdf -add-page-labels out.pdf 15-20 -label-prefix "A-"!\\ \noindent\verb!cpdf -add-page-labels out.pdf 15-20 -label-prefix "A-"!\\
\noindent\verb! -label-offset -1 -o out.pdf! \noindent\verb! -label-startval 0 -o out.pdf!
\end{framed} \end{framed}
\noindent By default the labels begin at page number 1 for each range. To override this, we can use \texttt{-label-offset} (we used $-1$ in the final command), where we want the numbers to begin at zero rather than one. \noindent By default the labels begin at page number 1 for each range. To override this, we can use \texttt{-label-startval} (we used $0$ in the final command), where we want the numbers to begin at zero rather than one.
\chapter{File Attachments} \chapter{File Attachments}
\index{attachments} \index{attachments}