Differences between revisions 3 and 4
Revision 3 as of 2015-04-20 17:13:51
Size: 8257
Editor: Brian Potkin
Comment:
Revision 4 as of 2015-04-20 17:18:49
Size: 8287
Editor: Brian Potkin
Comment:
Deletions are marked like this. Additions are marked like this.
Line 66: Line 66:
A good way to appreciate what pdftopdf on Jessie does to fit an image on a paper is to use [[The cupsfilter Utility|cupsfilter]]. A PPD file is available for this and later tests. A good way to appreciate what pdftopdf on Jessie does to fit an image on a paper is to use [[The cupsfilter Utility|cupsfilter]]. A PPD file, [[attachment:test.ppd]], is available for this test and later ones.

Translation(s): none


An exploration of how pdftopdf treats rotation of pages in a PDF file.

TIDYING UP COMING SOON

Introduction

The purpose of most of this account is to explore the treatment of what are often called "portrait" and "landscape" pages in a PDF file when they are handled by the filtering subsystem on a Jessie CUPS printing system. On Wheezy the page management by pdftopdf is significantly different and, in the context of page rotation, the two subsystems are not comparable.

The Rôle of pdftopdf

Printers are limited. In general, they cannot directly scale the text in a PDF, directly do N-up printing, directly rotate a page or directly use a specific font such as freefont. It is not that they could not be manufactured to do such things; they just don't (in general).

So we need pdftopdf to apply options such as these to a PDF file it receives. pdftopdf is a page management filter. We will look at how it manages rotation of pages in a PDF file.

Portrait and Landscape Pages in a PDF

A PDF file with mixed orientation pages would be useful to have. mixed.pdf may be downloaded for you to use.

The file has three pages. Information on each page may be displayed with ?pdfinfo:

pdfinfo -f 1 -l 3 mixed.pdf

For the first page:

Page    1 size: 595 x 842 pts (A4)
Page    1 rot:  0

The page width is less than its height; it is a portrait page. "rot: 0" tells a PDF viewer not to rotate the page.

The second page has:

Page    2 size: 841.89 x 595.28 pts (A4)
Page    2 rot:  0

This is a landscape page because its width is greater than its height. There is no rotation done by the viewer.

Lastly:

Page    3 size: 595 x 842 pts (A4)
Page    3 rot:  90

This is another portrait page but the viewer rotates it 90 degrees clockwise.

Printing Portrait and Landscape Pages

Many printers take paper and feed it through the printer short-edge first; so, for example, text is printed parallel to this edge. For suitably sized paper page 1 should produce a satisfactory printout. On the other hand, pages 2 and 3 will probably have some part of the right-hand portion of the image not printed if they are sent as-is to the printer.

There are two solutions to this problem. One is to rotate pages 2 and 3 before printing them. The second is to alter the images of pages 2 and 3 to make them fit the width of the medium they are being printed on.

pdftopdf and Autorotation

A good way to appreciate what pdftopdf on Jessie does to fit an image on a paper is to use ?cupsfilter. A PPD file, test.ppd, is available for this test and later ones.

cupsfilter -p test.ppd -m application/vnd.cups-pdf mixed.pdf > out.pdf

mixed.pdf can be compared with out.pdf and it can be seen that pages 2 and 3 have been autorotated to fit the images on paper which goes through a printer short-edge first. All print jobs sent from an application or via lp/lpr will undergo selective rotation of landscape pages by pdftopdf.

Let's see what pdfinfo reports for out.pdf and compare it with what was given for mixed.pdf:

Page    1 size: 595 x 842 pts (A4)
Page    1 rot:  0
Page    2 size: 841.89 x 595.28 pts (A4)
Page    2 rot:  270
Page    3 size: 595 x 842 pts (A4)
Page    3 rot:  0

Page 1 hasn't been touched; the rotation field still has "0". Page 2 would now be rotated 270 degrees clockwise (90 degrees anticlockwise) when viewed. Page 3 has also been rotated 90 degrees anticlockwise and this cancels out its existing 90 degree clockwise rotation.

The autorotate feature is the only way a PDF with mixed orientation pages will be printed correctly when sent to a printer with lp/lpr or from some applications.

pdftopdf will autorotate appropriate pages by 90 degrees anticlockwise unless the PPD file indicates otherwise.

Autorotation will not take place when the ?PDF workflow is not used.

Edit test.ppd and alter the line with *LandscapeOrientation to read

*LandscapeOrientation Minus90

and repeat the previous cupsfilter command. You should observe that the rotation is now 90 degrees clockwise. Deleting or commenting out the line gives the same result.

Autorotation can be dispensed with by using "-o nopdfAutoRotate" or "-o pdfAutoRotate=off" when setting up a print queue or printing with lp/lpr. There is no way to turn it off from an application. Test with

cupsfilter -p test.ppd -m application/vnd.cups-pdf -o nopdfAutoRotate mixed.pdf  > out.pdf

The landscape and orientation-requested Options

CUPS has a help page on Command-Line Printing and Options. It says there that

The -o landscape option will rotate the page 90 degrees....

The direction of rotation is governed by *LandscapeOrientation in the PPD file. Minus90 rotates all pages in a PDF file degrees clockwise; Plus90 does the same but anticlockwise.

On the same page we see

The -o orientation-requested=N option rotates the page depending on the value of N:

-o orientation-requested=4 - landscape orientation (90 degrees)

However, the orientation-requested=N option always rotates every page in a file in an anticlockwise sense. *LandscapeOrientation is not consulted by it.

pdftopdf acts on the landscape and orientation-requested=N options whether or not autorotation is operative. The following command with *LandscapeOrientation as Plus90 might prove instructive:

cupsfilter -p test.ppd -m application/vnd.cups-pdf -o orientation-requested=4 > out.pdf

Page 1 is first rotated 90 degrees anticlockwise by orientation-requested=4 and then autorotation applies a further 90 degrees anticlockwise rotation. The other two pages are rotated 90 degrees anticlockwise by orientation-requested=4 but then autorotation has nothing to do.

The fit-to-page Option

Suppose you want pages 2 and 3 of mixed.pdf to be printed with the text parallel to the short edge of the paper and also for them to fit on the sheet. Autorotation will have to off for that.

cupsfilter -p test.ppd -m application/vnd.cups-pdf -o 'fit-to-page nopdfAutoRotate' > out.pdf

For fitting all pages on the sheet of paper and having text parallel to its long edge:

cupsfilter -p test.ppd -m application/vnd.cups-pdf -o 'fit-to-page nopdfAutoRotate landscape' > out.pdf

The landscape and portrait Options in Applications

The printing dialogue of a graphical application usully offers landscape and portrait options. The meaning attached to these two words when printing a PDF differs from ?what CUPS means and also has different meanings for different applications. Two illustrations.

  • "Portrait" with Iceweasel and Evince means "Do not rotate any page in this PDF". "Landscape" means "Rotate only pages with width less than height by 90 degrees anticlockwise". These instructions are dealt with by Cairo when it produces a PDF from the one it is given; they are not sent to CUPS.
  • Okular sends PostScript to CUPS. Its portrait option effectively sends "-o portrait"(a CUPS option which doesn't exist) to CUPS. Its landscape option sends "-o landscape" to CUPS.

A pdftopdf Bonus

Very simply - try this:

cupsfilter -p test.ppd -m application/vnd.cups-pdf -o 'fit-to-page booklet' > out.pdf

Available only through the ?PDF workflow