[pdftex] Simple (?) question about \pdfobj

Duncan Murdoch murdoch.duncan at gmail.com
Sat Mar 5 23:36:36 CET 2011


On 11-03-05 9:34 AM, Heiko Oberdiek wrote:
> On Sat, Mar 05, 2011 at 07:23:19AM -0500, Duncan Murdoch wrote:
>
>> I'm working with Sweave, a literate programming system that produces
>> LaTeX files as the human readable output.  I want to embed
>> information in the resulting .pdf file that gives the relation
>> between the .tex intermediate file and the original inputs, so that
>> viewers using Synctex can be told to jump to the original source.  A
>> while ago I went looking for a standard way to do this and didn't
>> find one, so I invented my own.   I construct a string of values
>> describing the concordance, and embed it in the pdf using this code:
>>
>> \newcommand{\Sconcordance}[1]{%
>>    \ifx\pdfoutput\undefined%
>>    \csname newcount\endcsname\pdfoutput\fi%
>>    \ifcase\pdfoutput\special{#1}%
>>    \else\immediate\pdfobj{#1}\fi}
>
> There is package `ifpdf' to test for pdfTeX in PDF mode
> in a more safe way:
>
> \usepackage{ifpdf}
> \newcommand*{\Sconcordance}[1]{%
>    \ifpdf
>      \special{#1}%
>    \else
>      \immediate\pdfobj{#1}%
>    \fi
> }
>
>> The text that is in the #1 argument has no particular structure
>> specific to PDF files.  Does it need to?
>
> Yes, I recommend it. Otherwise:
> * The object can get lost if the PDF file is rewritten, because
>    the object is unused.
> * A PDF processing program might scan the PDF file differently
>    starting from the beginning to find object, e.g. if the
>    cross ref table is corrupted.
>
>> A typical call looks like
>>
>> \Sconcordance{concordance:doc.tex:doc.Rnw:%
>> 1 21 1 7 0 1 3 4 1 7 0 1 6 1 1 8 0 1 3 6 1 4 0 1 3 1 1 11 0 1 6 2 1 7 0 %
>> 1 3 8 1 11 0 1 4 1 1 20 0 1 5 17 1 7 0 1 5 3 1 8 0 1 4 3 1 9 0 1 4 25 1}
>
> For instance the data can put in a string.
> If you have at most one \Sconcordance call per document,
> then the easiest way is probably to put it into the
> information dictionary as key value pair:
>
>    \pdfinfo{/concordance(concordance:doc.tex:doc.Rnw:1 21 ... 15 1)}
>
> The key is "/concordance", the string value is "(...)".
> In general it's better to ensure that "(...)" is a valid
> PDF string (some characters need escaping like the backslash).
> It can be done with \pdfescapestring:
>
> \usepackage{ifpdf}
> \newcommand*{\Sconcordance}[1]{%
>    \ifpdf
>      \special{#1}%
>    \else
>      \pdfinfo{%
>        /concordance%
>        (\pdfescapestring{#1})%
>      }%
>    \fi
> }
>
> If you want to support older pdfTeX versions that miss \pdfescapestring
> then package pdfescape fills the gap. It also supports LuaTeX:
>
> \usepackage{ifpdf}
> \usepackage{pdfescape}
> \newcommand*{\Sconcordance}[1]{%
>    \ifpdf
>      \special{#1}%
>    \else
>      \begingroup
>        \EdefEscapeString\StringValue{#1}%
>        \pdfinfo{%
>          /concordance%
>          (\StringValue)%
>       \endgroup
>    \fi
> }
>
> If package hyperref is used, then additional information entries
> can be added via option `pdfinfo' (since 6.80b) and hyperref
> takes care of the string conversion:
>
> \usepackage{ifpdf}
> \usepackage{hyperref}[2010/01/11]
> \newcommand*{\Sconcordance}[1]{%
>    \ifpdf
>      \special{#1}%
>    \else
>      \hypersetup{pdfinfo={concordance={#1}}}%
>    \fi
> }
>
>> I am asking this because when I use this with a Beamer document, I
>> end up producing a .pdf file that Acrobat Reader complains about
>> with the message "There was an error opening this document.  Invalid
>> action object."  With most other documents things are fine, so this
>> is conceivably a Beamer bug,
>
> Make a minimal example that shows the problem.

Thanks for all the suggestions, I'll work on them.  In the meantime, 
here's a minimal example where pdflatex version 1.40.11 from TeX Live 
2010 on a Mac produces a file that Adobe Reader 7.1.0 doesn't like:

\documentclass{beamer}

\immediate\pdfobj{concordance}

\begin{document}

\begin{frame}

test of beamer

\end{frame}

\end{document}

For this example I see the error message "There was an error opening 
this document.  The file is damaged and could not be repaired."

Preview on the Mac shows the file with no complaint.

Just in case you want to look at my version of the output, I've put it 
online at <http://www.stats.uwo.ca/faculty/murdoch/temp/test.pdf>.  I'll 
leave it there for a while, but not forever.

(Using pdflatex 1.40.9 from Miktex 2.7 on Windows produces a file that's 
fine.  The Beamer version is probably different too.)

Duncan Murdoch

Duncan Murdoch


More information about the pdftex mailing list