Including pages from PDF documents

From Wiki
Revision as of 19:57, 23 February 2009 by John Devereux (talk | contribs) (Added example based on suggestion by Wolfgang on the mailing list)
Jump to navigation Jump to search

page-imp.tex defines some handy macros for handling import of existing PDF documents.

To include only a specific page from a PDF document you can write

\externalfigure[file.pdf][page=1,width=...]

or

\startTEXpage
    \externalfigure[file.pdf][page=1,width=...]
\stopTEXpage

which is equal to

\startpagefigure[file.pdf][page=1,...]\stoppagefigure

This one inserts the first 30 pages of the document and adds a blank page after the first and the third page.

\insertpages[file.pdf][1,3][n=30,width=18cm]

If you want to insert a couple of pages use this:

\filterpages[file.pdf][1,3,4:6][width=18cm]

to insert pages 1, 3, 4, 5 and 6 or

\filterpages[file.pdf][even][width=18cm] % even/odd

to insert even/odd pages up to the page 30. (See also Taco's hack in Processing Lists for handling ranges of numbers or this thread in the mailing list.)

Yet another alternative is

\copypages[file.pdf][n=30,scale=950]

to insert the first 30 pages scaled down to 95%.

Printing Slides from a presentation

If you want to make a 2*3 matrix from all the slides in the document you can use the following example:

\setuppapersize
  [A4][A4] % or [A4,landscape][A4,landscape]

\setuplayout
  [header=0pt,footer=1cm,
   backspace=1cm,topspace=1cm,
   width=middle,height=middle]

\setupfootertexts
  [presentation---\currentdate\space---\space\pagenumber]

\starttext
  \combinepages[slides][nx=2,ny=3,frame=on]
\stoptext

Slicing the pages

The opposite of combining the pages together is to slice them in pieces.

This will make 3*3 pages out of your document (well, it depends on proportions).

\starttext
    \slicepages[slice1.pdf][n=3]
\stoptext

Adding comments to pages

\setuppagecomment[state=start,location=right]

\startpagecomment
\input knuth
\stoppagecomment

TODO: prepare a graphics for each example (See: To-Do List)

Reformatting a Single-Sided pdf for Double-Sided Printing

Context can be used as a pdf postprocessor.

This example takes an original single-sided document and applies differing horizontal offsets to odd and even pages. This simultaneously

  • compensates for the fixed offset in the original, and
  • introduces a new alternating one as required for double-sided printing

It is useful for printing reference manuals downloaded from the web.


% replace "Manual" with the name of your original pdf
\define\MySingleSidedDocument{Manual}

% can adjust topspace to move page etc
\setuplayout[\MySingleSidedDocument,topspace=1cm,header=0cm,backspace=0cm]
% suppress page numbering
\setuppagenumbering[location=]

\starttext

\getfiguredimensions[\MySingleSidedDocument]

\dorecurse\noffigurepages
  {\hbox to \textwidth
     {\ifodd\recurselevel
%adjust number to set odd page horizontal position
        \hskip-0.1cm\externalfigure[\MySingleSidedDocument][page=\recurselevel]\hss
      \else
%adjust number to set even page horizontal position
        \hskip-1.8cm\externalfigure[\MySingleSidedDocument][page=\recurselevel]\hss
      \fi}}
\stoptext