This commit is contained in:
John Whitington 2024-09-23 16:32:05 +01:00
parent fa831170c3
commit 614af1757a
4 changed files with 35 additions and 4 deletions

View File

@ -429,7 +429,7 @@ let rec ops_of_drawop struct_tree dryrun pdf endpage filename bates batespad num
[]
| TextSection ops ->
let m = mcid () in
if not dryrun then structdata := StDataMCID ("/P", m, None)::!structdata;
if not dryrun then structdata := StDataMCID ("P", m, None)::!structdata;
(if struct_tree && !do_auto_tag then [Pdfops.Op_BDC ("/P", Pdf.Dictionary ["/MCID", Pdf.Integer m])] else [])
@ [Pdfops.Op_BT]
@ ops_of_drawops struct_tree dryrun pdf endpage filename bates batespad num page ops
@ -460,7 +460,7 @@ let rec ops_of_drawop struct_tree dryrun pdf endpage filename bates batespad num
| Tag s ->
let m = mcid () in
if not dryrun then structdata := StDataMCID (s, m, None)::!structdata;
[Pdfops.Op_BDC (s, Pdf.Dictionary ["/MCID", Pdf.Integer m])]
[Pdfops.Op_BDC ("/" ^ s, Pdf.Dictionary ["/MCID", Pdf.Integer m])]
| EndTag -> [Pdfops.Op_EMC]
| STag s -> if not dryrun then structdata =| StDataBeginTree s; []
| EndSTag -> if not dryrun then structdata =| StDataEndTree; []
@ -691,7 +691,7 @@ let write_structure_tree pdf st =
(alt
@ page
@ namespace
@ [("/S", Pdf.Name kind);
@ [("/S", Pdf.Name ("/" ^ kind));
("/P", Pdf.Indirect struct_tree_parent);
("/K", Pdf.Array (map (mktree this_objnum) children))])
in

Binary file not shown.

View File

@ -5210,7 +5210,38 @@ $cpdf -print-struct-tree out.pdf
There are two types of tag we can add manually. One kind is used to tag individual pieces of content. We do this with a \texttt{-tag}/\texttt{-end-tag} pair. Note that nesting is not permitted here. For example, let us tag a heading:
(H1 / Para example)
\begin{framed}
\noindent\small\verb!cpdf -create-pdf AND -draw-struct-tree -draw -mtrans "50 700" !\\
\noindent\small\verb! -font-size 40 -no-auto-tags -tag H1 -bt -text "This is the heading"!\\
\noindent\small\verb! -et -end-tag -auto-tags -mtrans "0 -100" -font-size 20 -leading 25!\\
\noindent\small\verb! -bt -paras "L200pt=This is the first paragraph, which spreads over!\\
\noindent\small\verb!more than one line\nHere is the second, which also has multiple lines..."!\\
\noindent\small\verb! -et AND -o out.pdf!
\noindent\small\verb!!
\noindent\small\verb!!
\noindent\small\verb!!
\end{framed}
\noindent Here is the result, visually:
\bigskip
\fbox{\includegraphics[width=0.3\textwidth]{manualimages/h1.pdf}}
\bigskip
\noindent And here is the structure tree:
\begin{verbatim}
/StructTreeRoot
└──
├── /H1 (1)
│ └──
├── /P (1)
│ └──
└── /P (1)
└──
\end{verbatim}
\noindent\verb!-stag! Begin structure tree branch\\
\noindent\verb!-end-stag! End structure tree branch\\

BIN
manualimages/h1.pdf Normal file

Binary file not shown.