% Example how to use primitives added by pdftex. There are low-level
% primitives; high-level macros for more comfortable use may be supported
% later

\input eplain
\input pdfcolor.tex
\doublecolumns
\vsize=4.4in
%\font\f=ptmr8t\f

\pdfoutput=1\relax      % turn on PDF output; otherwise output DVI file
                        % this primitive can not be specified  *after* shipping
                        % out the *first* page

%\pdfpagesattr={/CropBox [36 36 558 866]}
                        % optional attributes for root Pages object; see PDF
                        % manual for it use. The specified text will be
                        % written out before closing output file 

%\pdfpageattr={/CropBox [36 372 558 866]} 
                        % optional attributes for Page object; see PDF manual
                        % for it use. The specified text will be written out
                        % during shipout. It overwrites any attributes given
                        % by `\pdfpagesattr'

\pdfpagewidth=8.26in    % page width of PDF output

\pdfpageheight=11.69in  % page height of PDF output

\pdfcompresslevel=0     % compression level for text and image;
                        % 0 = no compression (default)
                        % 1 = fastest compression
                        % 9 = best compression
                        % 2..8 = something between
                        % If there is specified a number which is out of this
                        % range then it will be fixed between 0..9

\pdfannot               % general annotation
                        %
    width 10cm          % optional dimension -- similiar to TeX rule
    height 3in          % specification
    depth 10pt          %
{                       %
    /Subtype /Text     % text annotation
    /Open true      
    /Contents 
        (The following text was taken from the  first page of TeX - The
         program, which  is the fine-listing source of TeX)
}      

\pdfdest                % destination for link annotations and outlines
                        %
                        % identifier specification (only one of the following
                        % can/must be specified)
    num 1               % num identifier
    %name {dest}         % name identifier
                        %
                        % appearance of destination (one of the following
                        % can/must be specified)
   %fit                 % fit whole page in window
   %fith                % fit whole width of page 
   %fitv                % fit whole height of page 
   %fitb                % fit whole "Bounding Box" page       
    fitbh               % fit whole width of "Bounding Box" of page 
   %fitbv               % fit whole height of "Bounding Box" of page 

\pdfthreadhoffset=1em   % thread margins
\pdfthreadvoffset=1em   %

\pdfthread              % start of article thread; the corresponding 
                        % `\pdfendthread' must be in the box in the same depth
                        % as the box containing `\pdfthread' all boxes in this
                        % depth level will be treated as part of this thread
                        %
                        % identifier specification (only one of the following
                        % can/must be specified). Threads with same identifier
                        % will be join to the only one.
   num 1               % num identifier
   %name {thread}       % name identifier

The main purpose of the following program is to explain the algorithms of \TeX\ 
as clearly as possible. As a result, the program will not necessarily be very
efficient when a particular PASCAL compiler has translated it into a
particular machine language. However, the program has been written so that it
can be tuned to run efficiently in a wide variety of operating environments by
making comparatively few changes. Such flexibility is possible because the
documentation that follows is written in the WEB language, which is at a
higher level than PASCAL; the preprocessing step that converts WEB to PASCAL
is able to introduce most of the necessary refinements.
Semi-automatic translation to other languages is also feasible, because the
program below does not make extensive use of features that are peculiar to
PASCAL. A large piece of software like TeX has inherent complexity that cannot
be reduced below a certain level of difficulty, although each individual
part is fairly simple by itself. The WEB language is intended to make
the algorithms as readable as possible, by reflecting the way the
individual program pieces fit together and by providing the
cross-references that connect different parts.
                        %
\pdfannotlink           % start of link annotation
                        %
    height 10pt         % optional dimension -- similiar to TeX rule
    depth 3pt           % specification. If not specified then it will be
    depth 3pt           % calculated from the box containing this link
                        %
    attr{/C [0.9 0 0]   % optional attributes of link annotation; specified text
    /Border [0 0 2]}    % is simply included to corresponding object of link
                        % annotation in PDF file. See PDF-1.2 manual for more
                        % details how to specify it
                        %
                        % action specification 
                        %
   goto                 % goto action
                        %
        %file{file.pdf} % optional file specification; can be used only with 
                        % `goto' action or `thread' action (see below). If
                        % action identifier is name then there should be a
                        % destination or a thread with same name identifier
                        % in the file; if action identifier is number then it
                        % means page number for `goto' action (in this case it
                        % will take effect as `fitb' specification) and index
                        % number of thread for `thread' action (the first one
                        % in document has index number 0)
                        %
                        % goto action type (one of the following can/must be
                        % specified)
         num 1          % goto destination with num identifier
        %name{dest}     % goto destination with name identifier
        %page 1 {/Fit}  % goto page 1 and fit the whole page
                        %
                        %
   %thread              % thread action; start to read a thread
                        %
        %file{file.pdf} % optional file specification; see above
                        %
                        % thread action type (one of the following can/must be
                        % specified)
        %num 1          % read thread with num identifier
        %name{thread}   % read thread with name identifier
                        %
                        %
   %user{/Subtype /Link /A << /Type /Action /S /URI /URI (http://www.tug.org/) >>}
                        % user-defined action. See PDF-1.2
                        % manual for more details. In this case it is an URI
                        % action
                        %
                        %
                        % end of `\pdfannotlink' parameters
                        %
                        %
                        %
\setcolor\cmykSeaGreen  % turn on color (this is not a part of `pdfannotlink');
                        % see the file pdfcolor.tex for example how to specify
                        % colors
                        %
Detailed comments about what is going on, and about why things were done in
certain ways, have been liberally sprinkled throughout the program.  These
comments explain features of the implementation, but they rarely attempt to
explain the
                        %
\pdfendlink             % ends link annotation; all text between
                        % `\pdfannotlink' and `\pdfendlink' will be treated as
                        % part of this link annotation
                        %
\setcolor\cmykBlack     % turn off color (this is not a part of `\pdfendlink')
                        %
TeX language itself, since the reader is supposed to be familiar with
The TeX book.\par
\pdfendthread           % end of article thread


                        % The outline specification is a bit more complicated:
                        %
\pdfoutline             % Outline entry specification
                        %
    goto num 1          % action specification. This is the same as the action
                        % specification of `\pdfannotlink'
                        %
    count 3             % number of direct subentries of this entry, 0 if this
                        % entry has no subentries (in this case it may be
                        % omitted). If after `count' follows an negative number
                        % then all subentries will be closed and the absolute
                        % value of this number specifies the number of
                        % direct subentries (see the following entries)
                        %
    {Outline 1}         % text contents of outline entry

    \pdfoutline goto num 1 count -2{Outline 1.1}
        \pdfoutline goto num 1 {Outline 1.1.1}
        \pdfoutline goto num 1 {Outline 1.1.2}
    \pdfoutline goto num 1 {Outline 1.2}
    \pdfoutline goto num 1 {Outline 1.3}
\pdfoutline goto num 1 {Outline 2}

\vfil\eject
\footline={\pdfannotlink user {/Subtype /Link /A << /S /Named /N /GoBack >>}\Cyan Go Back\Black \pdfendlink\hfil \folio}
%\pdfpageattr={}         % reset Page attributes for remaining pages

\hrule
\pdfimage               % insert an PNG image in to output. 
                        %
    height 4cm          % Optipnal dimensions size of the image in output      
    width  8cm          % file. Default values are zero. If all of them are   
    depth  1cm          % non-zero, the image will be scaled to fit the       
                        % specified dimensions. If some of them (but not all) 
                        % are zero, it will be set to a value corresponding to
                        % the remaining ones so as to make the image size to  
                        % yield the same proportion of $width:(height+depth)$ 
                        % as the natural image size, where depth is treated as
                        % zero. If all of them are zero then the image will   
                        % take the natural size of it. An image inserted at   
                        % natural size often has resolution 72~DPI in output  
                        % file. Some images may contain data specifying image 
                        % resolution, and in such a case the image will be    
                        % scaled to the intended resolution. The filename of  
                        % the image must appear after the optional dimension  
                        % parameters. The dimension of the image can be       
                        % accessed by enclosing the \pdfimage command to a box
                        % and checking the dimensions of the box.             
                        %                                              
    {image.png}         % the name of image file; the file should be in
                        % $TEXPSHEADERS paths                          
\bigskip
\pdfimage               % include an image and force its width to 6cm 
    width 4cm           % 
   {image.png}          % 

\bigskip
\pdfimage               % include an image at its natural size; resolution
   {image.png}          % will be 72 dpi


                        % include an image at fixed resolution (in this
                        % example 600 dpi)
                        %
\setbox0=\hbox{         % find out natural size (at 72 dpi)
   \pdfimage            %
     {image.png}}       %
                        %
\dimen0=0.12\wd0        % scale width of image (72/600 = 0.12)
                        %
\bigskip                %
\pdfimage               % include the image with resolution 600 dpi
    width \dimen0       %
   {image.png}          %

\vfil\eject

\setbox0=\vbox{         % make a box
    \hbox{Box 1}
    \hbox{Box 2}
    \hbox{Box 3}
}

\pdfform                % write out a TeX box as a Form object to PDF output
                        %
    0                   % box number

\newcount\n
\n=\pdflastform         % store the number of most recent Form object created by
                        % `\pdfform'

\pdfrefform             % put a reference to a Form object which was created 
                        % by `\pdfform'
    \n                  % reference to the Form object, its object number is
                        % stored in `\n'
\hrule

% Transformations are done by including transformation matrices. See PDF manual
% for more details how to use it. Generally, a transformation matrix is given
% as six real numbers followed by operator `cm'. Before doing any
% transformation we must store current graphic state (by operator `q')
% and restore it (by operator `Q') after transformation.  See examples below.
% Make sure that *no spacing* can be produced during transformation and
% we must adjust spacing ourselves then.

\setbox0=\vbox{
\hbox{Rotated text}
\hbox{Rotated text}
\hbox{Rotated text}
}
\setbox1=\vbox{
\hbox{Scaled text}
\hbox{Scaled text}
\hbox{Scaled text}
}
\setbox2=\vbox{
\hbox{Skewed text}
\hbox{Skewed text}
\hbox{Skewed text}
}
\newdimen\d
\newbox\b
\def\avoidboxdimen#1{%
    \setbox\b=\hbox{\box#1}%
    \wd\b=0pt 
    \ht\b=0pt
    \dp\b=0pt
    \box\b}

% rotation by `t' degrees counterclockwise is specified as 
% `cos(t) sin(t) -sin(t) cos(t) 0 0'.
    \vskip\wd0
    \leftline{\hskip\ht0\hskip\dp0%
    \pdfliteral{q 0 1 -1 0 0 0 cm}%
    \avoidboxdimen0%
    \pdfliteral{Q}}
\hrule

% scaling is specified as `Sx 0 0 Sy 0 0'
    \d=\ht1 \advance\d by \dp1
    \vskip3\d
    \pdfliteral{q 2 0 0 3 0 0 cm}%
    \avoidboxdimen1%
    \pdfliteral{Q}%
\hrule

% skewing x-axis by `u' degrees and y-axis by `v' degrees is specified as 
% `1 tan(u) tan(v) 1 0 0'.
    \d=\ht2 \advance\d by \dp2
    \vskip\d
    \d=0.57735\wd2 %tan(30) = 0.57735
    \pdfliteral{q 1 -0.57735 0 1 0 0 cm}%
    \avoidboxdimen2
    \pdfliteral{Q}
    \vskip\d
\hrule
\leftline{\pdfannotlink
    goto
    page 1 {/Fit} 
    %file {example.pdf}
    Click here to return to the first page\pdfendlink}
\leftline{\pdfannotlink
    goto
    file {tex.pdf}
    page 10 {/Fit} 
    Or read the 10. page of \TeX---The program\pdfendlink}
\vfil\eject

% Uncommenting out the following codes causes that gv fails to display the pdf
% output. A bug of pdftex/gs?
%
% \bigskip
% \leftline{\pdfannotlink thread 
%     %file {example.pdf}
%     num 1
%     %name{thread}
%     \Blue Click here to read the thread \Black\pdfendlink}

\bigskip
\leftline{\pdfannotlink user{
    /Subtype /Link
    /A << 
        /Type /Action 
        /S /URI 
        /URI (http://www.fi.muni.cz/) 
    >>
} \Red Click here to visit our faculty\Black\pdfendlink}

\pdfinfo{               % Info dictionary of PDF output; all keys are
                        % optional. 
    /Author (Han The Thanh)
    /CreationDate (D:19980212201000)    % (D:YYYYMMDDhhmmss)
                                        % YYYY  year
                                        % MM    month
                                        % DD    day
                                        % hh    hour
                                        % mm    minutes
                                        % ss    seconds
                                        %
                                        % default: the actual date
                                        %
    /ModDate (D:19980212201000)         % ModDate is similar
    /Creator (TeX)                      % default: "TeX"
    /Producer (pdfTeX)                  % default: "pdfTeX"
    /Title (example.pdf)                %
    /Subject (Example)                  %
    /Keywords (pdfTeX)                  %
}

\pdfcatalog{            % Catalog dictionary of PDF output. 
    /PageMode /UseOutlines
    /URI (http://www.fi.muni.cz/)
} openaction goto page 3 {/Fit}

\bye
