Support for cpdflib getImageResolution

This commit is contained in:
John Whitington 2024-02-07 14:42:38 +00:00
parent 60a587fd4b
commit 8684ec3092
3 changed files with 15 additions and 8 deletions

View File

@ -4256,13 +4256,10 @@ let go () =
| Some (ImageResolution f) -> | Some (ImageResolution f) ->
let pdf = get_single_pdf args.op true in let pdf = get_single_pdf args.op true in
let range = parse_pagespec_allow_empty pdf (get_pagespec ()) 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 if args.format_json then
flprint flprint (Pdfio.string_of_bytes (Cpdfimage.image_resolution_json pdf range f))
(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 else
let images = Cpdfimage.image_resolution pdf range f in
iter iter
(function (pagenum, xobject, w, h, wdpi, hdpi, objnum) -> (function (pagenum, xobject, w, h, wdpi, hdpi, objnum) ->
if wdpi < f || hdpi < f then if wdpi < f || hdpi < f then

View File

@ -324,6 +324,14 @@ let image_resolution pdf range dpi =
image_resolution pdf range dpi; image_resolution pdf range dpi;
rev !image_results 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. *) (* All the images in file referenced at least once from the given range of pages. *)
let images pdf range = let images pdf range =
let images = null_hash () in let images = null_hash () in

View File

@ -11,6 +11,8 @@ val extract_images :
(** Report image resolutions. *) (** Report image resolutions. *)
val image_resolution : Pdf.t -> int list -> float -> (int * string * int * int * float * float * int) list 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 *) (** List images in JSON format *)
val images : Pdf.t -> int list -> Cpdfyojson.Safe.t val images : Pdf.t -> int list -> Cpdfyojson.Safe.t