[pdftex] Forward looking object references
Klaus Guntermann
guntermann at informatik.tu-darmstadt.de
Fri Mar 14 10:49:16 CET 2003
Igor Khomyakov writes:
> I am trying to create a PDF document (DVI is not a requirement) that would
> show the total number of pages on each page (e.g. PAGE X OF Y), and do it in
> one front-to-back linear pdfTeX pass! I believe it can be done in PDF by
> using "forward object references" (I also did not think it was possible
> until a colleague of mine suggested this interesting method). For example,
> the output doc can look as follows:
>
> page 1: PAGE 1 OF <reference to 1000 0 R>
> page 2: PAGE 2 OF <reference to 1000 0 R>
> ....
> page 100: PAGE 100 OF <reference to 1000 0 R>
> 1000 0 obj <<...100...>>
This is not that easy for at least two reasons:
- Object references are not allowed within text streams, but in arrays
and dictionaries only. The pdf specification says about object
references:
Any object used as an element of an array or as a value in a
dictionary may be specified by either a direct object or an
indirect reference.
- In general you would not know in advance how much space your total
number is going to take. You would need that information if you want
that text e.g. aligned right in the header or footer of the page or
to position following material properly.
Thus I could only think of the following scenario: put the whole text
"page n of m" with appropriate values of "n" and "m" in a separate
text stream together with proper positioning and formatting and add
this text stream as an additional element to the list of streams for
all the pages.
If you can manage to prepare the open references you could create all
the missing streams at the end.
> Is there a way to achieve this in pdfTeX?
Whether this is possible within pdfTeX is beyond my knowledge of
pdfTeX internals.
But I doubt, that it is really easier than doing a second pass on
the document.
If the document is really large you would need to keep track of a lot
of open references and possibly different positioning, size and font
information to create the streams properly, which could result in a
cumbersome bookkeeping and searching overhead.
If the document is small anyway, just typeset it twice and you are
done.
Klaus
--
Klaus Guntermann <guntermann at informatik.tu-darmstadt.de>
FG Systemprogrammierung, FB Informatik, TU Darmstadt
Wilhelminenstr. 7, 64283 Darmstadt, Germany
More information about the pdftex
mailing list