From e6b3cc8a65a1bbcb71725a9c38742f3f4c4370e0 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Sun, 18 Aug 2019 10:55:40 +0100 Subject: [PATCH] Fix for -gs-malformed on files with wrong owner or user password --- cpdfcommand.ml | 19 ++++++++++++++----- cpdfmanual.pdf | Bin 238297 -> 238297 bytes cpdfmanual.tex | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/cpdfcommand.ml b/cpdfcommand.ml index a0b38e7..74911a8 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -1677,6 +1677,10 @@ let setdraftremoveonly s = let setgsquiet () = args.gs_quiet <- true +let whingemalformed () = + prerr_string "Command line must be of exactly the form\ncpdf -gs -gs-malformed-force -o \n"; + exit 1 + (* Parse a control file, make an argv, and then make Arg parse it. *) let rec make_control_argv_and_parse filename = control_args := !control_args @ parse_control_file filename @@ -2291,7 +2295,9 @@ and specs = ("-gs-quiet", Arg.Unit setgsquiet, " Make gs go into quiet mode"); ("-squeeze", Arg.Unit setsqueeze, " Squeeze"); ("-squeeze-log-to", Arg.String setsqueezelogto, " Squeeze log location"); - (*These items are undocumented *) + (* Just for error reporting *) + ("-gs-malformed-force", Arg.Unit whingemalformed, ""); + (* These items are undocumented *) ("-remove-unused-resources", Arg.Unit (setop RemoveUnusedResources), ""); ("-stay-on-error", Arg.Unit setstayonerror, ""); ("-extract-fontfile", Arg.Unit (setop ExtractFontFile), ""); @@ -2405,7 +2411,7 @@ let rec get_single_pdf ?(decrypt=true) ?(fail=false) op read_lazy = end | _ -> () end; - Printf.eprintf "Failed to read malformed PDF file. Consider using -gs-malformed\n"; + Printf.eprintf "get_single_pdf: failed to read malformed PDF file. Consider using -gs-malformed\n"; exit 2 in match args.inputs with @@ -2419,7 +2425,8 @@ let rec get_single_pdf ?(decrypt=true) ?(fail=false) op read_lazy = else pdfread_pdf_of_file ?revision (optstring u) (optstring o) inname with - _ -> + | Cpdf.SoftError _ as e -> raise e (* Bad owner or user password *) + | _ -> if args.gs_malformed then begin failout (); @@ -2487,7 +2494,7 @@ let rec get_pdf_from_input_kind ?(read_lazy=false) ?(decrypt=true) ?(fail=false) end | _ -> () end; - Printf.eprintf "Failed to read malformed PDF file. Consider using -gs-malformed\n"; + Printf.eprintf "get_pdf_from_input_kind: failed to read malformed PDF file. Consider using -gs-malformed\n"; exit 2 in match ik with @@ -2512,7 +2519,9 @@ let rec get_pdf_from_input_kind ?(read_lazy=false) ?(decrypt=true) ?(fail=false) else pdfread_pdf_of_file ?revision (optstring u) (optstring o) s with - _ -> + | Cpdf.SoftError _ as e -> raise e (* Bad owner or user password *) + | e -> + Printf.printf "%s\n" (Printexc.to_string e); if args.gs_malformed then begin failout (); diff --git a/cpdfmanual.pdf b/cpdfmanual.pdf index f0dc3a85e6c978de95e3bcaaae67778fb9a64502..b8cf56c140589845466c87a70a9763b23e2db526 100644 GIT binary patch delta 146 zcmcb4l<($Iz70novibb$nRA+b^67`pj3+1aKZ;`Evh)y}KGB>}xVhm`d&48f?G2BZ zgx0Z|8yOoLPM+~H#a4r;>C-1L%R!jicTHga#O`e2WNGMV>1t%*;%s4TX5?z&W^U?gV(MsQ=ICna T>SAK2U_(gB_V+WGUvUBe4j(TZ diff --git a/cpdfmanual.tex b/cpdfmanual.tex index 70a7011..9d544c2 100644 --- a/cpdfmanual.tex +++ b/cpdfmanual.tex @@ -1237,7 +1237,7 @@ tree with no entry being more than one greater than the last). As an alternative to extracting a bookmark file and manipulating the open-status of bookmarks, mass manipulation may be achieved by the following operation: \begin{framed} - \small\verb!cpdf -open-bookmarks-to-level in.pdf -o out.pdf! + \small\verb!cpdf -bookmarks-open-to-level in.pdf -o out.pdf! \end{framed} \noindent A level of 0 will close all bookmarks, level 1 will open just the top level, closing all others etc. To open all of them, pick a sufficiently large level.