From b43ca58b24a64c079f13e821a51b5d53270a7cde Mon Sep 17 00:00:00 2001 From: John Whitington Date: Thu, 18 Jan 2024 16:20:51 +0000 Subject: [PATCH] Finish -extract-stream --- cpdfcommand.ml | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 29dec8e..61c6b3a 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -3560,12 +3560,24 @@ let build_enc () = Pdfwrite.user_password = args.user; Pdfwrite.permissions = banlist_of_args ()} -let extract_stream pdf objnum decomp = - (* Find obj *) - (* Decompress if appropriate *) - (* Find output filename or stdout *) - (* Output it *) - () +let extract_stream pdf decomp objnum = + let obj = Pdf.lookup_obj pdf objnum in + Pdf.getstream obj; + if decomp then Pdfcodec.decode_pdfstream_until_unknown pdf obj; + 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 obj =