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

View File

@ -257,7 +257,7 @@ type args =
mutable uprightstamp : bool;
mutable labelstyle : Pdfpagelabels.labelstyle;
mutable labelprefix : string option;
mutable labeloffset : int option;
mutable labelstartval : int;
mutable squeeze : bool}
(* 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;
labelstyle = Pdfpagelabels.DecimalArabic;
labelprefix = None;
labeloffset = None;
labelstartval = 1;
squeeze = false}
let reset_arguments () =
@ -414,7 +414,7 @@ let reset_arguments () =
args.uprightstamp <- false;
args.labelstyle <- Pdfpagelabels.DecimalArabic;
args.labelprefix <- None;
args.labeloffset <- None;
args.labelstartval <- 1;
args.squeeze <- false
(* 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. *)
@ -1221,8 +1221,8 @@ let setlabelstyle s =
let setlabelprefix s =
args.labelprefix <- Some s
let setlabeloffset i =
args.labeloffset <- Some i
let setlabelstartval i =
args.labelstartval <- i
(* Parse a control file, make an argv, and then make Arg parse it. *)
let rec make_control_argv_and_parse filename =
@ -1702,9 +1702,9 @@ and specs =
("-label-prefix",
Arg.String setlabelprefix,
" Set label prefix (default none)");
("-label-offset",
Arg.Int setlabeloffset,
" Set label offset (default 1)");
("-label-startval",
Arg.Int setlabelstartval,
" Set label start value (default 1)");
(* These items are for cpdftk *)
("-update-info", Arg.String setupdateinfo, "");
("-printf-format", Arg.Unit setprintfformat, "");
@ -3468,11 +3468,9 @@ let go () =
| Some AddPageLabels ->
let pdf = get_single_pdf args.op false in
let range = parse_pagespec pdf (get_pagespec ()) in
let offset =
match args.labeloffset with None -> 1 | Some x -> x
in
Cpdf.add_page_labels pdf args.labelstyle args.labelprefix offset range;
write_pdf false pdf
Cpdf.add_page_labels
pdf args.labelstyle args.labelprefix args.labelstartval range;
write_pdf false pdf
| Some RemovePageLabels ->
let pdf = get_single_pdf args.op false in
Pdfpagelabels.remove pdf;

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!\\
\noindent\verb! [-label-style <style>]!\\
\noindent\verb! [-label-prefix <string>]!\\
\noindent\verb! [-label-offset <integer>]!
\noindent\verb! [-label-startval <integer>]!
\end{framed}
\section{Listing Fonts}
\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 15-20 -label-prefix "A-"!\\
\noindent\verb! -label-offset -1 -o out.pdf!
\noindent\verb! -label-startval 0 -o out.pdf!
\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}
\index{attachments}