From 80e7b0de323171356b8f9cabbf54f36d3a4025f6 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Tue, 2 Jul 2019 18:20:05 +0100 Subject: [PATCH] Added -embed-missing-fonts --- cpdfcommand.ml | 33 ++++++++++++++++++++++++++++++++- cpdfmanual.tex | 2 ++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/cpdfcommand.ml b/cpdfcommand.ml index b837324..69a4902 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -181,6 +181,7 @@ type op = | RemoveClipping | SetMetadataDate of string | CreateMetadata + | EmbedMissingFonts let string_of_op = function | CopyFont _ -> "CopyFont" @@ -295,6 +296,7 @@ let string_of_op = function | RemoveBleed -> "RemoveBleed" | SetMetadataDate _ -> "SetMetadataDate" | CreateMetadata -> "CreateMetadata" + | EmbedMissingFonts -> "EmbedMissingFonts" (* Inputs: filename, pagespec. *) type input_kind = @@ -631,7 +633,7 @@ let banned banlist = function | ListBookmarks | ImageResolution _ | MissingFonts | PrintPageLabels | Clean | Compress | Decompress | RemoveUnusedResources | ChangeId | CopyId _ | ListSpotColours | Version - | DumpAttachedFiles | RemoveMetadata -> false (* Always allowed *) + | DumpAttachedFiles | RemoveMetadata | EmbedMissingFonts -> false (* Always allowed *) (* Combine pages is not allowed because we would not know where to get the -recrypt from -- the first or second file? *) | ExtractText | ExtractImages | ExtractFontFile @@ -1952,6 +1954,9 @@ and specs = ("-relative-to-cropbox", Arg.Unit setrelativetocropbox, " Add text relative to Crop Box not Media Box"); + ("-embed-missing-fonts", + Arg.Unit (setop EmbedMissingFonts), + " Embed missing fonts by calling gs"); ("-prerotate", Arg.Unit setprerotate, " Calls -upright on pages before adding text"); @@ -2227,6 +2232,20 @@ let filesize name = with _ -> 0 +(* Embed missing fonts with Ghostscript. *) +let embed_missing_fonts fi fo = + if args.path_to_ghostscript = "" then begin + Printf.eprintf "Please supply path to gs with -gs\n"; + end; + let gscall = + args.path_to_ghostscript ^ + " -dNOPAUSE -dQUIET -sDEVICE=pdfwrite -sOUTPUTFILE=" ^ fo ^ + " -dBATCH " ^ fi + in + match Sys.command gscall with + | 0 -> exit 0 + | _ -> Printf.eprintf "Font embedding failed.\n"; exit 2 + (* Mend PDF file with Ghostscript. We use this if a file is malformed and CPDF * cannot mend it. It is copied to a temporary file, fixed, then we return None or Some (pdf). *) let mend_pdf_file_with_ghostscript filename = @@ -4262,6 +4281,18 @@ let go () = | Some CreateMetadata -> let pdf = get_single_pdf args.op false in write_pdf false (Cpdf.create_metadata pdf) + | Some EmbedMissingFonts -> + let fi = + match args.inputs with + [(InFile fi, _, _, _, _, _)] -> fi + | _ -> error "Input method not supported for -embed-missing-fonts" + in + let fo = + match args.out with + File fo -> fo + | _ -> error "Output method not supported for -embed-missing-fonts" + in + embed_missing_fonts fi fo let parse_argv () = if args.debug then diff --git a/cpdfmanual.tex b/cpdfmanual.tex index 624bfcb..2a01d1c 100644 --- a/cpdfmanual.tex +++ b/cpdfmanual.tex @@ -18,6 +18,8 @@ %FIXME: Document new -pad-multiple-before %FIXME: Document new @N@@@ @E@@@, @S@@@ options %FIXME: Document the rotate dance for adding rotated text +%FIXME: Document -gs gs -gs-malformed +%FIXME: Document -gs gs -gs-embed-fonts \documentclass{book} \usepackage{palatino}