[pdftex] Forward looking object references

Igor Khomyakov igorkh at optonline.net
Fri Mar 21 19:22:17 CET 2003


Hi,

Thank you Hans, Sebastian, Klaus, and Laurent for your replies. In this
email I will try to justify/clarify the goal I am trying to achieve, and
provide some examples. I believe that this method will work nicely for PDF
output, and can be used successfully for wide range of applications (e.g.
number of total pages, table of contents, summary sections, etc.). I hope
that if nobody knows how to achieve this in existing version of pdfTeX, Han
(The Thanh) would pick it up, and tell us how it can be done, or whether
there is a chance this functionality will be included into future releases.

Why do I need  to avoid the second pass? We typeset thousands of PDF
documents (reports) on daily basis. It takes hours to complete this job. If
we could avoid the second pass (in our case the second pass is only needed
to typeset  "Page n of m" on every page), it would save us tremendous amount
of time, resources, etc.

pdfTeX supports PDF xforms. The following TeX script outputs "Page n of 1"
on each page it generates, it uses xform (xobject/form), the output is nice,
the only problem is that it does not know the total number of pages in the
beginning, and therefore prints 1 instead:

\setbox0=\hbox{\folio}
\pdfxform 0
Page \folio of \pdfrefxform\pdflastxform
\vfill\eject
Page \folio of \pdfrefxform\pdflastxform
....
Page \folio of \pdfrefxform\pdflastxform
\bye

If we could postpone the creation of xforms in pdftex but at the same time
were allowed to create the reference to the xform that will be created
later, that would allow us to generate PDFs w/ "total pages" on each page in
one single pass, for example:

\newcount\x
\x=\pdfnewxformreference
Page \folio of \pdfrefxform\x % page 1
\vfill\eject
Page \folio of \pdfrefxform\x  % page 2
....
Page \folio of \pdfrefxform\x  % page 99999
\setbox0=\hbox{\folio}
\pdfxform obj \number\x 0
\bye

Below please find the PDF example that was initially created with pdfTeX,
and then edited manually. This example shows that in PDF we can use forward
references! Please check out object 1000. I believe that this document can
be quite easily generated in one pass -- the object (xform) is at the very
end of the file -- we do have necessary information by that time.

I just wanted to thank everybody again for their participation in this
discussion,

Best regards,
Igor.

------- PDF EXAMPLE --- CUT HERE ---
%PDF-1.4
4 0 obj <<
/Length 186
>>
stream
1 0 0 1 91.925 759.927 cm
BT
/F51 9.963 Tf 0 0 Td[(P)40(age)-278(1)-278(of)]TJ
ET
q
1 0 0 1 45.021 0 cm
/Fm1 Do
Q
1 0 0 1 -19.925 -2.461 cm
q
[]0 d
0 J
0.398 w
0 0.199 m
468 0.199 l
S
Q
endstream
endobj
3 0 obj <<
/Type /Page
/Contents 4 0 R
/Resources 2 0 R
/MediaBox [0 0 595.276 841.89]
/Parent 7 0 R
>> endobj
8 0 obj <<
/Font << /F51 6 0 R >>
/ProcSet [ /PDF /Text ]
>> endobj
2 0 obj <<
/Font << /F51 6 0 R >>
/XObject << /Fm1 1000 0 R >>
/ProcSet [ /PDF /Text ]
>> endobj
11 0 obj <<
/Length 186
>>
stream
1 0 0 1 91.925 759.927 cm
BT
/F51 9.963 Tf 0 0 Td[(P)40(age)-278(2)-278(of)]TJ
ET
q
1 0 0 1 45.021 0 cm
/Fm1 Do
Q
1 0 0 1 -19.925 -2.461 cm
q
[]0 d
0 J
0.398 w
0 0.199 m
468 0.199 l
S
Q
endstream
endobj
10 0 obj <<
/Type /Page
/Contents 11 0 R
/Resources 9 0 R
/MediaBox [0 0 595.276 841.89]
/Parent 7 0 R
>> endobj
9 0 obj <<
/Font << /F51 6 0 R >>
/XObject << /Fm1 1000 0 R >>
/ProcSet [ /PDF /Text ]
>> endobj
6 0 obj <<
/Type /Font
/Subtype /Type1
/BaseFont /Helvetica
>> endobj
7 0 obj <<
/Type /Pages
/Count 2
/Kids [3 0 R 10 0 R]
>> endobj
13 0 obj <<
/Type /Catalog
/Pages 7 0 R
/PTEX.Fullbanner (This is pdfTeX, Version 3.14159-1.10a)
>> endobj
14 0 obj <<
/Producer (pdfTeX-1.10a)
/Creator (TeX)
/CreationDate (D:20030320203100)
>> endobj
1000 0 obj <<
/Type /XObject
/Subtype /Form
/MyXObjectFormAttribute /MyValue
/BBox [0 0 55.539 7.034]
/FormType 1
/Matrix [1 0 0 1 0 0]
/Resources 8 0 R
/Length 34
>>
stream
BT
/F51 9.963 Tf 0 0 Td[(99999)]TJ
ET
endstream
endobj
trailer
<<
/Size 15
/Root 13 0 R
/Info 14 0 R
>>
%%EOF
-------------- END OF PDF --- CUT HERE ----



More information about the pdftex mailing list