diff --git a/Changes b/Changes index 252b4be..db6a1ec 100644 --- a/Changes +++ b/Changes @@ -13,6 +13,7 @@ Extended features: o Allow -utf8 with -split-bookmarks -o @B.pdf to produce UTF8 filenames o -merge-add-bookmarks now works with unicode filenames o Better transformation of some annotation types +o -list-annotations[-json] now respects page range Fixes: diff --git a/cpdfannot.ml b/cpdfannot.ml index 85363fc..75b9458 100644 --- a/cpdfannot.ml +++ b/cpdfannot.ml @@ -65,17 +65,19 @@ let annotations_json_page pdf page pagenum = (map (Pdf.direct pdf) annots) | _ -> [] -let list_annotations_json pdf = +let list_annotations_json range pdf = let module J = Cpdfyojson.Safe in let pages = Pdfpage.pages_of_pagetree pdf in let pagenums = indx pages in + let pairs = combine pages pagenums in + let pairs = option_map (fun (p, n) -> if mem n range then Some (p, n) else None) pairs in + let pages, pagenums = split pairs in let json = `List (flatten (map2 (annotations_json_page pdf) pages pagenums)) in J.pretty_to_channel stdout json -let list_annotations ~json encoding pdf = - let range = Cpdfpagespec.parse_pagespec pdf "all" in +let list_annotations ~json range encoding pdf = if json - then list_annotations_json pdf + then list_annotations_json range pdf else Cpdfpage.iter_pages (list_page_annotations encoding pdf) pdf range (* Return annotations *) diff --git a/cpdfannot.mli b/cpdfannot.mli index 7a13cd3..79ce1e4 100644 --- a/cpdfannot.mli +++ b/cpdfannot.mli @@ -1,7 +1,7 @@ (** Annotations *) (** List the annotations to standard output in a given encoding. See cpdfmanual.pdf for the format details. *) -val list_annotations : json:bool -> Cpdfmetadata.encoding -> Pdf.t -> unit +val list_annotations : json:bool -> int list -> Cpdfmetadata.encoding -> Pdf.t -> unit (** Return the annotations as a (pagenumber, content) list *) val get_annotations : Cpdfmetadata.encoding -> Pdf.t -> (int * string) list diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 811c6ee..33fb38b 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -3966,7 +3966,9 @@ let go () = | _ -> error "copy-annotations: No input file specified" end | Some ListAnnotations -> - Cpdfannot.list_annotations ~json:args.format_json args.encoding (get_single_pdf args.op true) + let pdf = get_single_pdf args.op true in + let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in + Cpdfannot.list_annotations ~json:args.format_json range args.encoding pdf | Some Shift -> let pdf = get_single_pdf args.op false in let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in diff --git a/cpdfmanual.tex b/cpdfmanual.tex index f392809..67b82ee 100644 --- a/cpdfmanual.tex +++ b/cpdfmanual.tex @@ -2,6 +2,7 @@ %Document -font-ttf %Document -draw and friends %Document -png -jpeg +%Document -list-annotations[-json] now obey page range \documentclass{book} % Edit here to produce cpdfmanual.pdf, cpdflibmanual.pdf, pycpdfmanual.pdf, % dotnetcpdflibmanual.pdf, jcpdflibmanual.pdf jscpdflibmanual.pdf etc.