Rework syntax for -print-obj

This commit is contained in:
John Whitington 2024-07-01 17:01:56 +01:00
parent 42155139a6
commit 4b59f3e4ae
4 changed files with 8 additions and 6 deletions

View File

@ -6,6 +6,7 @@ o Build PDF files from JPEG2000 (.jp2, .jpf/.jpx) files
o Mark a file as PDF/UA compliant, or remove such marking o Mark a file as PDF/UA compliant, or remove such marking
o Verify compliance to PDF/UA via the Matterhorn protocol o Verify compliance to PDF/UA via the Matterhorn protocol
o Extract, edit and reapply document structure tree o Extract, edit and reapply document structure tree
o Print structure tree summary
o Split structure tree when splitting PDF to save size o Split structure tree when splitting PDF to save size
o Combine structure trees when stamping PDFs o Combine structure trees when stamping PDFs
o Set the natural language of a file o Set the natural language of a file

View File

@ -3444,6 +3444,7 @@ let extract_stream pdf decomp objnum =
commas. Begins with P and it's a page number then a (possibly empty) chain. commas. Begins with P and it's a page number then a (possibly empty) chain.
Otherwise it's an object number (0 = trailerdict). *) Otherwise it's an object number (0 = trailerdict). *)
let print_obj pdf objspec = let print_obj pdf objspec =
let split str = map (fun x -> "/" ^ x) (tl (String.split_on_char '/' str)) in
let simple_obj obj = let simple_obj obj =
let obj = if obj = 0 then pdf.Pdf.trailerdict else Pdf.lookup_obj pdf obj in let obj = if obj = 0 then pdf.Pdf.trailerdict else Pdf.lookup_obj pdf obj in
Printf.printf "%S\n" (Pdfwrite.string_of_pdf obj) Printf.printf "%S\n" (Pdfwrite.string_of_pdf obj)
@ -3459,10 +3460,10 @@ let print_obj pdf objspec =
let number, chain = let number, chain =
let digits, rest = cleavewhile isdigit more in let digits, rest = cleavewhile isdigit more in
List.nth (Pdf.page_reference_numbers pdf) (int_of_string (implode digits) - 1), List.nth (Pdf.page_reference_numbers pdf) (int_of_string (implode digits) - 1),
begin match String.split_on_char ',' (implode rest) with [""] -> [] | x -> x end begin match split (implode rest) with [""] -> [] | x -> x end
in in
chain_obj number chain chain_obj number chain
| '/'::more -> chain_obj 0 (String.split_on_char ',' (implode ('/'::more))) | '/'::more -> chain_obj 0 (split (implode ('/'::more)))
| [] -> simple_obj 0 | [] -> simple_obj 0
| _ -> simple_obj (int_of_string objspec) | _ -> simple_obj (int_of_string objspec)

Binary file not shown.

View File

@ -5266,7 +5266,7 @@ We can print an abbreviated form of the structure tree to standard output with \
This JSON file can be edited, for example to change text strings, and reapplied with \texttt{cpdf -replace-struct-tree out.json in.pdf -o out.pdf}. If extra objects are required, they should be introduced with negative object numbers: cpdf will renumber them on import so as not to clash with any existing numbers. This JSON file can be edited, for example to change text strings, and reapplied with \texttt{cpdf -replace-struct-tree out.json in.pdf -o out.pdf}. If extra objects are required, they should be introduced with negative object numbers: cpdf will renumber them on import so as not to clash with any existing numbers.
To remove a structure tree from a PDF, we can use \texttt{-remove-dict-entry} from Chapter \ref{chap:misc} i.e \texttt{cpdf -remove-struct-entry /StructTreeRoot in.pdf -o out.pdf}. To remove a structure tree from a PDF, we can use \texttt{-remove-dict-entry} from Chapter \ref{chap:misc} i.e \texttt{cpdf -remove-dict-entry /StructTreeRoot in.pdf -o out.pdf}.
\section{Verifying conformance to PDF/UA} \section{Verifying conformance to PDF/UA}
@ -5400,7 +5400,7 @@ Once we are sure a file complies to PDF/UA, in terms of both machine and human c
\noindent\verb!cpdf -remove-clipping [<range>] in.pdf -o out.pdf! \noindent\verb!cpdf -remove-clipping [<range>] in.pdf -o out.pdf!
\vspace{1.5mm} \vspace{1.5mm}
\noindent\verb!cpdf -obj <obj num> in.pdf! \noindent\verb!cpdf -obj <object specification> in.pdf!
\vspace{1.5mm} \vspace{1.5mm}
\noindent\verb!cpdf -extract-stream[-decompress] <obj num> in.pdf [-o out.dat | -stdout]! \noindent\verb!cpdf -extract-stream[-decompress] <obj num> in.pdf [-o out.dat | -stdout]!
@ -5618,14 +5618,14 @@ $ cpdf -obj 1238 out.pdf
\noindent Alternatively, we may follow a chain of dictionary entries from the trailer dictionary: \noindent Alternatively, we may follow a chain of dictionary entries from the trailer dictionary:
{\small\begin{verbatim} {\small\begin{verbatim}
$ ./cpdf -obj /Root,/Pages,/Count cpdfmanual.pdf $ ./cpdf -obj /Root/Pages/Count cpdfmanual.pdf
"133" "133"
\end{verbatim}} \end{verbatim}}
\noindent We may also begin at a numbered page instead of at the trailer dictionary: \noindent We may also begin at a numbered page instead of at the trailer dictionary:
{\small\begin{verbatim} {\small\begin{verbatim}
./cpdf -obj P20/Resources,/Font,/F58,/BaseFont cpdfmanual.pdf ./cpdf -obj P20/Resources/Font/F58/BaseFont cpdfmanual.pdf
"/MCBERL+URWPalladioL-Roma" "/MCBERL+URWPalladioL-Roma"
\end{verbatim}} \end{verbatim}}