Finished -gs-malformed

This commit is contained in:
John Whitington 2019-07-02 16:50:39 +01:00
parent a6328dc973
commit ed0a7a800d
1 changed files with 17 additions and 18 deletions

View File

@ -2334,7 +2334,7 @@ let filenames = null_hash ()
(* This now memoizes on the name of the file to make sure we only load each (* This now memoizes on the name of the file to make sure we only load each
file once *) file once *)
let rec get_pdf_from_input_kind ?(decrypt=true) ?(fail=false) ((_, x, u, o, y, revision) as input) op ik = let rec get_pdf_from_input_kind ?(read_lazy=false) ?(decrypt=true) ?(fail=false) ((_, x, u, o, y, revision) as input) op ik =
let failout () = let failout () =
if fail then begin if fail then begin
(* Reconstructed with ghostscript, but then we couldn't read it even then. Do not loop. *) (* Reconstructed with ghostscript, but then we couldn't read it even then. Do not loop. *)
@ -2358,7 +2358,12 @@ let rec get_pdf_from_input_kind ?(decrypt=true) ?(fail=false) ((_, x, u, o, y, r
begin try Hashtbl.find filenames s with begin try Hashtbl.find filenames s with
Not_found -> Not_found ->
let pdf = let pdf =
try pdfread_pdf_of_file ?revision (optstring u) (optstring o) s with try
if read_lazy then
pdfread_pdf_of_channel_lazy ?revision (optstring u) (optstring o) (open_in_bin s)
else
pdfread_pdf_of_file ?revision (optstring u) (optstring o) s
with
_ -> _ ->
if args.gs_malformed then if args.gs_malformed then
begin begin
@ -3548,7 +3553,7 @@ let go () =
| Some CountPages -> | Some CountPages ->
begin match args.inputs with begin match args.inputs with
[(ik, _, _, _, _, _) as input] -> [(ik, _, _, _, _, _) as input] ->
let pdf = get_pdf_from_input_kind ~decrypt:false input (Some CountPages) ik in let pdf = get_pdf_from_input_kind ~read_lazy:true ~decrypt:false input (Some CountPages) ik in
output_page_count pdf output_page_count pdf
| _ -> raise (Arg.Bad "CountPages: must have a single input file only") | _ -> raise (Arg.Bad "CountPages: must have a single input file only")
end end
@ -3572,21 +3577,15 @@ let go () =
| _ -> error "Clean: No output specified" | _ -> error "Clean: No output specified"
end end
| Some Info -> | Some Info ->
let pdf, inname, input = let pdf = get_single_pdf ~decrypt:true (Some Info) true in
match args.inputs with let inname = match args.inputs with (InFile x, _, _, _, _, _)::_ -> x | _ -> "" in
| (InFile inname, _, u, o, _, revision) as input::_ -> Printf.printf "Encryption: %s\n" (getencryption pdf);
pdfread_pdf_of_channel_lazy ?revision (optstring u) (optstring o) (open_in_bin inname), inname, input Printf.printf "Permissions: %s\n" (getpermissions pdf);
| (StdIn, _, u, o, _, revision) as input::_ -> pdf_of_stdin ?revision u o, "", input if inname <> "" then
| (AlreadyInMemory pdf, _, _, _, _, _) as input::_ -> pdf, "", input Printf.printf "Linearized: %b\n" (Pdfread.is_linearized (Pdfio.input_of_channel (open_in_bin inname)));
| _ -> raise (Arg.Bad "cpdf: No input specified.\n") let pdf = decrypt_if_necessary (List.hd args.inputs) (Some Info) pdf in
in Cpdf.output_info args.encoding pdf;
Printf.printf "Encryption: %s\n" (getencryption pdf); Cpdf.output_xmp_info args.encoding pdf
Printf.printf "Permissions: %s\n" (getpermissions pdf);
if inname <> "" then
Printf.printf "Linearized: %b\n" (Pdfread.is_linearized (Pdfio.input_of_channel (open_in_bin inname)));
let pdf = decrypt_if_necessary input (Some Info) pdf in
Cpdf.output_info args.encoding pdf;
Cpdf.output_xmp_info args.encoding pdf
| Some PageInfo -> | Some PageInfo ->
begin match args.inputs, args.out with begin match args.inputs, args.out with
| (_, pagespec, _, _, _, _)::_, _ -> | (_, pagespec, _, _, _, _)::_, _ ->