diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 2bc83df..87f0a37 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -3647,11 +3647,11 @@ let extract_stream pdf decomp objnum = let data = match obj with | Pdf.Stream {contents = (_, Pdf.Got x)} -> x - | _ -> mkbytes 0 + | _ -> raise (Pdf.PDFError "Stream not found") in match args.out with | NoOutputSpecified -> - () + raise (Pdf.PDFError "No output specified") | File outname -> let fh = open_out_bin outname in output_string fh (Pdfio.string_of_bytes data); @@ -3688,7 +3688,8 @@ let print_obj json pdf objspec = let obj = if objnum = 0 then pdf.Pdf.trailerdict else Pdf.lookup_obj pdf objnum in match Pdf.lookup_chain pdf obj chain with | Some x -> write x - | None -> () + | None -> + Pdfe.log "Chain not found"; exit 2 in match explode objspec with | 'P'::more -> @@ -3709,7 +3710,10 @@ let print_version () = let replace_obj pdf objspec obj = let split_chain str = map (fun x -> "/" ^ x) (tl (String.split_on_char '/' str)) in let chain = split_chain objspec in - Pdf.replace_chain pdf chain obj + try + Pdf.replace_chain pdf chain obj + with + e -> Pdfe.log "Chain not found"; exit 2 (* Call out to GhostScript to rasterize. Read back in and replace the page contents with the resultant PNG. *) let rasterize antialias downsample device res annots quality pdf range = diff --git a/cpdfmanual.pdf b/cpdfmanual.pdf index 48ed51d..3db19ea 100644 Binary files a/cpdfmanual.pdf and b/cpdfmanual.pdf differ diff --git a/cpdfmanual.tex b/cpdfmanual.tex index aacfc00..1502412 100644 --- a/cpdfmanual.tex +++ b/cpdfmanual.tex @@ -6582,7 +6582,7 @@ $ ./cpdf -obj /Root/Pages/Count cpdfmanual.pdf "/MCBERL+URWPalladioL-Roma" \end{verbatim}} -\noindent To output data in JSON format instead of PDF format, use \texttt{-obj-json} in place of \texttt{-obj}. +\noindent If the object does not exist, Cpdf will exit with code 2. To output data in JSON format instead of PDF format, use \texttt{-obj-json} in place of \texttt{-obj}. A stream may be extracted with \texttt{-extract-stream} or \texttt{-extract-stream-decompress}, which decompresses it first where possible: diff --git a/cpdftweak.ml b/cpdftweak.ml index 053be62..ce721be 100644 --- a/cpdftweak.ml +++ b/cpdftweak.ml @@ -263,7 +263,6 @@ let replace_dict_entry pdf key value search = Pdf.objselfmap (dict_entry_single_object f pdf) pdf; pdf.Pdf.trailerdict <- dict_entry_single_object f pdf pdf.Pdf.trailerdict -(* FIXME no need to self map here, since nothing changes *) let print_dict_entry ~utf8 pdf key = let f d = match Pdf.lookup_direct pdf key d with