Finish -extract-stream

This commit is contained in:
John Whitington 2024-01-18 16:20:51 +00:00
parent cc08db98d0
commit b43ca58b24
1 changed files with 18 additions and 6 deletions

View File

@ -3560,12 +3560,24 @@ let build_enc () =
Pdfwrite.user_password = args.user; Pdfwrite.user_password = args.user;
Pdfwrite.permissions = banlist_of_args ()} Pdfwrite.permissions = banlist_of_args ()}
let extract_stream pdf objnum decomp = let extract_stream pdf decomp objnum =
(* Find obj *) let obj = Pdf.lookup_obj pdf objnum in
(* Decompress if appropriate *) Pdf.getstream obj;
(* Find output filename or stdout *) if decomp then Pdfcodec.decode_pdfstream_until_unknown pdf obj;
(* Output it *) let data =
match obj with
| Pdf.Stream {contents = (_, Pdf.Got x)} -> x
| _ -> mkbytes 0
in
match args.out with
| NoOutputSpecified ->
() ()
| File outname ->
let fh = open_out_bin outname in
output_string fh (Pdfio.string_of_bytes data);
close_out fh
| Stdout ->
output_string stdout (Pdfio.string_of_bytes data)
let print_obj pdf objnum = let print_obj pdf objnum =
let obj = let obj =