This commit is contained in:
John Whitington 2021-10-12 18:58:37 +01:00
parent d11b6a97bb
commit 2859f9e4ef
2 changed files with 16 additions and 7 deletions

View File

@ -1,4 +1,3 @@
(*FIXME add -output-json-precombine-contents *)
(* cpdf command line tools *) (* cpdf command line tools *)
let demo = false let demo = false
let noncomp = false let noncomp = false
@ -450,6 +449,7 @@ type args =
mutable createpdf_pagesize : Pdfpaper.t; mutable createpdf_pagesize : Pdfpaper.t;
mutable removeonly : string option; mutable removeonly : string option;
mutable jsonparsecontentstreams : bool; mutable jsonparsecontentstreams : bool;
mutable jsonprecombinecontentstreams : bool;
mutable jsonnostreamdata : bool; mutable jsonnostreamdata : bool;
mutable jsondecompressstreams : bool; mutable jsondecompressstreams : bool;
mutable ocgrenamefrom : string; mutable ocgrenamefrom : string;
@ -555,6 +555,7 @@ let args =
createpdf_pagesize = Pdfpaper.a4; createpdf_pagesize = Pdfpaper.a4;
removeonly = None; removeonly = None;
jsonparsecontentstreams = false; jsonparsecontentstreams = false;
jsonprecombinecontentstreams = false;
jsonnostreamdata = false; jsonnostreamdata = false;
jsondecompressstreams = false; jsondecompressstreams = false;
ocgrenamefrom = ""; ocgrenamefrom = "";
@ -645,6 +646,7 @@ let reset_arguments () =
args.createpdf_pagesize <- Pdfpaper.a4; args.createpdf_pagesize <- Pdfpaper.a4;
args.removeonly <- None; args.removeonly <- None;
args.jsonparsecontentstreams <- false; args.jsonparsecontentstreams <- false;
args.jsonprecombinecontentstreams <- false;
args.jsonnostreamdata <- false; args.jsonnostreamdata <- false;
args.jsondecompressstreams <- false; args.jsondecompressstreams <- false;
args.ocgrenamefrom <- ""; args.ocgrenamefrom <- "";
@ -753,7 +755,7 @@ let rec decrypt_if_necessary (_, _, user_pw, owner_pw, was_dec_with_owner, _) op
* pages. This is pervented by permissions above, but in the case that the * pages. This is pervented by permissions above, but in the case that the
* owner password is blank (e.g christmas_tree_lights.pdf), we would end * owner password is blank (e.g christmas_tree_lights.pdf), we would end
* up here. *) * up here. *)
soft_error "Combine pages: both files must be unencrypted for this operation." soft_error "Combine pages: both files must be unencrypted for this operation, or add -decrypt-force"
| _ -> | _ ->
match Pdfcrypt.decrypt_pdf_owner owner_pw pdf with match Pdfcrypt.decrypt_pdf_owner owner_pw pdf with
| Some pdf -> | Some pdf ->
@ -773,7 +775,7 @@ let rec decrypt_if_necessary (_, _, user_pw, owner_pw, was_dec_with_owner, _) op
if args.debugcrypt then Printf.printf "Managed to decrypt with user password\n"; if args.debugcrypt then Printf.printf "Managed to decrypt with user password\n";
if operation_allowed pdf permissions op if operation_allowed pdf permissions op
then pdf then pdf
else soft_error "User password cannot give permission for this operation" else soft_error "User password cannot give permission for this operation. Supply owner or add -decrypt-force."
| _ -> | _ ->
if args.debugcrypt then Printf.printf "Failed to decrypt with user password: raising soft_error"; if args.debugcrypt then Printf.printf "Failed to decrypt with user password: raising soft_error";
soft_error "Failed to decrypt file: wrong password?" soft_error "Failed to decrypt file: wrong password?"
@ -1500,6 +1502,9 @@ let setgsquiet () =
let setjsonparsecontentstreams () = let setjsonparsecontentstreams () =
args.jsonparsecontentstreams <- true args.jsonparsecontentstreams <- true
let setjsonprecombinecontentstreams () =
args.jsonprecombinecontentstreams <- true
let setjsonnostreamdata () = let setjsonnostreamdata () =
args.jsonnostreamdata <- true args.jsonnostreamdata <- true
@ -2194,6 +2199,9 @@ and specs =
("-output-json-parse-content-streams", ("-output-json-parse-content-streams",
Arg.Unit setjsonparsecontentstreams, Arg.Unit setjsonparsecontentstreams,
" Parse content streams"); " Parse content streams");
("-output-json-precombine-content-streams",
Arg.Unit setjsonprecombinecontentstreams,
" Precombine content streams");
("-output-json-no-stream-data", ("-output-json-no-stream-data",
Arg.Unit setjsonnostreamdata, Arg.Unit setjsonnostreamdata,
" Skip stream data for brevity"); " Skip stream data for brevity");
@ -2549,7 +2557,7 @@ let really_write_pdf ?(encryption = None) ?(is_decompress=false) mk_id pdf outna
end end
else else
soft_error soft_error
"You must supply -recrypt here, or provide the owner password." "You must supply -recrypt here, or add -decrypt-force, or provide the owner password."
end end
end; end;
begin begin
@ -3409,7 +3417,7 @@ let write_json output pdf =
~parse_content:args.jsonparsecontentstreams ~parse_content:args.jsonparsecontentstreams
~no_stream_data:args.jsonnostreamdata ~no_stream_data:args.jsonnostreamdata
~decompress_streams:args.jsondecompressstreams ~decompress_streams:args.jsondecompressstreams
~precombine_page_content:false (* FIXME add arg *) ~precombine_page_content:args.jsonprecombinecontentstreams
pdf pdf
| File filename -> | File filename ->
let f = open_out filename in let f = open_out filename in
@ -3418,7 +3426,7 @@ let write_json output pdf =
~parse_content:args.jsonparsecontentstreams ~parse_content:args.jsonparsecontentstreams
~no_stream_data:args.jsonnostreamdata ~no_stream_data:args.jsonnostreamdata
~decompress_streams:args.jsondecompressstreams ~decompress_streams:args.jsondecompressstreams
~precombine_page_content:false (* FIXME add arg *) ~precombine_page_content:args.jsonprecombinecontentstreams
pdf; pdf;
close_out f close_out f
@ -3467,7 +3475,7 @@ let go () =
inputs inputs
pdfs))) pdfs)))
then then
soft_error "Merge requires the owner password for all encrypted files." soft_error "Merge requires the owner password for all encrypted files, or -decrypt-force."
else else
let pdfs = let pdfs =
if args.merge_add_bookmarks then if args.merge_add_bookmarks then

View File

@ -1,5 +1,6 @@
%Document -j to input JSON %Document -j to input JSON
%Document -decrypt-force %Document -decrypt-force
%Document -output-json-precombine-object-streams and friends
\documentclass{book} \documentclass{book}
% Edit here to produce cpdfmanual.pdf, cpdflibmanual.pdf, pycpdfmanual.pdf etc. % Edit here to produce cpdfmanual.pdf, cpdflibmanual.pdf, pycpdfmanual.pdf etc.
\usepackage{comment}\excludecomment{cpdflib}\excludecomment{pycpdflib} \usepackage{comment}\excludecomment{cpdflib}\excludecomment{pycpdflib}