From 68fe5bd5f793ee0e45bc9908499e567556b6d40d Mon Sep 17 00:00:00 2001 From: John Whitington Date: Tue, 26 Nov 2024 20:18:31 +0000 Subject: [PATCH] Scaffolding for -output-[jpeg|png] --- Changes | 2 +- cpdfcommand.ml | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Changes b/Changes index 6b69bf2..5d5839f 100644 --- a/Changes +++ b/Changes @@ -5,7 +5,7 @@ New features: o New -center-to-fit centres pages on a given paper size o New -jpeg-to-jpeg-scale and -jpeg-to-jpeg-dpi o Rasterize PDFs by calling out to GhostScript -o Convert to PNG/JPEG by calling out to GhostScript +o Extract pages as PNG/JPEG by calling out to GhostScript Extended features: diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 0aea7fc..687e809 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -231,6 +231,7 @@ type op = | SetLanguage of string | Redact | Rasterize + | OutputImage of string let string_of_op = function | PrintFontEncoding _ -> "PrintFontEncoding" @@ -385,6 +386,7 @@ let string_of_op = function | SetLanguage _ -> "SetLanguage" | Redact -> "Redact" | Rasterize -> "Rasterize" + | OutputImage _ -> "OutputImage" (* Inputs: filename, pagespec. *) type input_kind = @@ -940,7 +942,7 @@ let banned banlist = function | OCGRename | OCGList | OCGOrderAll | PrintFontEncoding _ | TableOfContents | Typeset _ | Composition _ | TextWidth _ | SetAnnotations _ | CopyAnnotations _ | ExtractStream _ | PrintObj _ | ReplaceObj _ | Verify _ | MarkAs _ | RemoveMark _ | ExtractStructTree | ReplaceStructTree _ | SetLanguage _ - | PrintStructTree | Rasterize + | PrintStructTree | Rasterize | OutputImage _ -> false (* Always allowed *) (* Combine pages is not allowed because we would not know where to get the -recrypt from -- the first or second file? *) @@ -3010,6 +3012,8 @@ let specs = ("-rasterize-res", Arg.Float (fun f -> args.rast_res <- f), " Rastierization resolution"); ("-rasterize-annots", Arg.Unit (fun () -> args.rast_annots <- true), " Rasterize annotations"); ("-rasterize-no-antialias", Arg.Unit (fun () -> args.rast_antialias <- false), " Don't antialias when rasterizing"); + ("-output-jpeg", Arg.String (fun s -> args.op <- Some (OutputImage s)), " Output pages as JPEGs"); + ("-output-png", Arg.String (fun s -> args.op <- Some (OutputImage s)), " Output pages as PNGs"); (* These items are undocumented *) ("-debug", Arg.Unit setdebug, ""); ("-debug-crypt", Arg.Unit (fun () -> args.debugcrypt <- true), ""); @@ -3729,6 +3733,9 @@ let rasterize antialias device res annots pdf range = Sys.remove tmppdf; pdf +let write_images spec pdf range = + () + (* Main function *) let go () = check_bookmarks_mistake (); @@ -4836,6 +4843,10 @@ let go () = let pdf = get_single_pdf args.op false in let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in write_pdf false (rasterize args.rast_antialias args.rast_device args.rast_res args.rast_annots pdf range) + | Some (OutputImage spec) -> + let pdf = get_single_pdf args.op false in + let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in + write_images spec pdf range (* Advise the user if a combination of command line flags makes little sense, or error out if it make no sense at all. *)