diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 65f4e20..a9696dd 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -3641,10 +3641,11 @@ let build_enc () = let print_obj json pdf objspec = let obj = Cpdftweak.find_obj pdf objspec in + let trim s = implode (rev (tl (rev (tl (explode s))))) in if json then print_string (Cpdfyojson.Safe.pretty_to_string (Cpdfjson.json_of_object ~utf8:true pdf (fun _ -> ()) ~no_stream_data:false ~parse_content:false obj)) else - Printf.printf "%S\n" (Pdfwrite.string_of_pdf obj) + print_endline (trim (Printf.sprintf "%S" (Pdfwrite.string_of_pdf obj))) let extract_stream_find_obj pdf objspec = int_of_string objspec diff --git a/cpdfmanual.pdf b/cpdfmanual.pdf index 3915659..4c4ac6b 100644 Binary files a/cpdfmanual.pdf and b/cpdfmanual.pdf differ diff --git a/cpdfmanual.tex b/cpdfmanual.tex index 4ad2ad6..237412a 100644 --- a/cpdfmanual.tex +++ b/cpdfmanual.tex @@ -6559,50 +6559,69 @@ The \texttt{-remove-clipping} operation removes any clipping paths on given page {\small\begin{verbatim} $ cpdf -obj 0 in.pdf -"<\249\157\182F_\153V\175z[\234\196) -('\029\\t>\249\157\182F_\153V\175z[\234\196)]/Info 1351 0 R/Size 1406>>" +<\249\157\182F_\153V\175z[\234\196) +('\029\\t>\249\157\182F_\153V\175z[\234\196)]/Info 1351 0 R/Size 1406>> $ cpdf -obj 1256 in.pdf -"<>16<>]>>/PageMode -/UseOutlines/Names 924 0 R/Outlines 838 0 R/Pages 851 0 R/Type/Catalog>>" +<>16<>]>>/PageMode +/UseOutlines/Names 924 0 R/Outlines 838 0 R/Pages 851 0 R/Type/Catalog>> $ cpdf -obj 1238 out.pdf -"<>" +<> \end{verbatim}} \noindent Alternatively, we may follow a chain of dictionary entries from the trailer dictionary: {\small\begin{verbatim} $ ./cpdf -obj /Root/Pages/Count cpdfmanual.pdf -"133" +133 +\end{verbatim}} + +\noindent Or, from a given object number: + +{\small\begin{verbatim} +$ ./cpdf -obj 1256/PageLabels/Nums cpdfmanual.pdf +[0<>16<>] \end{verbatim}} \noindent We may also begin at a numbered page instead of at the trailer dictionary: {\small\begin{verbatim} ./cpdf -obj P20/Resources/Font/F58/BaseFont cpdfmanual.pdf -"/MCBERL+URWPalladioL-Roma" +/MCBERL+URWPalladioL-Roma \end{verbatim}} -\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}. +\noindent To output data in JSON format instead of PDF format, add \texttt{-json}: -A stream may be extracted with \texttt{-extract-stream} or \texttt{-extract-stream-decompress}, which decompresses it first where possible: +{\small\begin{verbatim} +./cpdf -obj-json 140/Prev/Prev/Prev cpdfmanual.pdf +{ "/Title": 129, "/A": 126, "/Parent": 112, "/Prev": 124, "/Next": 132 } +\end{verbatim}} + +\noindent We can follow array entries as well as dictionary entries by giving the index number into the array - here object 0 (the trailer dictionary), dictionary entry \texttt{/ID}, index number 0: + +{\small\begin{verbatim} +./cpdf -obj 0/ID/[0] hello.pdf +(\232\20625\030\179/\176q:O\202\135\176u\137) +\end{verbatim}} + +\noindent A stream may be extracted with \texttt{-extract-stream} or \texttt{-extract-stream-decompress}, which decompresses it first where possible: {\small\begin{verbatim} $ cpdf -obj 0 hello.pdf -"<>" +<> $ cpdf -obj 4 hello.pdf -"<>" +<> $ cpdf -obj 1 hello.pdf -"<>" +<> $ cpdf -obj 3 hello.pdf -"<>>>>>/MediaBox[0 0 595.275590551 841.88976378] -/Rotate 0/Contents[2 0 R]>>" +/Rotate 0/Contents[2 0 R]>> $ cpdf -extract-stream-decompress 2 hello.pdf -stdout 1 0 0 1 50 770 cm BT/F0 36 Tf(Hello, World!)Tj ET