Regularize exit codes for PDF exploration commands

This commit is contained in:
John Whitington
2024-12-31 14:59:10 +00:00
parent d50a94eb1a
commit 0d7f0d593d
4 changed files with 9 additions and 6 deletions

View File

@ -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 =

Binary file not shown.

View File

@ -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:

View File

@ -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