Debian Codegraph @

texmf-dist/doc/pdftex/samplepdftex/samplepdf.tex

raw
1 % $Id: samplepdf.tex 749 2016-04-26 23:03:45Z karl $
2 % (This samplepdf.tex file is public domain.)
3 %
4 % This example shows how to use pdfTeX primitives. High-level macros are
5 % provided by macros packages like LaTeX or ConTeXt. We present basic
6 % set of commands, extended with some more sophisticated issues (like MP
7 % to PDF conversion). All the functionality other than provided by
8 % pdfTeX itself is commented by default. Please follow the code below
9 % and uncomment fragments you want.
10
11 % Many new features has been implemented since the first release of pdfTeX. To
12 % make this sample version independent, we use compatibility sections.
13
14 \def\ifversion#1.#2#3#4 {% 1.20, 1.30.0 ...
15 \ifnum\pdftexversion<#1#2#3
16 \notsupported
17 \else
18 \supported
19 \fi}
20
21 % to trick \if..\fi balancing
22 % \def\otherwise{\else}
23 % \def\endif{\fi}
24
25 \def\supported{\expandafter\iftrue}
26 \def\notsupported{\expandafter\iffalse}
27
28 \def\feature#1.#2#3#4#{\dofeature{#1#2#3}{#1.#2#3#4}}
29 \long\def\dofeature#1#2#3#4\endfeature{%
30 \ifnum#1>\pdftexversion
31 #3 not supported by this version of \pdfTeX.\par
32 \else#4\fi}
33
34 \def\pdfTeX{pdf\TeX}
35 \def\cs#1{{\tt\string#1}}
36 \def\newpage{\null\vfill\eject}
37
38 \parindent=0pt
39
40 \input pdfcolor.tex % simple macros to use color with pdftex;
41 % color names derived from dvicolor.tex
42
43 % Unless mentioned explicitly, the default values of new parameters
44 % are: 1) zero for integer/dimension parameters; 2) empty for tokens
45 % parameters.
46
47 % In previous versions of pdfTeX, integer parameters took their corresponding
48 % values from pdftex.cfg config file. Starting from pdfTeX 1.20, the config file
49 % id not read at all. All the parameters are specified in TeX code, optionally
50 % dumped into format file.
51
52 \pdfoutput=1 % positive value turns on PDF output;
53 % this parameter can not be changed after the pdf
54 % output has been opened
55
56 \pdfcompresslevel=0 % compression level for text and image; allowed
57 % values are 0..9;
58 % 0 = no compression
59 % 1 = fastest compression
60 % 9 = best compression
61 % 2..8 = something between
62 % numbers out of range will be fixed to the most
63 % closed allowed value. Recommended value for most
64 % cases is 6 or 7.
65
66 \ifversion 1.40.0
67 \pdfobjcompresslevel=0 % having pdfTeX 1.40.0 or higher and PDF 1.5 or higher,
68 % we can also control non-stream compression level. See
69 % pdfTeX manual for details.
70 \fi
71
72 \pdfdecimaldigits=3 % number of digits after decimal point for real
73 % number in pdf output; the larger value the
74 % better accuracy but also larger output size;
75 % allowed range of values is 0..4
76
77 %\pdfmovechars=2 % 1 turns on moving lower chars 0..32 to higher
78 % slots for fonts with last char code < 128,
79 % 2 or larger even for fonts with last char code > 127
80 % (rather obsolete)
81
82 \pdfpkresolution=300 % resolution for bitmap (PK) fonts; allowed values
83 % are 72..1200, default is 600
84
85 \pdfuniqueresname=0 % positive value turns on prepending unique
86 % prefix for each named resources
87 % pdftex-0.14[ef] has a bug with this feature
88 % turned on
89
90 % dimension parameters
91
92 \pdfhorigin=1in % horizontal origin (offset);
93 % for common purposes it is advised to use
94 % \hoffset
95
96 \pdfvorigin=1in % vertical origin (offset); similar to \pdfhorigin,
97 % advised to use \voffset
98
99
100 \pdfpagewidth=8.5in % paper size of the pdf output (letter in this case)
101 \pdfpageheight=11in
102
103 \pdflinkmargin=1pt % margin added to dimensions of link (see below)
104
105 \pdfdestmargin=10pt % margin added to dimensions of destination (see
106 % below)
107
108 \pdfthreadmargin=1em % margin added to dimensions of bead in article thread
109 % (see below)
110
111 % tokens registers
112
113 \pdfpagesattr={/MyPageAttribute /MyValue}
114 % optional attributes for the root Pages object;
115 % all pages inherit these attributes
116
117 \pdfpageattr={/MyPagesAttribute /MyValue}
118 % optional attributes for individual pages;
119 % attributes specified here overwrite any
120 % attributes given by `\pdfpagesattr' (see PDF spec for details)
121
122 \pdfpageresources{/MyPageResourceAttribute /MyValue}
123 % optional page resources dict content
124
125 % And some more parameters that need special care.
126
127 \ifversion 1.30.0 \else
128 \let\pdfforcepagebox\pdfoptionalwaysusepdfpagebox
129 \fi
130
131 \pdfforcepagebox=0 % a page box of PDF inclusions to be used
132 % as a clipping area. Here we use default (CropBox)
133 % \pdfforcepagebox is a shortened synonym of
134 % obsolete \pdfoptionalwaysusepdfpagebox.
135
136 \ifversion 1.30.0 \else
137 \let\pdfminorversion\pdfoptionpdfminorversion
138 \fi
139
140 \pdfminorversion=5 % version of created PDF files and allowed PDF inclusions.
141 % The default value is 4 that is enough in most cases (PDF 1.4).
142 % However, some pdfTeX features presented here requires
143 % PDF 1.5. Starting from pdfTeX 1.30.0, the command is called
144 % \pdfminorversion.
145
146
147
148 \ifversion 1.30.0 \else
149 \let\pdfinclusionerrorlevel\pdfoptionpdfinclusionerrorlevel
150 \fi
151
152 \pdfinclusionerrorlevel=0 % If the version of included PDF is greater than
153 % the one being typeset, by default an error is issued.
154 % If \pdfinclusionerrorlevel is set to one, warning only
155 % (synonym of obsolete \pdfoptionpdfinclusionerrorlevel).
156
157 \ifversion 1.30.0
158 \pdfimagehicolor=1 % enables 16-bit colors for PNG inclusions;
159 % defaults to 1 if \pdfminorversion>=5,
160 \pdfimageapplygamma=1 % enables gamma correction for PNG inclusions,
161 \pdfgamma=1000 % sets pdfTeX `device gamma,'
162 \pdfimagegamma=2200 % sets image gamma, if can't be taken from the image itself.
163 \fi % (see below for details).
164
165 % Version of pdftex can be accessed via \pdftexversion and \pdftexrevision.
166
167 This is version \the\pdftexversion\ (revision \pdftexrevision) of \pdfTeX.
168
169 % Version of created PDF (and the highest allowed version of PDF inclusions)
170 % can be controlled with \pdfminorversion. In pdfTeX versions below 1.30.0, the
171 % primitive was called \pdfoptionpdfminorversion.
172
173 This file is PDF version 1.\the\pdfminorversion.
174 \bigskip
175
176 % Font resource in the pdf output has the form
177 % "/F<number> <object number> 0 R", where <number> is accessible via
178 % \pdffontname and <object number> via \pdffontobjnum.
179
180 Font \fontname\font\ has resource name tag
181 \pdffontname\font\ and object number \pdffontobjnum\font\ in the PDF output.
182 Font size is \pdffontsize\font.\par
183
184 \feature 1.30.0 {Disabling ligatures}
185
186 Ligatures: ffont, fint, flint\par
187 {\font\noli=cmr10 at\pdffontsize\font
188 \pdfnoligatures\noli No ligatures: ffont, fint, flint}
189 \bigskip
190
191 \endfeature
192
193 % \pdfincludechars can be used to ensure certain characters to be
194 % included in the font file. Normally only used characters are
195 % included (subset is created).
196
197 \pdfincludechars\font{ABCDEF}
198
199 % pdfTeX ignores \special's text if \pdfoutput is set, unless they have
200 % prefix "pdf:" or "PDF:" (in this case the prefix is not written out, of
201 % course). \pdfliteral is intended to replace \special in pdf output mode.
202
203 Changing color can be done by inserting `raw' PDF code, like
204 \pdfliteral direct {0 1 1 0 k} % switch color to cmyk red
205 this.
206
207 \special{PDF:0 g} % switch color back to black; \special can be
208 % used with prefix "pdf:" or "PDF:", optionally appended with
209 % "direct:"
210 % A `direct' keyword is optional; it ensures that what one
211 % types into \pdfliteral is inserted literally indeed.
212 % Otherwise pdfTeX moves the space origin to the place after
213 % the last types item on the page, inserts the user code and
214 % restores its internal position. It's recommended to use \pdfliteral
215 % instead of \special
216
217 A simple picture:
218 \pdfliteral {q 1 j 0 1 0 rg 0 0 1 RG 0 0 10 10 re B Q}
219
220 % pdfTeX keeps the origin point of coordinates in the lower-left corner of the
221 % page (native PDF space origin). \pdfliteral used without `direct' keyword
222 % moves this position temporarily to the point user probably expect; current
223 % position on the page. That is why the rectangle above appears in-line.
224 % Drawing anything relative to the page origin is a bit problematic. In most
225 % cases, one can't simply say `\pdfliteral direct {q <paiting operators> Q}'.
226 % That is because q..Q operators can't appear inside BT..ET blocks.
227 %
228 % Starting from pdfTeX 1.30.0, another \pdfliteral modifier can be used instead
229 % of `direct'. If the keyword is `page', pdfTeX closes internal text block with `ET'
230 % before putting the literal content; like with `direct', without translation.
231
232 \feature 1.30.0 {\cs\pdfliteral{ \tt page} keyword}
233 ...and now look at the lower-left corner of the page.\par
234 \pdfliteral page {q 1 j 0 1 0 rg 0 0 1 RG 0 0 10 10 re B Q}
235 \pdfliteral page {q -1 0 0 1 612 0 cm .5 g}\hfill Do you like that?\pdfliteral page {Q}
236 \endfeature
237
238 % Every page in PDF document has its own graphic state, automatically restored
239 % by the viever application. In example, unless set explicitly, text colour at
240 % the beginning of the every page is always black, regardless the text color at
241 % the end of the previous page. This may be a little bit confusing for those
242 % who get used to dvi output and color macros based on Postscript specials. In
243 % the case of PDF, passing text colour (as well as any other graphic
244 % properties) between pages requires much more care. Since normally we don't
245 % know where TeX is going to break tyhe page, one probably need to use \mark(s)
246 % register(s) for page-wise graphic stack, as it is in pdfcolor.tex macro input above.
247
248 \feature 1.40.0 {Graphic stack}
249 \def\pdfsetcolor#1{}% disable generic color support of pdfcolor.tex
250
251 % pdfTeX 1.40.0 introduces graphic stack support. \pdfcolorstackinit primitive
252 % introduces new graphic stack and returns its number. Here we create a
253 % page-wise color stack with black as an initial stack value. \pdfcolorstack
254 % command operates on graphic stacks.
255
256 \chardef\Color=\pdfcolorstackinit page direct{0 g}
257 default color,
258 \pdfcolorstack\Color set{1 1 0 0 k}
259 some new default
260 \pdfcolorstack\Color push{0 1 1 0 k}
261 red,
262 \pdfcolorstack\Color push{1 0 1 0 k}
263 green,
264 \vfill\eject
265 still green,
266 \pdfcolorstack\Color pop
267 red again,
268 \pdfcolorstack\Color pop
269 default again,
270 \pdfcolorstack\Color set{0 g}
271 back to black.
272
273 \endfeature
274
275 \bigskip
276
277 % User-defined object can be inserted into the pdf output by \pdfobj. The
278 % object is written out as specified, apart from case when \pdfobj is used with
279 % "stream" option. An object created by \pdfobj is held in memory and will
280 % not be written to the pdf output, unless 1) the object is referenced by
281 % saying \pdfrefobj <object number>; or 2) \pdfobj is preceded by
282 % \immediate. The object number of the last object created by \pdfobj is
283 % accessible via \pdflastobj
284
285 \pdfobj{(Hello)} % the simplest case: a string "Hello"
286 \pdfrefobj \pdflastobj % mark the object to be written out; it can be
287 % understood as a reference to the object
288
289 % Note, that the object you type must comply the syntax of one of PDF data
290 % types (dictionary, array, string, stream, number, ...). The object created
291 % with `\pdfobj{Hello}' is incorrect and may lead to parser crash. This issue
292 % may not be noticed until one try to refer to the object anyhow or compress it
293 % using non-zero \pdfobjectstreams.
294
295 \immediate \pdfobj stream % create the object as a stream a write it to
296 {Hello} % the pdf output immediately
297
298 \pdfobj stream % create the object as a stream with
299 attr {/MyStreamAttribute /MyValue} % additional attributes
300 {Hello}
301 \pdfrefobj \pdflastobj
302
303 \pdfobj file {obj.dat} % read the object contents from file obj.dat
304 \pdfrefobj \pdflastobj
305
306 \pdfobj stream % read the stream contents from file obj.dat
307 file {obj.dat}
308 \pdfrefobj \pdflastobj
309
310 \pdfobj stream % read the stream contents from file obj.dat
311 attr {/MyStreamAttribute /MyValue} % with additional attributes
312 file {obj.dat}
313 \pdfrefobj \pdflastobj
314
315 % \pdflastobj is always global, as all others \pdflast* read-only integers (see
316 % below). PDF object numbers are unique within the document. One may notice, that
317 % if \pdfobj is preceded by \immediate, \pdflastobj seems to return subsequent
318 % values (i.e 5,6,7,8...). Since \pdfobj is not the only command that creates PDF
319 % objects, one can't simply assume, that if current \pdflastobj returns 5, the
320 % next one will always return 6. Thus, pdfTeX provides a forward-referencing
321 % mechanism (introduced in pdfTeX 1.20).
322
323 \feature 1.20 {Forward object referencing}
324
325 \pdfobj reserveobjnum
326 We have an access to PDF object numbers, even before defining those objects.
327 \pdfobj useobjnum\pdflastobj {(This is object number \the\pdflastobj)}
328 \pdfrefobj\pdflastobj
329
330 \endfeature
331
332 % TeX boxes can be written into so-called XObject form, which is very
333 % similar to a normal page in the pdf output. Additional data can be
334 % inserted to the XObject form dictionary itself as well as the Resource
335 % dictionary of the XObject form
336
337 \setbox0=\hbox{This is a box saved as a XObject form}
338 \pdfxform
339 attr {/MyXObjectFormAttribute /MyValue}
340 resources {/MyXObjectFormResourceAttribute /MyValue}
341 0
342
343 % Similarly to \pdfobj, the object created by \pdfxform is held in memory
344 % and is not written to the pdf output, unless 1) the object is referenced
345 % by saying \pdfrefxform <object number>; or 2) \pdfxform is preceded by
346 % \immediate. The object number of the last XObject form created
347 % by \pdfxform is accessible via \pdflastxform. Note that
348 % \immediate\pdfxform does not typeset anything; it just ensures that the
349 % XObject form is written out to the output. To display the form, it is
350 % necessary to say \pdfrefxform <object number> in the intended place.
351 % Another point is that \pdfrefxform acts similarly rather to rules than to
352 % boxes concerning dimensions and space setting. It's highly recommended to
353 % wrap \pdfrefxform by a box in order to ensure spacing will be correct.
354
355 \hbox{\pdfrefxform \pdflastxform}
356
357 % Similarly to \pdflastobj, \pdflastxform returns the PDF object number assigned
358 % for XObject form just created. pdfTeX also provides \pdfxformname primitive, that
359 % returns a resource name identifier of the XObject written to PDF output with given
360 % object number.
361
362 XObject above has been written as object \the\pdflastxform.
363
364 \feature 1.30.0 {Access to XObject names}
365
366 Its resource name tag is \pdfxformname\pdflastxform\
367 ({\tt/Fm\pdfxformname\pdflastxform\ \the\pdflastxform\space 0 R}
368 entry in page resources dictionary).
369
370 \endfeature
371
372 \bigskip
373
374 % Thanks to Taco Hoekwater pdfTeX 1.30.0 and higher provides precise time
375 % measuring mechanism. \pdfelapsedtime primitive returns the time elapsed from
376 % the current run start. Time is measured in `scaled seconds' meaning that 65536
377 % scaled seconds is 1 second. There is also \pdfresettimer primitive that causes
378 % zeroing the internal clock.
379
380 {\catcode`\p=12 \catcode`\t=12 \gdef\WITHOUTPT#1pt{#1}}
381 \def\withoutpt#1{\expandafter\WITHOUTPT#1} % returns float-like string
382
383 \feature 1.30.0 {Precise timer}
384
385 \dimen0=\pdfelapsedtime sp
386 \pdfresettimer
387 It took \withoutpt\the\dimen0 \ seconds to typeset the whole stuff above.
388 To typeset the last two sentences it took \the\pdfelapsedtime\ `scaled seconds'
389 (1s/65536).
390 \bigskip
391
392 \endfeature
393
394 % Taco Hoekwater has also implemented random number support (introduced in 1.30.0)
395
396 \feature 1.30.0 {Random numbers}
397
398 Random seed initialized to \the\pdfrandomseed.
399 \pdfsetrandomseed\dimen0 % just saved elapsed time
400 We may change it, lets say to \the\pdfrandomseed.\par
401
402 10 uniformly distributed random numbers [0..100]:
403 \count100=0 \loop
404 \pdfuniformdeviate101
405 \advance\count100 by1
406 \ifnum\count100<10,
407 \repeat.\par
408
409 10 normally distributed random numbers:
410
411 \count100=0 \loop
412 \dimen0=\pdfnormaldeviate sp
413 $\withoutpt\the\dimen0$%
414 \advance\count100 by1
415 \ifnum\count100<10,
416 \repeat.\par
417
418 \bigskip
419
420 \endfeature
421
422 % Starting from pdfTeX 1.30.0, there is an expandable string comparison in pdfTeX.
423 % You can compare two strings lexicographically using \pdfstrcmp{<str1>}{<str2>}.
424 % The command returns -1, 0, or 1 as a comparison result.
425 % Both strings are expanded before being compared.
426 % \feature 1.30.0 {String comparison}
427 % \pdfstrcmp{a}{aa} returns -1 since 'a'<'aa'
428 % \pdfstrcmp{aa}{aa} returns 0 since 'aa'='aa'
429 % \pdfstrcmp{aaa}{abc} returns -1 since 'aaa'<'abc'
430 % \pdfstrcmp{abc}{ABC} returns 1 since 'aaa'>'ABC'
431 % \endfeature
432 % This is still experimental, as well as regex support.
433
434 % Starting from version 1.40.0 there are two handy primitives for absolute
435 % values comparison. This is e-TeX however...
436 % \feature 1.40.0 {Absolute \cs\if's}\fi\endfeature
437
438 % Thanks to Heiko Oberdiek, starting from pdfTeX 1.30.0 a set of expandable
439 % string handlers are available. \pdfescapestring converts its parameter into a
440 % form readable for PDF interpreters, escaping those characters that can be used
441 % in PDF string objects without quotation. Similarly, \pdfescapename converts its
442 % argument into PDF name, replacing special PDF characters with their hexadecimal
443 % representation preceded by `#'. \pdfescapehex takes an ASCII code of each
444 % character of its argument and converts this number into hexadecimal form. Last
445 % but not least, \pdfunescapehex treats each pair of characters as a hexadecimal
446 % number and returns an ASCII characters of given codes. All those commands
447 % expand their arguments before applying conversion.
448
449 \feature 1.30.0 {PDF string handling}
450
451 \def\sometext{Some text/(1)}
452 If there is a text `{\tt\sometext}',\par
453 in PDF string one should use {\tt(\pdfescapestring{\sometext}},\par
454 and in PDF name it would be {\tt/\pdfescapename {\sometext}}.\par
455 In hex form it looks like {\tt<\pdfescapehex{\sometext}>},\par
456 but you can always reverse it to get {\tt\pdfunescapehex{\pdfescapehex{\sometext}}}.
457 \bigskip
458
459 \endfeature
460
461 % Also handling external files has been greatly improved. Starting from pdfTeX 1.30.0
462 % you can check external files modification date, file size and even md5 check sum.
463
464 \feature 1.30.0 {External file handling}
465
466 The source of this document is {\tt\pdffilesize{\jobname}} bytes long. Last modification date
467 is {\tt\pdffilemoddate{\jobname}}. The md5 sum is {\tt\pdfmdfivesum{\jobname}}.
468 Bytes 7 to 13 of the source are hex {\tt\pdffiledump offset 7 length 7{\jobname}}
469 (string `\pdfunescapehex{\pdffiledump offset 7 length 7 {\jobname}}').
470
471 \endfeature
472
473 % \pdfsavepos saves coordinates of the current position (basepoint) on the page
474 % relative to lower-left corner. \pdflastxpos and \pdflastypos are available
475 % while shipping out the page. Both are integers; the position is expressed in
476 % scaled points. Starting from pdfTeX 1.40.0, availavle also in DVI mode.
477
478 \pdfsavepos
479 \write16{Position: X=\number\pdflastxpos sp, Y=\number\pdflastypos sp.}
480
481 \newpage
482
483 % pdfTeX 1.20 and higher allows to get the object number of already typeset page
484
485 \feature 1.20 {Page object reference}
486
487 The previous page has been written as object \pdfpageref1.
488
489 \endfeature
490
491 % Images can be included with pdftex using \pdfximage. Supported formats
492 % are determined by file name extension:
493 % .pdf/.PDF: PDF
494 % .png/.PNG: PNG
495 % .jpg/.JPG/.jpeg/.JPEG: JPEG
496 %
497 % Sorry, TIFF files are no longer supported.
498 %
499 % pdfTeX itself does not support EPS and Postscript codes at all, but
500 % it is possible to include Metapost output. EPS files can be converted to
501 % PDF for use with pdfTeX. See below for further info about using Metapost
502 % and EPS.
503
504 \pdfximage {pic.pdf} % read image pic.pdf (search for it in TEXINPUTS path)
505
506 % It also possible to select which page to include. Pages are numbered from
507 % 1. Out-of-range values are fixed to 1 and bitmapped images have always 1
508 % page. To include let's say the 2nd page of a pdf image, one can use
509 % \pdfximage page 2 {file.pdf}
510
511 % Similarly to \pdfobj, the image created by \pdfximage is held in memory
512 % and is not written to the pdf output, unless 1) the image is referenced
513 % by saying \pdfrefximage <object number>; or 2) \pdfximage is preceded by
514 % \immediate. The object number of the last image created by \pdfximage is
515 % accessible via \pdflastximage. Note that \immediate\pdfximage does not
516 % typeset anything; it just ensures that the image is written out to the
517 % output. To display the image, it is necessary to say
518 % \pdfrefximage <object number> in the intended place. Another point is
519 % \pdfrefximage act similarly rather to rules than to boxes concerning
520 % dimensions and space setting. In order to make images act as boxes
521 % (concerning dimensions and spacing), it's necessary to wrap them into a
522 % box.
523
524 \hbox{\pdfrefximage \pdflastximage}
525
526 % Since a pdf image may have more than 1 page, the number of the last image
527 % opened by \pdfximage is accessible via \pdflastximagepages
528
529 The last image has \the\pdflastximagepages\ page(s).
530
531 % The dimensions of the image can be also controlled via <rule spec>. The
532 % default values are zero for depth and `running' for height and width. If
533 % all of them are given, the image will be scaled to fit the specified
534 % values. If some of them (but not all) are given, the rest will be set to
535 % a value corresponding to the remaining ones so as to make the image size
536 % to yield the same proportion of width : (height + depth) as the original
537 % image size, where depth is treated as zero. If none of them is given then
538 % the image will take its natural size. An image inserted at its natural
539 % size often has a resolution of \pdfimageresolution (or 72 if
540 % \pdfimageresolution is set to zero) given in dots per inch in the output
541 % file, but some images may contain data specifying the image resolution,
542 % and in such a case the image will be scaled to the original resolution.
543 % The dimension of the image can be accessed by enclosing the \pdfrefximage
544 % command to a box and checking the dimensions of the box.
545
546 \pdfximage width 6cm {pic.pdf} % set the image width and keep the
547 \pdfrefximage \pdflastximage % `nature' proportion width : height
548
549 \pdfximage height 4cm {pic.png} % set the image height and keep the
550 % `nature' proportion width : height
551
552 \edef\MyImg{\the\pdflastximage} % save the image number for later reuse
553 \pdfrefximage\MyImg
554
555 \pdfximage width 6cm height 4cm % set both image width and height; the
556 {pic.jpg} % final proportion width : height may be
557 % different from the `nature' one
558
559 \pdfimageresolution=72 % to open an image at 72 dpi
560 \pdfximage {pic.pdf}
561 \setbox0=\hbox{\pdfrefximage\pdflastximage} % get dimensions of the image
562 % in order to include the image
563 % at a specific resolution
564 \dimen0=.06\wd0 % calculate the image width at 1200 dpi (0.06 = 72/1200)
565 \pdfximage % include the image at resolution 1200 dpi
566 width \dimen0 {pic.pdf} % by setting image width to the calculated value
567 \pdfrefximage \pdflastximage
568
569 % While working with bitmap graphic it might be more convenient to operate on
570 % pixels rather then dimension units. Starting from version 1.30.0, pdfTeX offers
571 % a special, scalable unit called `px'. The real value associated with `px' is controlled
572 % via \pdfpxdimen primitive. It used to be a count register defaulted to 65536 (1pt = 1px).
573 % Starting from pdfTeX 1.40.0, \pdfpxdimen is a true dimen defaulted to 1bp, that implies
574 % 72dpi resolution.
575
576
577 \feature 1.30.0 {Scalable {\tt px} unit}
578
579 \ifversion 1.40.0
580 \pdfpxdimen=0.06bp % 1200dpi -> 72/1200
581 \else
582 \pdfpxdimen=3946 % 1200dpi -> 72*65781/1200
583 \fi
584
585 640 pixels in 1200dpi makes \dimen0=640px \the\dimen0.
586
587 \endfeature
588
589
590 % ... Be aware of rounding error significant for large resolutions
591 % 1200 pixels in 1200dpi makes \dimen0=1200px \the\dimen0. -> 72.25342pt < 72.27
592
593 \newpage
594
595 % While embedding PDF image one may decide which area of the image (mediabox,
596 % cropbox, bleedbox, trimbox or artbox) should be treated as a final (visible)
597 % bounding box. There is \pdfoptionalwaysusepdfpagebox parameter that specifies
598 % the default behaviour (1 for mediabox, 2 for cropbox, 3 for bleedbox, 4 for
599 % trimbox and 5 for artbox). For sake of backward compatibility, if set to 0
600 % cropbox is used. Starting from pdfTeX 1.30.0, a synonym \pdfforcepagebox is
601 % used. One may also override the default settings by providing page box
602 % specification in \pdfximage syntax. In example, \pdfximage trimbox {<file>}
603 % causes clipping the image to the trimbox area. Obviously, those settings take an
604 % effect only if the desired box page is defined in the image being included.
605 % According to PDF spec, PDF page boxes act as follows:
606 % mediabox % the entire page area (the only one always present)
607 % cropbox % the visible page area (defaults to mediabox)
608 % bleedbox % the page area with trimming margins (defaults to cropbox)
609 % trimbox % the page area without bleeds (defaults to cropbox)
610 % artbox % the logical page content (defaults to cropbox)
611
612 % pdfTeX takes care about version of included PDF images. By default, an error is
613 % issued if this version is newer than the PDF being created (controlled by
614 % \pdfminorversion). If the \pdfoptionpdfinclusionerrorlevel is set to 0, only
615 % warning is issued. Starting pdfTeX 1.30.0 \pdfinclusionerrorlevel synonym is used
616 % instead.
617
618 % Thanks to Taco Hoekwater pdfTeX 1.30.0 and higher provides advanced PNG
619 % inclusions handling. Nonzero \pdfimagehicolor parameter enables embedding
620 % of PNG images with 16 bit wide color channels at their full color resolution.
621 % This functionality is automatically disabled if \pdfminorversion<5, and automatically
622 % enabled if \pdfminorversion>=5
623 % Another primitive -- \pdfimageapplygamma -- enables gamma correction of embedded
624 % PNG files on the base of two parameters:
625 % \pdfgamma % device gamma for pdfTex
626 % \pdfimagegamma % image gamma (used if one can't be derived from the image)
627 % Both values are integers measured in promile (1000 = gamma 1.0)
628 % All the parameters of gamma correction have to be set before any data
629 % is written to the PDF output; thus we put them at the very beginning of this sample.
630
631 % \ifx\undefined\quitvmode % primitive `\leavevmode' introduced in pdfTeX 1.30.0
632 % \let\quitvmode\leavevmode
633 % \fi
634
635 \pdfximage width8cm {pic16.png}%
636 \pdfrefximage\pdflastximage
637 The image had originally 16 bits-per-channel.
638
639 \feature 1.21 {Image color depth info}
640 Embedded one has \the\pdflastximagecolordepth\ bits-per-channel;
641 \endfeature
642
643 \feature 1.30.0 {16-bit color mode for PNG inclusions}
644 the image has been read in 16-bit color resolution.
645 \endfeature
646
647 \feature 1.30.0 {Gamma correction}
648 Try out different gamma parameters. % we have to set them before any data
649 \endfeature % is written to the output
650
651 \bigskip
652
653 % From pdfTeX 1.21 \pdfximage command can be followed by `colorspace <objnum>',
654 % where <objnum> is a number of user-defined color space object. Simply speaking,
655 % we may instructs the viewer, how the image should be rendered. However, this
656 % works only for JPEGs. Here we perform some sort of `color management' by
657 % applying a color profile to the JPEG image.
658
659 % Be aware; this is viewer dependent.
660
661 \feature 1.21 {User-defined image color space hook}
662
663 \immediate\pdfobj
664 stream
665 attr {/N 3 /Alternate /DeviceRGB}
666 file {rgb.icc} % color profile
667
668 \immediate\pdfobj{[/ICCBased \the\pdflastobj\space 0 R]}
669
670 \edef\objnum{\the\pdflastobj}
671
672 \pdfximage width 8cm colorspace\objnum {pic.jpg}
673 \pdfrefximage\pdflastximage
674 The image is calibrated with ICC profile.
675
676 \immediate\pdfobj
677 stream attr
678 {/FunctionType 4
679 /Domain [0 1 0 1 0 1]
680 /Range [0 1 0 1 0 1]}{{exch pop exch pop 0 exch 0 exch}}
681
682 \immediate\pdfobj % don't treat it serious %)
683 {[/DeviceN [/Red /Green /Blue] /DeviceRGB \the\pdflastobj\space 0 R]}
684
685 \edef\objnum{\the\pdflastobj}
686
687 \pdfximage width8cm colorspace\objnum {pic.jpg}
688 \pdfrefximage\pdflastximage
689 Hacked image color space.
690
691 \endfeature
692
693 % Thanks to Hans Hagen, pictures created by Metapost can be used directly with
694 % pdftex. The following files come from ConTeXt distribution. Another
695 % place to get them is http://www.tug.org/applications/pdftex/, where
696 % is also possible to get the latest driver file for using LaTeX graphicx
697 % package with pdftex.
698
699 \input supp-mis.tex % supp-mis.tex is loaded by supp-pdf.tex
700 \input supp-pdf.tex % automatically, so the above line could be left
701 % out (it's given here to make clear what all files
702 % are needed to use \convertMPtoPDF)
703
704 % the figure cmr10.103 was created by running Metapost on cmr10.mf
705
706 %\convertMPtoPDF {filename} {x scale} {y scale}
707 %\convertMPtoPDF{cmr10.103}{1}{1}
708 \newpage
709
710 % It is possible to have Metapost code inside the tex sources and call
711 % Metapost to generate the figure before calling \convertMPtoPDF.
712
713 % define some contants that will be used in the Metapost code
714 \def\pointA{(50, 50)}
715 \def\pointB{(400, 250)}
716
717 \newwrite\mpfile % temporary file for metapost code
718 \immediate\openout\mpfile = \jobname.mp
719
720 \immediate \write \mpfile {%
721 prologues := 1;
722 def drawleaf(expr A, B, C) =
723 pickup pencircle scaled 4bp;
724 draw (0, 0) {dir 60} .. A .. {dir 60} B withcolor C;
725 pickup pencircle scaled 2bp;
726 draw A {dir 75} .. {dir 45} B withcolor C;
727 draw A {right} .. {dir 75} B withcolor C;
728 enddef;
729 beginfig(0);
730 drawleaf(\pointA, \pointB, .6green);
731 d := .5 xpart \pointB;
732 currentpicture := currentpicture reflectedabout ((d, 0), (d, 1));
733 endfig;
734 beginfig(1);
735 drawleaf(\pointA, \pointB, .6blue);
736 currentpicture := currentpicture reflectedabout (\pointA, \pointB);
737 endfig;
738 end;
739 }
740 \immediate \closeout \mpfile % close the file before running Metapost
741
742 % Now we call Metapost to generate the ps output; this is system-dependent
743 % and has been tested for web2c only. It is necessary to have
744 %
745 % shell_escape = t
746 %
747 % in texmf.cnf in order to run it.
748 %
749 % Starting from pdfTeX 1.21a, one may test if this option is enabled using
750 % \ifeof condition (distribution dependent):
751
752 \feature 1.21 {Shell escape detection (via \cs{ifeof})}
753 Shell escape (via \cs{ifeof}) seems to be
754 \ifeof18 disabled\else enabled\fi.
755 \endfeature
756
757 % ...pdfTeX 1.30.0 introduces its own primitive integer flag
758
759 \feature 1.30.0 {Shell escape detection (via \cs\pdfshellescape)}
760 Shell escape (via \cs\pdfshellescape) seems to be
761 \ifnum\pdfshellescape=2 enabled (restricted)\fi%
762 \ifnum\pdfshellescape=1 enabled\fi%
763 \ifnum\pdfshellescape=0 disabled\fi.
764 \endfeature
765
766 % Uncomment line below, if Metapost is available on your system (should be!)
767 % \immediate \write 18 {mpost \jobname.mp} % call Metapost on \jobname.mp
768 \convertMPtoPDF{\jobname.0}{1}{1}
769 \convertMPtoPDF{\jobname.1}{1}{1}
770
771 \newpage
772
773 % EPS pictures cannot be inserted directly by pdfTeX, but it's possible to
774 % convert them to PDF using a Postscript-to-PDF converter, like
775 % Ghostscript. The below example calls epstopdf (available
776 % from http://www.tug.org/applications/pdftex), which preprocess the EPS
777 % and afterwards uses Ghostscript to convert to PDF.
778
779 % Uncomment line below, if there is epstopdf utility available in your system
780
781 %\immediate \write 18 {epstopdf --outfile=tmp.pdf cmr10.103} % call epstopdf
782 \pdfximage height \vsize {tmp.pdf} % insert the PDF converted from EPS
783 \topskip=0pt
784 \pdfrefximage \pdflastximage
785 \newpage
786
787 % some text to try using threads
788
789 \def\text{%
790 Ah! perhaps a burning match might be some good, if she could draw it from
791 the bundle and strike it against the wall, just to warm her fingers. She
792 drew one out---"scratch!" how it sputtered as it burnt! It gave a warm,
793 bright light, like a little candle, as she held her hand over it. It was
794 really a wonderful light. It seemed to the little girl that she was sitting
795 by a large iron stove, with polished brass feet and a brass ornament. How
796 the fire burned! and seemed so beautifully warm that the child stretched
797 out her feet as if to warm them, when, lo! the flame of the match went out,
798 the stove vanished, and she had only the remains of the half-burnt match in
799 her hand.
800
801 She rubbed another match on the wall. It burst into a flame, and
802 where its light fell upon the wall it became as transparent as a veil,
803 and she could see into the room. The table was covered with a snowy
804 white table-cloth, on which stood a splendid dinner service, and a
805 steaming roast goose, stuffed with apples and dried plums. And what
806 was still more wonderful, the goose jumped down from the dish and
807 waddled across the floor, with a knife and fork in its breast, to
808 the little girl. Then the match went out, and there remained nothing
809 but the thick, damp, cold wall before her.
810
811 She lighted another match, and then she found herself sitting
812 under a beautiful Christmas-tree. It was larger and more beautifully
813 decorated than the one which she had seen through the glass door at
814 the rich merchant's. Thousands of tapers were burning upon the green
815 branches, and colored pictures, like those she had seen in the
816 show-windows, looked down upon it all. The little one stretched out
817 her hand towards them, and the match went out.
818
819 The Christmas lights rose higher and higher, till they looked to
820 her like the stars in the sky. Then she saw a star fall, leaving
821 behind it a bright streak of fire. "Some one is dying," thought the
822 little girl, for her old grandmother, the only one who had ever
823 loved her, and who was now dead, had told her that when a star
824 falls, a soul was going up to God.
825
826 She again rubbed a match on the wall, and the light shone round
827 her; in the brightness stood her old grandmother, clear and shining,
828 yet mild and loving in her appearance. "Grandmother," cried the little
829 one, "O take me with you; I know you will go away when the match burns
830 out; you will vanish like the warm stove, the roast goose, and the
831 large, glorious Christmas-tree." And she made haste to light the whole
832 bundle of matches, for she wished to keep her grandmother there. And
833 the matches glowed with a light that was brighter than the noon-day,
834 and her grandmother had never appeared so large or so beautiful. She
835 took the little girl in her arms, and they both flew upwards in
836 brightness and joy far above the earth, where there was neither cold
837 nor hunger nor pain, for they were with God.
838 }
839
840 \pdfannot % generic annotation
841 %
842 width 10cm % the dimension of the annotation can be controlled
843 height 0cm % via <rule spec>; if some of dimensions in
844 depth 4cm % <rule spec> is not given, the corresponding
845 % value of the parent box will be used.
846 { %
847 /Subtype /Text % text annotation
848 % /Open true % if given then the text annotation will be opened
849 % by default
850 /Contents % text contents
851 (This text is from THE LITTLE MATCH-SELLER by Hans Christian
852 Andersen)
853 }
854
855 \def\colsep{\qquad} % column separator
856 \setbox0=\vbox{%
857 \baselineskip=1.2em plus 1pt minus 1pt
858 \hsize=2in
859 \tolerance=1000
860 \rightskip=0pt plus 1em
861 \hfuzz=1em
862 \parskip=\baselineskip
863 \null % will use \vsplit to remove this null box and
864 % insert \splittopskip glue to top of the
865 % first column. I don't know how to make the
866 % first column have the same height as other
867 % columns so have to use this trick to ensure
868 % that all columns will have \splittopskip glue
869 % properly inserted at the top
870 \text
871 \vfil}
872
873 \setbox1=\vsplit0 to 0pt % remove the null box and insert \splittopskip glue
874 \setbox3=\copy0 % make a copy of box0 for later use
875
876 % Using thread by explicit determination which boxes will belong to a thread
877
878 \setbox2=\hbox{}
879 \loop
880 \setbox1=\vsplit0 to .75\vsize
881 \setbox2=\hbox{\unhbox2 \vtop{%
882 \pdfthread % add a bead to the thread with id=`num 1' (given
883 % below)
884 % <rule spec> % dimensions of the bead can be controlled
885 % via <rule spec>; if some of dimensions in
886 % <rule spec> is not given, the corresponding
887 % value of the parent box will be used. If
888 % \pdfthreadmargin is not zero then its value
889 % will be added to the margins of the bead
890 %
891 % additional attributes of thread
892 attr {/I <</Title (THE LITTLE MATCH-SELLER by Hans Christian)>>}
893 %
894 % identifier specification (exactly one of the
895 % following must be specified):
896 %
897 num 1 % num identifier (must be positive), or
898 % name {thread1} % name identifier; \pdfthread with the same id
899 % will be joined together. Attributes of the
900 % final thread is the last one if any was
901 % given.
902 \unvbox1}\colsep}
903 \ifdim \ht0 > 0pt \repeat
904 \box2
905
906 \newpage
907
908 % Using thread by automatic determination which boxes will belong to a
909 % thread; \pdfstartthread has the same syntax as \pdfthread, apart that it
910 % must be followed by a \pdfendthread. \pdfstartthread and the
911 % corresponding \pdfendthread must end up in vboxes with the same
912 % nesting level; all vboxes between them with the same nesting level will
913 % be added into the thread. Note that during output routine if there are
914 % other newly created boxes which have the same nesting level as vboxes
915 % containing \pdfstartthread and \pdfendthread, they will be also added
916 % into the thread, which is probably not what we want. To avoid such
917 % unconsidered behaviour, it's often enough to wrap the box that shouldn't
918 % belong to the thread by another box to change the nesting level.
919
920 \setbox0=\vbox{%
921 \pdfstartthread
922 attr {/I <</Title (THE LITTLE MATCH-SELLER by Hans Christian)>>}%
923 name {thread2}%
924 \unvbox3
925 \pdfendthread
926 }
927 \setbox2=\hbox{}
928 \loop
929 \setbox1=\vsplit0 to .75\vsize
930 \setbox2=\hbox{\unhbox2 \vtop{\unvbox1}\colsep}
931 \ifdim \ht0 > 0pt \repeat
932 \box2
933
934 \newpage
935
936 \pdfdest % destination for link and outlines
937 %
938 % identifier specification (exactly one of the
939 % following must be specified):
940 %
941 num 1 % num identifier (must be positive), or
942 % name {dest1} % name identifier. Must be unique in one document
943 %
944 % appearance of destination (exactly one of the
945 % following must be specified):
946 %
947 fit % fit whole page in window
948 % fith % fit whole width of page
949 % fitv % fit whole height of page
950 % fitb % fit whole "Bounding Box" page
951 % fitbh % fit whole width of "Bounding Box" of page
952 % fitbv % fit whole height of "Bounding Box" of page
953 % fitr <rule spec> % fit the rectangle specified by <rule spec>; if
954 % some of dimensions in <rule spec> is not given,
955 % the corresponding value of the parent box will be
956 % used. If \pdfdestmargin is not zero then its
957 % value will be added to the margins of the
958 % rectangle
959 % xyz % goto the current position
960
961 This is a page containing destination `num 1'
962
963 \newpage
964
965 % \pdfstartlink and \pdfendlink are similar to \pdfstartthread and
966 % \pdfendthread, but they must end up in hboxes instead of vboxes
967
968 \leftline{This is a link to destination
969 \pdfstartlink % start a link
970 %
971 height 10pt % dimensions of the link can be controlled
972 depth 3pt % via <rule spec>; if some of dimensions in
973 % <rule spec> is not given, the corresponding
974 % value of the parent box will be used. If
975 % \pdflinkmargin is not zero then its value
976 % will be added to the margins of the link
977 %
978 attr{/C [0.9 0 0] % additional attributes of link
979 /Border [0 0 2]} %
980 %
981 % action specification (exactly one of the
982 % following must be specified):
983 %
984 goto % goto action
985 %
986 % file{file.pdf} % optional file specification; can be used only with
987 % `goto' action or `thread' action (see below). If
988 % action identifier is name then there should be a
989 % destination or a thread with same name identifier
990 % in the file; if action identifier is number then it
991 % means page number for `goto' action (in this case it
992 % will take effect as `fitb' specification) and index
993 % number of thread for `thread' action (the first
994 % thread in a document has index number 0)
995 %
996 % goto action identifier (exactly one of the following
997 % must be specified):
998 %
999 num 1 % goto destination with num identifier
1000 % name{dest1} % goto destination with name identifier
1001 % page 1 {/Fit} % goto page 1 and fit the whole page
1002 %
1003 %
1004 % thread % thread action; start to read a thread
1005 %
1006 %file{file.pdf} % optional file specification
1007 %
1008 % thread action type (exactly one of the following
1009 % must be specified):
1010 %
1011 % num 1 % read thread with num identifier id=`num 1'
1012 % name{thread2} % read thread with name identifier id=`name{thread2}'
1013 %
1014 %
1015 % user{ % user-defined action; a URI action can be specified
1016 % % as below
1017 % /Subtype /Link
1018 % /A <<
1019 % /Type /Action
1020 % /S /URI
1021 % /URI (http://www.tug.org/)
1022 % >>}
1023 `num 1'%
1024 \pdfendlink % end of link; if \pdfstartlink and
1025 % \pdfendlink end up in different hboxes (in this
1026 % case the boxes must have the same box nesting
1027 % level), all hboxes between them will be treated
1028 % as part of the link. Line breaks and even page
1029 % breaks are allowed between \pdfstartlink and
1030 % \pdfendlink
1031 }
1032
1033 \feature 1.40.0 {Last link object}
1034 The link is object \the\pdflastlink.
1035 \endfeature
1036
1037 % more link examples
1038
1039 \leftline{%
1040 This is a link to the
1041 \pdfstartlink
1042 goto
1043 page 1 {/FitB}% % goto the 1st page and fit the page BBox in the
1044 % window
1045 first page%
1046 \pdfendlink}
1047
1048 \leftline{%
1049 This is a link to the
1050 \pdfstartlink
1051 thread num 1 % read the thread `num 1'
1052 thread `num 1'%
1053 \pdfendlink}
1054
1055 \leftline{%
1056 This is a link to
1057 \pdfstartlink
1058 attr{ /Border [0 0 0]} % make the bbox of the link invisible
1059 user {% % a named action (undocumented in PDF spec)
1060 /Subtype /Link
1061 /A <<
1062 /S /Named
1063 /N /GoBack
1064 >>}%
1065 \Cyan the previous view\Black % color text inside the link
1066 \pdfendlink}
1067
1068 \leftline{%
1069 This is a link to
1070 \pdfstartlink user{%
1071 /Subtype /Link
1072 /A <<
1073 /Type /Action
1074 /S /URI
1075 /URI (http://www.fi.muni.cz/)
1076 >>}%
1077 \Red our faculty\Black
1078 \pdfendlink}
1079
1080 {\hsize2in \raggedright \noindent
1081 This is an example of
1082 \pdfstartlink
1083 attr{ /Border [0 0 0]} % make the bbox of the link invisible
1084 goto page 1 {/FitB}%
1085 \Red multiple line link. Make sure that the link and
1086 its end must be in horizontal mode and the parent boxes must have the
1087 same box nesting level.\Black
1088 \pdfendlink
1089 A common mistake here is using \cs{\pdfstartlink} at the
1090 beginning of the text without \cs{\indent}, \cs{\noindent}
1091 or \cs{\leavevmode}, so \cs{\pdfstartlink}
1092 will end up in vertical mode and cause an error.
1093 \par}
1094
1095 % A sound or movie annotation can be created as below. Using such kinds of
1096 % annotation or Java script causes the pdf output to be system-dependent.
1097 % More info about this topic can be found in PDF spec.
1098
1099 % \leftline{%
1100 % \pdfannot width 4in height 0in depth 3in {%
1101 % /Subtype /Movie
1102 % /Movie << /F (MovieFile.mov) >>}
1103 % An example of movie annotation}
1104
1105 % \leftline{%
1106 % \pdfannot width 0in height 0in depth 0in {%
1107 % /Subtype /Sound
1108 % /Sound << /F (SoundFile.wav) >>}
1109 % An example of sound annotation}
1110
1111 % \leftline{%
1112 % \pdfannot width 0in height 0in depth 0in {%
1113 % /Subtype /Movie
1114 % /Movie << /F (SoundFile.wav) >>}
1115 % Sound can be also embedded using Movie annotation}
1116
1117 % outlines (bookmarks):
1118 \pdfoutline % outline entry specification
1119 %
1120 goto num 1 % action specification. This is the same as the action
1121 % specification of `\pdfstartlink'
1122 %
1123 count 3 % number of direct subentries of this entry, 0 if this
1124 % entry has no subentries (in this case it may be
1125 % omitted). If after `count' follows an negative number
1126 % then all subentries will be closed and the absolute
1127 % value of this number specifies the number of
1128 % direct subentries (see the following entries)
1129 %
1130 {Outline 1} % text contents of outline entry
1131
1132 \pdfoutline goto num 1 count -2{Outline 1.1}
1133 \pdfoutline goto num 1 {Outline 1.1.1}
1134 \pdfoutline goto num 1 {Outline 1.1.2}
1135 \pdfoutline goto num 1 {Outline 1.2}
1136 \pdfoutline goto num 1 {Outline 1.3}
1137 \pdfoutline goto page 1 {/Fit} {Outline 2}
1138
1139 \newpage
1140
1141 % Transformations are done by changing transformation matrices. See PDF spec for
1142 % more details how to use it. Generally, a transformation matrix is given as six
1143 % real numbers followed by operator `cm'. Before doing any transformation we must
1144 % store current graphic state (by operator `q') and restore it (by operator `Q')
1145 % after transformation. `q' and `Q' operators acts more or less like `gsave' and
1146 % `grestore' in Postscript. See examples below. Make sure that *no spacing*
1147 % can be produced during transformation and afterwards we must adjust spacing `by
1148 % hand'.
1149
1150 \font\f=cmb10 at 50pt
1151 \setbox0=\hbox{\f Rotated text}
1152 \setbox1=\hbox{\f Scaled text}
1153 \setbox2=\hbox{\f Skewed text}
1154
1155 \newdimen\d
1156 \newbox\tmpbox
1157 \def\avoidboxdimen#1{%
1158 \setbox\tmpbox=\hbox{\box#1}%
1159 \wd\tmpbox=0pt
1160 \ht\tmpbox=0pt
1161 \dp\tmpbox=0pt
1162 \box\tmpbox}
1163
1164 \hrule
1165
1166 % rotation by `t' degrees counterclockwise is specified as
1167 % `cos(t) sin(t) -sin(t) cos(t) 0 0'.
1168 \vskip\wd0
1169 \leftline{\hskip\ht0\hskip\dp0%
1170 \pdfliteral{q 0 1 -1 0 0 0 cm}%
1171 \avoidboxdimen 0
1172 \pdfliteral{Q}}
1173
1174 \hrule
1175
1176 % scaling is specified as `Sx 0 0 Sy 0 0'
1177 \d=\ht1 \advance\d by \dp1
1178 \vskip3\d
1179 \pdfliteral{q 2 0 0 3 0 0 cm}%
1180 \avoidboxdimen 1
1181 \pdfliteral{Q}%
1182
1183 \hrule
1184
1185 % skewing x-axis by `u' degrees and y-axis by `v' degrees is specified as
1186 % `1 tan(u) tan(v) 1 0 0'.
1187 \d=\ht2 \advance\d by \dp2
1188 \vskip\d
1189 \d=0.57735\wd2 %tan(30) = 0.57735
1190 \pdfliteral{q 1 -0.57735 0 1 0 0 cm}%
1191 \avoidboxdimen 2
1192 \pdfliteral{Q}
1193 \vskip\d
1194
1195 % For better understaing \pdfliteral rules, play with the transformations above using
1196 % `direct' and `page' modifiers. Expect surprises, including corrupted output...
1197
1198 % One may already notice that any transformation applied to text or some other
1199 % page graphic object do not affect active rectangles of links and other
1200 % annotations. This is because those rectangles are kept in PDF as a different
1201 % structure then the page content. pdfTeX is not aware of any transformation
1202 % shown above (\pdfliteral content is not analyzed anyhow), so any annotation
1203 % related to the box being transformed remains untouched.
1204
1205 % Check it out:
1206 % \pdfliteral{q 0.87 -0.5 0.5 0.87 0 0 cm}
1207 % \setbox0\hbox{\f\pdfstartlink goto page \pageno{/FitH}Link\pdfendlink}
1208 % \avoidboxdimen0
1209 % \pdfliteral{Q}
1210
1211 % pdfTeX 1.40.0 comes with three extra primitives that fixes this problem.
1212 % \pdfsetmatrix primitive inserts first four numbers of the afine
1213 % transformation matrix into the page content stream and updates annotations
1214 % accordingly. \pdfsave saves the current matrix, \pdfrestore restores the
1215 % previously saved matrix.
1216 \hrule height 0pt depth 0pt width 0pt
1217 \bigskip
1218
1219 \feature 1.40.0 {Saving/restoring transformation matrix}
1220
1221 \setbox0\hbox{\f\pdfstartlink goto page \pageno{/FitH}Link\pdfendlink}
1222 \pdfsave
1223 \pdfsetmatrix{0.87 -0.5 0.5 0.87}
1224 \avoidboxdimen0
1225 \pdfrestore
1226
1227 \endfeature
1228
1229 % To have a smoothly readable PDF output one may use a newline character to
1230 % separate entries written directly do PDF code. No matter for the viewer.
1231
1232 \def\n{^^J}
1233
1234 % If the file is modified are released oftenly (as this one) it might be convenient to
1235 % keep trace of modification time. In pdfTeX 1.30.0 there is a
1236 % \pdfcreationdate that returns a date of the file being created.
1237 % Date is formated in PDF way.
1238
1239 \ifversion 1.30.0 \else
1240
1241 \count100=\time
1242 \divide\count100 by60
1243 \edef\pdfcreationdate{\ifnum\count100<10 0\fi\the\count100} % hours
1244 \multiply\count100 by-60
1245 \advance\count100 by\time
1246 \edef\pdfcreationdate{%
1247 \pdfcreationdate
1248 \ifnum\count100<10 0\fi\the\count100 00} % minutes (seconds zeroed)
1249 \edef\pdfcreationdate{%
1250 D:\the\year
1251 \ifnum\month<10 0\fi\the\month
1252 \ifnum\day<10 0\fi\the\day
1253 \pdfcreationdate} % time zone discarded
1254
1255 \fi
1256
1257 \pdfinfo{% % Info dictionary of PDF output;
1258 % all keys are optional.
1259 /Author (Han The Thanh)
1260 \n/CreationDate (D:20001212000000) % (D:YYYYMMDDhhmmss)
1261 % YYYY year
1262 % MM month
1263 % DD day
1264 % hh hour
1265 % mm minutes
1266 % ss seconds
1267 %
1268 % default: the actual date
1269 %
1270 \n/ModDate (\pdfcreationdate) % ModDate is similar
1271 \n/Creator (TeX) % default: "TeX"
1272 \n/Producer (pdfTeX) % default: "pdfTeX" + pdftex version
1273 \n/Title (samplepdf.pdf) %
1274 \n/Subject (Example) %
1275 \n/Keywords (PDF TeX) %
1276 }
1277
1278 \pdfcatalog{ % Catalog dictionary of PDF output.
1279 /PageMode /UseOutlines %
1280 /URI (http://www.fi.muni.cz/) %
1281 % pdfscreen-like setting might look like:
1282 % /PageMode /none
1283 % /ViewerPreferences <<
1284 % /HideToolbar true
1285 % /HideMenubar true
1286 % /HideWindowUI true
1287 % /FitWindow true
1288 % /CenterWindow true
1289 % >>
1290 }
1291 openaction goto page 1 {/Fit} % the action to be activated when
1292 % opening the document; this is the
1293 % same as <action spec> for links
1294 % and outlines
1295 \end