Implement listing of page info in JSON
This commit is contained in:
parent
442acf71cd
commit
122285db59
|
@ -3489,7 +3489,7 @@ let go () =
|
|||
| (_, pagespec, _, _, _, _)::_, _ ->
|
||||
let pdf = get_single_pdf args.op true in
|
||||
let range = parse_pagespec_allow_empty pdf pagespec in
|
||||
Cpdfpage.output_page_info pdf range
|
||||
Cpdfpage.output_page_info ~json:args.format_json pdf range
|
||||
| _ -> error "list-bookmarks: bad command line"
|
||||
end
|
||||
| Some Metadata ->
|
||||
|
|
24
cpdfpage.ml
24
cpdfpage.ml
|
@ -154,7 +154,7 @@ let change_pattern_matrices_page pdf tr page =
|
|||
{page with Pdfpage.resources = change_pattern_matrices_resources pdf tr page.Pdfpage.resources used}
|
||||
|
||||
(* Output information for each page *)
|
||||
let output_page_info pdf range =
|
||||
let output_page_info ?(json=false) pdf range =
|
||||
let pages = Pdfpage.pages_of_pagetree pdf
|
||||
and labels = Pdfpagelabels.read pdf in
|
||||
let getbox page box =
|
||||
|
@ -173,6 +173,28 @@ let output_page_info pdf range =
|
|||
and rotation page =
|
||||
Pdfpage.int_of_rotation page.Pdfpage.rotate
|
||||
in
|
||||
let json_entry_of_pnum pnum =
|
||||
let getbox_json page box =
|
||||
match getbox page box with
|
||||
| "" -> `Null
|
||||
| s ->
|
||||
let a, b, c, d = Cpdfcoord.parse_rectangle (Pdf.empty ()) s in
|
||||
`List [`Float a; `Float b; `Float c; `Float d]
|
||||
in
|
||||
let page = select pnum pages in
|
||||
`Assoc
|
||||
[("Page", `Int pnum);
|
||||
("Label", (`String (try Pdfpagelabels.pagelabeltext_of_pagenumber pnum labels with Not_found -> "")));
|
||||
("MediaBox", getbox_json page "/MediaBox");
|
||||
("CropBox", getbox_json page "/CropBox");
|
||||
("BleedBox", getbox_json page "/BleedBox");
|
||||
("TrimBox", getbox_json page "/TrimBox");
|
||||
("ArtBox", getbox_json page "/ArtBox");
|
||||
("Rotation", `Int (rotation page))]
|
||||
in
|
||||
if json then
|
||||
flprint (Cpdfyojson.Safe.pretty_to_string (`List (map json_entry_of_pnum range)))
|
||||
else
|
||||
iter
|
||||
(fun pnum ->
|
||||
let page = select pnum pages in
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
(** Working with pages *)
|
||||
|
||||
(** Print page info (Mediabox etc) to standard output. *)
|
||||
val output_page_info : Pdf.t -> int list -> unit
|
||||
val output_page_info : ?json:bool -> Pdf.t -> int list -> unit
|
||||
|
||||
(** Given a function from page number and page to page, a document, and a list
|
||||
of page numbers to apply it to, apply the function to all those pages. *)
|
||||
|
|
Loading…
Reference in New Issue