Changes

Jump to navigation Jump to search
\firstsectionpage and \lastsectionpage
[http://source.contextgarden.net/tex/context/base/page-imp.tex page-imp.tex] defines some handy macros for handling import of existing PDF documents.__TOC__
[http://source.contextgarden.net/tex/context/base/page-imp.mkii page-imp.mkii] and [http://source.contextgarden.net/tex/context/base/page-sel.mkiv page-sel.mkiv] defines some handy macros for handling import of existing PDF documents. = Insert a PDF page as a figure = To include only insert a specific single page from a PDF document into your text as a figure, you can write
<texcode>
\externalfigure[file.pdf][page=1,width=...]
</texcode>
By default, the interactive elements of the included PDF file are discarded. To enable the interactive elements of the included PDF file, use <texcode>\externalfigure[filename.pdf][interaction=yes]</texcode> = Insert PDF page(s) as full-page figures = If you simply want to insert the first "n" number of pages from a PDF as full-page figures, use {{cmd|copypages}}. For example, to insert the first 30 pages scaled down to 95%, you can write<texcode>\copypages[file.pdf][n=30][scale=950]</texcode>Insertion always starts from the first page. Your existing headers, footers, crop marks will be printed on each page. If, in addition, you want to insert blank pages after specified pages use {{cmd|insertpages}}. For example, to insert the first 30 pages of a PDF and add a blank page after the first and the third page, you can write<texcode>\insertpages[file.pdf][1,3][n=30,width=18cm]</texcode> If you do not want to start insertion from page 1 and you want to specify precisely, which pages orpage-ranges to insert, then use {{cmd|filterpages}}. For example, to insert pages 1, 3, 4, 5 and 6, you can write<texcode>\filterpages[file.pdf][1,3,4:6][width=18cm]</texcode>To insert even/odd pages up to page 30.<texcode>\filterpages[file.pdf][even][width=18cm] % even/odd</texcode>(See also Taco's hack in [[Processing Lists]] for handling ranges of numbers or [http://archive.contextgarden.net/thread/20050704.222033.bbadb15a.en.html this] thread in the mailing list.) = Merge a single PDF page into your document = To insert a single page from a PDF document after the current page as a full page without adding any headers, footers, etc., use this:
<texcode>
\startpagefigure[file.pdf][page=1,...]\stoppagefigure
</texcode>
which is equal to
<texcode>
\startTEXpage
\stopTEXpage
</texcode>
Optionally, you can also add some text to the bottom of the PDF page. For more info, see {{cmd|startpagefigure}}. '''Note''' that with the latest CTX standalone beta as of '''2017/05/27''' (mkiv, LuaTeX) the way described seems not to work properly. In the output you might find the first page only, no matter which <code>page</code> argument (<code>page=2...n</code>) you use.The following workaround might provide useful in that case:<texcode> \startpagemakeup \filterpages[file][n] % n in Natural \stoppagemakeup</texcode> = Include a section from other PDF document = It is equal possible toinclude a whole section (part, chapter, section...) from another PDF document generated, using the value of its reference key, such as the one generated from the following source: 
<texcode>
\startpagefiguresetuppagenumbering[file.pdfalternative=doublesided]\starttext \dorecurse{25} {\startchapter[pagetitle=1{Chapter},...reference={c-\recurselevel}] \dorecurse{\recurselevel} {\input knuth} \stopchapter}\stoppagefigurestoptext
</texcode>
This one inserts In the first 30 pages of document you want the document and adds section to be included, use a blank page after loop ({{cmd|dostepwiserecurse}}) from the first value you get from {{cmd|firstsectionpage}} and the third page.from {{cmd|lastsectionpage}}, such as in:
<texcode>
\insertpagesstarttext\dostepwiserecurse {\firstsectionpage[file.pdfx][c-18]} {\lastsectionpage[x][c-18]} {1,3} { \startTEXpage[pagestate=start] \externalfigure[n=30,widthx.pdf][page=18cm\recurselevel] \stopTEXpage }\stoptext
</texcode>
If The source PDF document (the one from which pages are included) needs also its <code>.tuc</code> file used to generate it. Which pages are related to which references are contained in this file. = Page numbering with {{cmd|startpagefigure}} = Experience shows that when you want include a page from a PDF file using {{cmd|startpagefigure}}, the page number of your document is not increased. The included PDF page is completely excluded from the page numbering process. This is annoying if you include a PDF page in the middle of your document, and expect your page numbers to be correct after the PDF page. One solution is to use the commands {{cmd|insertpages}}, {{cmd|filterpages}}, and {{cmd|copypages}}. They correctly increment the page numbers. But those commands include the PDF pages like additional "layers" on your page, so it means that your headers, footers, crop marks, etc. will be printed on top of or behind the included PDF pages. (Headers and footers will be printed behind, crop marks will be printed on top of the included PDF.) Another solution is to insert fix the page number manually after using {{cmd|startpagefigure}}. Let's say we include 3 pages from a couple PDF like this:<texcode>% Several pages of text here\startpagefigure[include_this.pdf][page=4]\stoppagefigure\startpagefigure[include_this.pdf][page=6]\stoppagefigure\startpagefigure[include_this.pdf][page=11]\stoppagefigure% Several pages use of text here</texcode>Notice that {{cmd|startpagefigure}} can include only 1 page at a time. After compiling the above file with ConTeXt, your page numbers will look like this:<texcode>...Page 10Page 11Page 12include_this.pdf page 4include_this.pdf page 6include_this.pdf page 11Page 13Page 14...</texcode>This behavior is also reflected in the command line output of ConTeXt. The value of <code>userpage</code> is the page number which will be printed in your header/footer. Continuing the above example:<texcode>pages > flushing realpage 12, userpage 10pages > flushing realpage 13, userpage 11pages > flushing realpage 14, userpage 12 &lt;include_this.pdf&gt;pages > flushing realpage 15, userpage 13 <-- include_this.pdf page 4pages > flushing realpage 16, userpage 13 <-- include_this.pdf page 6pages > flushing realpage 17, userpage 13 <-- include_this.pdf page 11pages > flushing realpage 18, userpage 13 <-- First ConTeXt page after PDF pagespages > flushing realpage 19, userpage 14</texcode>Therefore, you must "fix" your page number after you finish including PDF pages. You can either set it to a fixed number by saying:
<texcode>
% Several pages of text here\filterpagesstartpagefigure[fileinclude_this.pdf][1,3,page=4:]\stoppagefigure\startpagefigure[include_this.pdf][page=6]\stoppagefigure\startpagefigure[include_this.pdf][widthpage=18cm11]\stoppagefigure\setcounter [userpage] [16]% Several pages of text here
</texcode>
to insert pages 1Or, 3which is even better, 4, 5 and 6 orincrement the page number by the number of included PDF pages:
<texcode>
% Several pages of text here\startpagefigure[include_this.pdf][page=4]\stoppagefigure\filterpagesstartpagefigure[fileinclude_this.pdf][evenpage=6]\stoppagefigure\startpagefigure[include_this.pdf][widthpage=18cm11]\stoppagefigure\setcounter [userpage] [\pagenumber+3] % even/oddSeveral pages of text here
</texcode>
to insert even/odd pages up to the page 30. (See also Taco's hack in [[Processing Lists]] for handling ranges of numbers or [http://archive.contextgarden.net/thread/20050704.222033.bbadb15a.en.html this] thread in the mailing list.)
Yet another alternative isThis way your command line output will be:
<texcode>
\copypages[filepages > flushing realpage 12, userpage 10pages > flushing realpage 13, userpage 11pages > flushing realpage 14, userpage 12 &lt;include_this.pdf][n=30&gt;pages > flushing realpage 15, userpage 13 <-- include_this.pdf page 4pages > flushing realpage 16, userpage 13 <-- include_this.pdf page 6pages > flushing realpage 17, userpage 13 <-- include_this.pdf page 11pages > flushing realpage 18, userpage 16 <-- First ConTeXt page after PDF pagespages > flushing realpage 19,scale=950]userpage 17
</texcode>
to insert the first 30 pages scaled down to 95%.
=This {{cmd|setcounter}} command was tested and worked correctly with<code>ConTeXt ver: 2013.10.01 20:08 MKIV beta</code>. Other commands like <code>\incrementnumber[page]</code> or <code>\page[+1]</code> or <code>\page[16]</code> did not help to solve this problem correctly. = 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:
</texcode>
== Slicing the pages ==
The opposite of combining the pages together is to slice them in pieces.
</texcode>
== Adding comments to pages ==
<texcode>
{{todo|prepare a graphics for each example}}
 
 
= 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.
 
<texcode>
 
% 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
 
</texcode>
 
[[Category:PDF]]
[[Category:Graphics]]
139

edits

Navigation menu