Added -embed-missing-fonts

This commit is contained in:
John Whitington 2019-07-02 18:20:05 +01:00
parent ed0a7a800d
commit 80e7b0de32
2 changed files with 34 additions and 1 deletions

View File

@ -181,6 +181,7 @@ type op =
| RemoveClipping | RemoveClipping
| SetMetadataDate of string | SetMetadataDate of string
| CreateMetadata | CreateMetadata
| EmbedMissingFonts
let string_of_op = function let string_of_op = function
| CopyFont _ -> "CopyFont" | CopyFont _ -> "CopyFont"
@ -295,6 +296,7 @@ let string_of_op = function
| RemoveBleed -> "RemoveBleed" | RemoveBleed -> "RemoveBleed"
| SetMetadataDate _ -> "SetMetadataDate" | SetMetadataDate _ -> "SetMetadataDate"
| CreateMetadata -> "CreateMetadata" | CreateMetadata -> "CreateMetadata"
| EmbedMissingFonts -> "EmbedMissingFonts"
(* Inputs: filename, pagespec. *) (* Inputs: filename, pagespec. *)
type input_kind = type input_kind =
@ -631,7 +633,7 @@ let banned banlist = function
| ListBookmarks | ImageResolution _ | MissingFonts | ListBookmarks | ImageResolution _ | MissingFonts
| PrintPageLabels | Clean | Compress | Decompress | PrintPageLabels | Clean | Compress | Decompress
| RemoveUnusedResources | ChangeId | CopyId _ | ListSpotColours | Version | 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 (* Combine pages is not allowed because we would not know where to get the
-recrypt from -- the first or second file? *) -recrypt from -- the first or second file? *)
| ExtractText | ExtractImages | ExtractFontFile | ExtractText | ExtractImages | ExtractFontFile
@ -1952,6 +1954,9 @@ and specs =
("-relative-to-cropbox", ("-relative-to-cropbox",
Arg.Unit setrelativetocropbox, Arg.Unit setrelativetocropbox,
" Add text relative to Crop Box not Media Box"); " Add text relative to Crop Box not Media Box");
("-embed-missing-fonts",
Arg.Unit (setop EmbedMissingFonts),
" Embed missing fonts by calling gs");
("-prerotate", ("-prerotate",
Arg.Unit setprerotate, Arg.Unit setprerotate,
" Calls -upright on pages before adding text"); " Calls -upright on pages before adding text");
@ -2227,6 +2232,20 @@ let filesize name =
with with
_ -> 0 _ -> 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 (* 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). *) * 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 = let mend_pdf_file_with_ghostscript filename =
@ -4262,6 +4281,18 @@ let go () =
| Some CreateMetadata -> | Some CreateMetadata ->
let pdf = get_single_pdf args.op false in let pdf = get_single_pdf args.op false in
write_pdf false (Cpdf.create_metadata pdf) 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 () = let parse_argv () =
if args.debug then if args.debug then

View File

@ -18,6 +18,8 @@
%FIXME: Document new -pad-multiple-before %FIXME: Document new -pad-multiple-before
%FIXME: Document new @N@@@ @E@@@, @S@@@ options %FIXME: Document new @N@@@ @E@@@, @S@@@ options
%FIXME: Document the rotate dance for adding rotated text %FIXME: Document the rotate dance for adding rotated text
%FIXME: Document -gs gs -gs-malformed
%FIXME: Document -gs gs -gs-embed-fonts
\documentclass{book} \documentclass{book}
\usepackage{palatino} \usepackage{palatino}