diff --git a/cpdf.ml b/cpdf.ml index f5e831d..ab6f65d 100644 --- a/cpdf.ml +++ b/cpdf.ml @@ -1239,32 +1239,35 @@ let split_on_bookmarks pdf level = (* Output information for each page *) let output_page_info pdf = let pages = Pdfpage.pages_of_pagetree pdf - in let getbox page box = - if box = "/MediaBox" then - match page.Pdfpage.mediabox with - | Pdf.Array [a; b; c; d] -> - Printf.sprintf "%f %f %f %f" - (Pdf.getnum a) (Pdf.getnum b) (Pdf.getnum c) (Pdf.getnum d) - | _ -> "" - else - match Pdf.lookup_direct pdf box page.Pdfpage.rest with - | Some (Pdf.Array [a; b; c; d]) -> - Printf.sprintf "%f %f %f %f" - (Pdf.getnum a) (Pdf.getnum b) (Pdf.getnum c) (Pdf.getnum d) - | _ -> "" - in let rotation page = - Pdfpage.int_of_rotation page.Pdfpage.rotate - in - for pnum = 1 to Pdfpage.endpage pdf do - let page = select pnum pages in - Printf.printf "Page %i:\n" pnum; - Printf.printf "MediaBox: %s\n" (getbox page "/MediaBox"); - Printf.printf "CropBox: %s\n" (getbox page "/CropBox"); - Printf.printf "BleedBox: %s\n" (getbox page "/BleedBox"); - Printf.printf "TrimBox: %s\n" (getbox page "/TrimBox"); - Printf.printf "ArtBox: %s\n" (getbox page "/ArtBox"); - Printf.printf "Rotation: %i\n" (rotation page) - done + and labels = Pdfpagelabels.read pdf in + let getbox page box = + if box = "/MediaBox" then + match page.Pdfpage.mediabox with + | Pdf.Array [a; b; c; d] -> + Printf.sprintf "%f %f %f %f" + (Pdf.getnum a) (Pdf.getnum b) (Pdf.getnum c) (Pdf.getnum d) + | _ -> "" + else + match Pdf.lookup_direct pdf box page.Pdfpage.rest with + | Some (Pdf.Array [a; b; c; d]) -> + Printf.sprintf "%f %f %f %f" + (Pdf.getnum a) (Pdf.getnum b) (Pdf.getnum c) (Pdf.getnum d) + | _ -> "" + and rotation page = + Pdfpage.int_of_rotation page.Pdfpage.rotate + in + for pnum = 1 to Pdfpage.endpage pdf do + let page = select pnum pages in + Printf.printf "Page %i:\n" pnum; + Printf.printf "Label: %s\n" + (try Pdfpagelabels.pagelabeltext_of_pagenumber pnum labels with Not_found -> ""); + Printf.printf "MediaBox: %s\n" (getbox page "/MediaBox"); + Printf.printf "CropBox: %s\n" (getbox page "/CropBox"); + Printf.printf "BleedBox: %s\n" (getbox page "/BleedBox"); + Printf.printf "TrimBox: %s\n" (getbox page "/TrimBox"); + Printf.printf "ArtBox: %s\n" (getbox page "/ArtBox"); + Printf.printf "Rotation: %i\n" (rotation page) + done (* Does the page have a defined box e.g "/CropBox" *) let hasbox pdf page boxname = diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 17a945b..830084d 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -152,6 +152,9 @@ type op = | PrintLinearization | OpenAtPage of int | OpenAtPageFit of int + | AddPageLabels of string + | RemovePageLabels + | PrintPageLabels (* Inputs: filename, pagespec. *) type input_kind = @@ -1187,6 +1190,9 @@ let setopenatpage n = let setopenatpagefit n = args.op <- Some (OpenAtPageFit n) +let setaddpagelabels s = + args.op <- Some (AddPageLabels s) + (* Parse a control file, make an argv, and then make Arg parse it. *) let rec make_control_argv_and_parse filename = control_args := !control_args @ parse_control_file filename @@ -1647,6 +1653,15 @@ and specs = ("-copy-id-from", Arg.String setcopyid, " Copy one file's ID tag to another"); + ("-print-page-labels", + Arg.Unit (setop PrintPageLabels), + " Print page labels"); + ("-remove-page-labels", + Arg.Unit (setop RemovePageLabels), + " Remove page labels"); + ("-add-page-labels", + Arg.String setaddpagelabels, + " Add or replace page labels"); (* These items are for cpdftk *) ("-update-info", Arg.String setupdateinfo, ""); ("-printf-format", Arg.Unit setprintfformat, ""); @@ -3352,6 +3367,16 @@ let go () = Pdfread.print_linearization (Pdfio.input_of_channel (open_in_bin inname)) | _ -> raise (Arg.Bad "-print-linearization: supply a single file name") end + | Some (AddPageLabels labelspec) -> () + | Some RemovePageLabels -> + let pdf = get_single_pdf args.op false in + Pdfpagelabels.remove pdf; + write_pdf false pdf + | Some PrintPageLabels -> + let pdf = get_single_pdf args.op true in + iter + print_string + (map Pdfpagelabels.string_of_pagelabel (Pdfpagelabels.read pdf)) let parse_argv () = Arg.parse_argv ~current:(ref 0)