diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 08479ff..270c19e 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -4255,14 +4255,11 @@ let go () = Cpdfimage.extract_images ~raw:(args.encoding = Cpdfmetadata.Raw) ?path_to_p2p:(match args.path_to_p2p with "" -> None | x -> Some x) ?path_to_im:(match args.path_to_im with "" -> None | x -> Some x) args.encoding args.dedup args.dedup_per_page pdf range output_spec | Some (ImageResolution f) -> let pdf = get_single_pdf args.op true in - let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in - let images = Cpdfimage.image_resolution pdf range f in - if args.format_json then - flprint - (Cpdfyojson.Safe.pretty_to_string - (`List (map (fun (pagenum, xobject, w, h, wdpi, hdpi, objnum) -> - `Assoc [("Object", `Int objnum); ("Page", `Int pagenum); ("XObject", `String xobject); ("W", `Int w); ("H", `Int h); ("Xdpi", `Float wdpi); ("Ydpi", `Float hdpi)]) images))) - else + let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in + if args.format_json then + flprint (Pdfio.string_of_bytes (Cpdfimage.image_resolution_json pdf range f)) + else + let images = Cpdfimage.image_resolution pdf range f in iter (function (pagenum, xobject, w, h, wdpi, hdpi, objnum) -> if wdpi < f || hdpi < f then diff --git a/cpdfimage.ml b/cpdfimage.ml index f16376e..75d43ff 100644 --- a/cpdfimage.ml +++ b/cpdfimage.ml @@ -324,6 +324,14 @@ let image_resolution pdf range dpi = image_resolution pdf range dpi; rev !image_results +let image_resolution_json pdf range dpi = + let images = image_resolution pdf range dpi in + Pdfio.bytes_of_string + (Cpdfyojson.Safe.pretty_to_string + (`List (map (fun (pagenum, xobject, w, h, wdpi, hdpi, objnum) -> + `Assoc [("Object", `Int objnum); ("Page", `Int pagenum); ("XObject", `String xobject); + ("W", `Int w); ("H", `Int h); ("Xdpi", `Float wdpi); ("Ydpi", `Float hdpi)]) images))) + (* All the images in file referenced at least once from the given range of pages. *) let images pdf range = let images = null_hash () in diff --git a/cpdfimage.mli b/cpdfimage.mli index 0e18936..85b32a6 100644 --- a/cpdfimage.mli +++ b/cpdfimage.mli @@ -11,6 +11,8 @@ val extract_images : (** Report image resolutions. *) val image_resolution : Pdf.t -> int list -> float -> (int * string * int * int * float * float * int) list +val image_resolution_json : Pdf.t -> int list -> float -> Pdfio.bytes + (** List images in JSON format *) val images : Pdf.t -> int list -> Cpdfyojson.Safe.t