3

Given the auxiliary file test.xbb

%%Title: test.pdf
%%Creator: extractbb 20180506
%%BoundingBox: 0 0 300 343
%%HiResBoundingBox: 0.000000 0.000000 300.290000 342.810000
%%PDFVersion: 1.4
%%Pages: 17
%%CreationDate: Mon Jan  7 18:06:49 2019

produced from input file test.pdf using the extractbb utility

extractbb test.pdf

Is there an easy way to read the value of the %%Pages: key from test.xbb by means of some internal command defined in the graphics package? I know that graphics parses user provided xbb files in order to determine bounding-box coordinates for binary-type or compressed image files that TeX cannot read on its own. Can it do the same for %%Pages: out of the box?

AlexG
  • 54,894

1 Answers1

5

enter image description here

\documentclass{article}

\begin{document}


{%
\def\%#1:#2@{\expandafter\xdef\csname ZZ#1\endcsname{#2}}%
\endlinechar`\@ %
\catcode`\%=0 \sbox0{\input{test.xbb}}}%


Pages: \ZZPages
\end{document}
David Carlisle
  • 757,742
  • Would you please explain why \input must be placed into an sbox? To prevent any typeset output? – AlexG Jan 07 '19 at 20:35
  • @AlexG try without:-) yes as you say it throws away any accidental typeset result, in fact you get a typeset @ from the final newline, which could be avoided in other ways but.... – David Carlisle Jan 07 '19 at 20:36
  • Ok. Very smart! And what about the double percent sign in the input? I can see only one % in \def\%... – AlexG Jan 07 '19 at 20:39
  • @AlexG if % has catcode 0 (escape character ) then %% references the same command as \% the command with name % just as \\ references the command with name \ – David Carlisle Jan 07 '19 at 20:42
  • Thank you, @David. I think I got it (after 5 reads or so :-) ). – AlexG Jan 07 '19 at 20:47
  • What is the sense of the % (=escape chars) at the end of the lines? – Ulrike Fischer Jan 07 '19 at 20:53