From 53e3d92a8140760348484eef3477c9e9bb60b7e1 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Mon, 13 Nov 2023 17:55:59 +0000 Subject: [PATCH] Scaffolding for -list-images --- Changes | 3 ++- cpdfcommand.ml | 9 +++++++-- cpdfimage.ml | 2 ++ cpdfimage.mli | 3 +++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Changes b/Changes index c9b4443..518f744 100644 --- a/Changes +++ b/Changes @@ -7,13 +7,14 @@ o Spray splits a file to multiple outputs by alternating pages o List document and page info in JSON format o List page labels in JSON format o List fonts in JSON format -o Identify PDF/A, PDF/X, PDF/E, PDF/VT, PDF/UA +o Identify PDF/A, PDF/X, PDF/E, PDF/VT, PDF/UA in -info o Extract font files from a document o List images on a page with -list-images[-json] Extended features: o -list-images-used[-json] extends -image-resolution +o Use -raw with -extract-images to get PNMs Fixes: diff --git a/cpdfcommand.ml b/cpdfcommand.ml index f4be454..653a5c0 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -4177,8 +4177,13 @@ let go () = Printf.printf "%i, %s, %i, %i, %f, %f\n" pagenum xobject w h wdpi hdpi) images | Some ListImages -> - (* FIXME Implement ListImages *) - () + let pdf = get_single_pdf args.op true in + let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in + let json = Cpdfimage.images pdf range in + if args.format_json then + flprint (Cpdfyojson.Safe.pretty_to_string json) + else + flprint "old fashioned output\n" | Some MissingFonts -> let pdf = get_single_pdf args.op true in let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in diff --git a/cpdfimage.ml b/cpdfimage.ml index 3841e63..e842a70 100644 --- a/cpdfimage.ml +++ b/cpdfimage.ml @@ -272,6 +272,8 @@ let image_resolution pdf range dpi = image_resolution pdf range dpi; rev !image_results +let images pdf range = `Null + let obj_of_jpeg_data data = let w, h = Cpdfjpeg.jpeg_dimensions data in let d = diff --git a/cpdfimage.mli b/cpdfimage.mli index 5e1ffcd..69bbf33 100644 --- a/cpdfimage.mli +++ b/cpdfimage.mli @@ -8,6 +8,9 @@ val extract_images : ?raw:bool -> ?path_to_p2p:string -> (** Report image resolutions. *) val image_resolution : Pdf.t -> int list -> float -> (int * string * int * int * float * float) list +(** List images in JSON format *) +val images : Pdf.t -> int list -> Cpdfyojson.Safe.t + (**/**) val image_of_input : (Pdfio.bytes -> Pdf.pdfobject) -> Pdfio.input -> Pdf.t val obj_of_jpeg_data : Pdfio.bytes -> Pdf.pdfobject