Alter the `list-annotations` output to include the page number.

Also make the output format more succinct to make it grep/awk-friendly.
The new format is `Page: <comment>\n`. Grep users will need to be
careful to deal with multiline comments, though.

Signed-off-by: Anil Madhavapeddy <anil@recoil.org>
This commit is contained in:
Anil Madhavapeddy 2013-09-16 13:46:00 +01:00
parent a6ff553210
commit 79afdd42e4
1 changed files with 11 additions and 8 deletions

19
cpdf.ml
View File

@ -2253,21 +2253,24 @@ let get_annotation_string encoding pdf annot =
| Some (Pdf.String s) -> encode_output encoding s
| _ -> ""
let print_annotation encoding pdf s =
let print_annotation encoding pdf num s =
let s = get_annotation_string encoding pdf s in
flprint "------------------------------------------------------------------------\n";
flprint s;
flprint "\n"
match s with
| "" -> ()
| s ->
flprint (Printf.sprintf "Page %d: " num);
flprint s;
flprint "\n"
let list_page_annotations encoding pdf page =
let list_page_annotations encoding pdf num page =
match Pdf.lookup_direct pdf "/Annots" page.Pdfpage.rest with
| Some (Pdf.Array annots) ->
iter (print_annotation encoding pdf) (map (Pdf.direct pdf) annots)
iter (print_annotation encoding pdf num) (map (Pdf.direct pdf) annots)
| _ -> ()
let list_annotations encoding pdf =
let pages = Pdfpage.pages_of_pagetree pdf in
iter (list_page_annotations encoding pdf) pages
let range = parse_pagespec pdf "all" in
iter_pages (list_page_annotations encoding pdf) pdf range
let get_annotations encoding pdf =
let pages = Pdfpage.pages_of_pagetree pdf in