1

I am attempting to use copypages to insert multi-page PDFs into my ConTeXt document. I would like to scale the inserted pages so that they appear smaller but place them flush with the top of each page of my new document. How can I do so?

The default behavior appears to center the scaled pages in the center of each page of the new document.

Here's a MWE of the default behavior (assuming you supply a PDF document of your own to insert).

\starttext
\copypages[a.pdf][][height=\textheight]
\stoptext

UPDATE (2020-02-06):

Using layers, I've successfully place one inserted page at the correct location, but it cannot handle multi-page PDFs or multiple PDFs. Here's the MWE I'm working from:

\setupbackgrounds
  [page]
  [setups=layer,background={foreground,insert}]

\definelayer[insert][height=10in]

\starttext
\showframe
~
\getfiguredimensions[02.pdf]\dorecurse\noffigurepages{\setuptexttexts
  [{\setlayerframed
      [insert]
      []
      []
      {\externalfigure[02.pdf][page=\recurselevel]}}]}

\stoptext

For context, I am attempting to "Bates stamp" a series of PDFs. I would like to place a page number at the bottom of each page, and to shrink each inserted PDF page such that the newly placed page number does not overlap the inserted PDF pages. I do NOT need a header line on the included pages. copypages provides the right functionality to insert the PDFs, but it places the inserted PDF pages in the center of the page, not flush to the top of the paper.


UPDATE (2020-03-03):

For future reference, here is a working version of what I'm looking for. Note that this code also includes commands for typesetting a specially formatted page number.

Thank you to Wolfgang Schuster for your guidance!

\setupexternalfigures[location=default]
\setuppapersize[letter]
\setuplayout[width=6.5in,height=10in,topspace=0.5in,backspace=1in,
  header=0.5in,footer=0.5in]
\setupheadertexts 

\setupbackgrounds
  [page]
  [background={foreground,tmp,numbering}]
\definelayer
  [numbering]
  [height=\paperheight,
   width=\paperwidth]
\setuptexttexts
  [{\setlayerframed
      [numbering]
      [preset=middlebottom,
       voffset=0.25in]
      [frame=off]
      {RA/\pagenumber}}]

\definelayout
  [topaligned]
  [header=0pt]

\showframe

\starttext

\startlayout[topaligned]
\copypages[M-654.pdf][][height=10.5in]
\copypages[M-654.pdf][][height=10.5in]
\stoplayout

\stoptext

First Page of Output: enter image description here

6
  • 2
    \copypages is just a thin wrapper around \externalfigure. You can do the same with just \getfiguredimensions[a.pdf]\dorecurse\noffigurepages{\externalfigure[a.pdf][page=\recurselevel]}. Jan 27, 2020 at 7:00
  • @HenriMenke: Thanks. That helps me tremendously, although I am still searching for the exact look for what I want. In particular, I'm trying to get the included PDF flush with the very top of the page (in the top margin). I've been playing with \externalfigure and \placefigure, but I haven't figured out how best to slide the included PDF to the top of the page.
    – J. King
    Jan 27, 2020 at 15:16
  • For this I'd just put it in a layer, which you can position manually. wiki.contextgarden.net/Layers Jan 28, 2020 at 21:28
  • Do you need a header line on the included pages or should the space be empty. Jan 29, 2020 at 20:47
  • @WolfgangSchuster: I do not need a header line on the included pages. I've updated my original query to clarify.
    – J. King
    Feb 6, 2020 at 20:17

1 Answer 1

3

There are two method available to push the included images or pages to the top of the page. As can be seen in the following example we have to go over the gap which is created by the top space on the page and the height of the header line.

\setupexternalfigures[location=default]

\setuppapersize[A7]

\showframe

\starttext

\externalfigure[mill][width=\textwidth]

\stoptext

enter image description here

When you rely on \externalfigure to include the page one by one you can use the \offset comman to shift each image upwards with the values stored in the \topspace and \headerheight registers.

The downside of this method is that you have to use \getfiguredimensions to get number of pages and use \dorecurse to create a loop to include each page.

\setupexternalfigures[location=default]

\setuppapersize[A7]

\definemeasure [topskip] [\dimexpr\headerheight+\topspace\relax]

\showframe

\starttext

\offset[y=-\measure{topskip}]{\externalfigure[mill][width=\textwidth]}

\stoptext

enter image description here

The second method you can use and which also works \copypages uses a modified layout for the figure pages. The changes of these pages is that we set the height of the topspace and the header to 0pt which gets rid of the unwanted space and the images are now aligned with the top margin of the paper.

\setupexternalfigures[location=default]

\setuppapersize[A7]

\definelayout
  [topaligned]
  [topspace=0pt,
   header=0pt]

\showframe

\starttext

\startlayout[topaligned]
\externalfigure[mill][width=\textwidth]
\stoplayout

\stoptext

enter image description here

1
  • 1
    Thanks for the wonderful solution. I'm using the latter of the two. I'm only using the header=0pt option. I omit the topspace option, which when set to zero shifts the included image from copypages too high. I am updating my original question with a working example of what I'm looking for.
    – J. King
    Mar 3, 2020 at 21:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .