SDB:Landscape Printing

Jump to: navigation, search


Tested on openSUSE

Recommended articles


This acrticle is currently work in progress...

Situation

You like to print something in landscape orientation.

There is no such thing as "landscape printing"

See Wikipedia: Page orientation:

Page orientation is the way in which a rectangular page is oriented for normal viewing.

The two most common types of orientation are portrait and landscape. The specific word definition comes from the fact that a close-up portrait of a person's face and upper body is more fitting for a canvas or photo where the height of the display area is greater than the width, and is more common for the pages of books. Landscape originally described artistic outdoor scenes where a wide view area is needed...

Portrait or landscape specify the orientation for viewing.

The viewing orientation is irrelevant for printing.

For printing it only matters whether or not the content of the page fits in the printable area of the paper regardless what the orientation for viewing the printed paper is.

"Portrait/Landscape" options

"Landscape" option when printing

A "Landscape" option when printing does not make sense (because there is no such thing as "landscape printing") so that such an option mainly causes confusion:

When printing something where the orientation for viewing the printed paper is "landscape", it depends on the printing output of the particular application program if the printout is correct if a "Landscape" printing option is activated or not.

In contrast printing options like "Fit on Paper" or "Autorotate Scale and Center" provide really useful functionality.

"Landscape" option in application programs

When application programs create content, there can be an option to specify if the content's orientation for viewing is "portrait" (usually the default) or "landscape".

Therefore a "Portrait/Landscape" option in an application program while creating the content makes sense.

For example when a browser program creates content for printing a web page, the user likes to specify whether the content's orientation for viewing the printout is "portrait" or "landscape" - i.e. whether the page layout is "portrait" or "landscape" and accordingly such an option belongs to "Page Layout" and not to "Printing".

Note the subtle distinction

A "Portrait/Landscape" option while creating the content makes sense but for printing that content such an option does no longer make sense in contrast to options like "Fit on Paper" or "Autorotate Scale and Center" that do make sense for printing.

How to fit on paper

Application's printing output should fit on paper

Assume in an application program this is the content for normal viewing:



    #
    #
    ###########


The viewing orientation of that content is "landscape".

Assume this is the application program's PostScript or PDF output page for printing that content:

  ________________
 |                |
 |                |
 |  #             |
 |  #             |
 |  ###########   |
 |                |
 |________________|

For basic information regarding PostScript or PDF output for printing see Concepts printing.

Assume this is the paper and the printable area for a particular printer:

  ___________
 |           |
 | ......... |
 | :       : |
 | :       : |
 | :       : |
 | :       : |
 | :       : |
 | :       : |
 | :       : |
 | ......... |
 |___________|

When the above PostScript or PDF page is "just printed" (i.e. without any "Fit on Paper" or "Autorotate Scale and Center" features) by that particular printer, the content does not fit in the printable area:

  ___________
 |           |
 | ......... |
 | :       : |
 | :       : |
 | :       : |
 | :       : |
 | :#      : |
 | :#      : |
 | :###########
 | ......... |
 |___________|

The result is that the content is truncated on the printed paper:

  ___________
 |           |
 | ......... |
 | :       : |
 | :       : |
 | :       : |
 | :       : |
 | :#      : |
 | :#      : |
 | :#######: |
 | ......... |
 |___________|

Some printer drivers (e.g. the Gutenprint driver and the HPCUPS driver in HPLIP which use the "cups" output device of Ghostscript) or built-in PostScript and PDF interpreters in PostScript/PDF printers may rotate content that does not fit by themselves so that it may even print correctly but it depends on the particular case (see the background information at SDB:How to Report a Printing Issue). In general one cannot rely on it.

To ensure that the content gets printed completely without the need for special "Fit on Paper" or "Autorotate Scale and Center" features, the application should make its PostScript or PDF output page so that the content fits in the printable area of the printer. The printable area for a particular printer is available via the PPD file (see Concepts printing). In this case the application's PostScript or PDF output page for printing would be:

  ___________
 |           |
 |           |
 |           |
 |        #  |
 |        #  |
 |        #  |
 |        #  |
 |        #  |
 |    #####  |
 |           |
 |___________|

The content is rotated 90 degrees anticlockwise.

When a PostScript or PDF page fits in the printable area, it can be "just printed":

  ___________
 |           |
 | ......... |
 | :       : |
 | :      #: |
 | :      #: |
 | :      #: |
 | :      #: |
 | :      #: |
 | :  #####: |
 | ......... |
 |___________|

Because the viewing orientation of that content is "landscape" the user must rotate the printed paper 90 degrees clockwise to view the printout in the right orientation:

  ________________
 |                |
 |                |
 |  #             |
 |  #             |
 |  ###########   |
 |                |
 |________________|

Let the printing system fit it on paper

Assume this is the content in a PostScript or PDF file for normal viewing:



    #
    #
    ###########


The viewing orientation of that content is "landscape".

When the above PostScript or PDF file is "just printed" (i.e. without any "Fit on Paper" or "Autorotate Scale and Center" features), the content does not fit in the printable area of usual paper:

  ___________
 |           |
 | ......... |
 | :       : |
 | :       : |
 | :       : |
 | :       : |
 | :#      : |
 | :#      : |
 | :###########
 | ......... |
 |___________|

To fit the content in the printable area of the paper there is the CUPS command-line printing option "-o fitplot" (up to CUPS version 1.3) and "-o fit-to-page" (since CUPS version 1.4), see http://www.cups.org/documentation.php/doc-1.3/options.html and http://www.cups.org/documentation.php/doc-1.5/options.html so that for example a PDF file can be printed using:

lp -d queue_name -o fitplot file.pdf

or

lp -d queue_name -o fit-to-page file.pdf

If "Fit on Paper" is wanted for all printout via a print queue, the option "fitplot" or "fit-to-page" can be set for the print queue with the following command (as root):

lpadmin -p queue_name -o fitplot-default

or

lpadmin -p queue_name -o fit-to-page-default

This way all content will be autorotated and scaled to fit on paper. In particular small content will be enlarged, for example printing A6 content like

echo "A6 content" | a2ps -1 -M A6 -o- | lp -d queue_name

may result unexpected output.

One can set up two separated print queues for the same printer device for example named "myprinter" for usual printing and "myprinter_fit_on_paper" where the "fitplot" or "fit-to-page" option is set.

The CUPS "Fit on Paper" feature depends upon an accurate size in the print file (regarding size in the print file, see the background information and explanation below). If no size is given in the file, the page may be scaled incorrectly. Therefore it does not work in all cases to leave it to the printing system to fit the content on the paper.

Again there is a subtle distinction

For printing the application should make its PostScript or PDF page so that the content fits in the printable area of the printer.

In contrast for an "Export/Save as PDF" functionality the application should preserve the orientation of the content in its output PDF file so that a PDF viewer could "just show" the PDF file content in the right orientation for viewing.

But for a printing functionality in a PDF viewer, the PDF viewer should make its PostScript or PDF printing output page so that the content fits in the printable area of the printer so that it can be "just printed".

Things get messed up if "viewing" and "printing" is mixed up.

For example when an application has a "Print as PDF" functionality that is misused to "Export/Save as PDF" (see SDB:Printing to PDF) or when an application uses the same "Export/Save as PDF" functionality to also make PDF output for printing.

Debugging issues with "landscape printing"

The crucial part is to find out whether or not the application's PostScript or PDF output that is submitted to CUPS for printing fits in the printable area of the particular printer.

See SDB:How to Report a Printing Issue how to get what the application submits to CUPS.

Example: LibreOffice "landscape printing"

Since some time LibreOffice submits by default PDF to CUPS but the LibreOffice printing settings provide options to switch it back to PostScript printing output.

In LibreOffice Writer create a document with "landscape" page layout like this (i.e. one page full of long lines of text):



    ###########
    ###########
    ###########


The viewing orientation of that content is "landscape".

LibreOffice's PDF output page for printing that content is:

  ________________
 |                |
 |                |
 |  ###########   |
 |  ###########   |
 |  ###########   |
 |                |
 |________________|

LibreOffice's PDF printing page does not fit in the printable area of usual paper:

  ___________
 |           |
 | ......... |
 | :       : |
 | :       : |
 | :###########
 | :###########
 | :###########
 | :       : |
 | :       : |
 | ......... |
 |___________|

When LibreOffice is switched back to PostScript printing output the PostScript output page for printing the above content is:

  ___________
 |           |
 |           |
 |           |
 |   #####   |
 |   #####   |
 |   #####   |
 |   #####   |
 |   #####   |
 |   #####   |
 |           |
 |___________|

The content is rotated 90 degrees anticlockwise.

Because LibreOffice's PostScript printing output fits in the printable area, it can be "just printed":

  ___________
 |           |
 | ......... |
 | :       : |
 | : ##### : |
 | : ##### : |
 | : ##### : |
 | : ##### : |
 | : ##### : |
 | : ##### : |
 | ......... |
 |___________|

The user must rotate the printed paper 90 degrees clockwise to view it in the right orientation.

Details

1.)
In LibreOffice Writer create a document with "landscape" page layout with content as shown above (i.e. one page full of long lines of text).

2.)
Print that document and get what LibreOffice submitted to CUPS (see "Debugging issues with landscape printing" above).

3.)
Assume you got what LibreOffice submitted to CUPS in /tmp/print-job-data.save (as described in SDB:How to Report a Printing Issue).

4.)
To test what file type it is (PDF or PostScript) run the command

file /tmp/print-job-data.save

which should result either "PDF document..." or "PostScript document...".

5.)
To find out if the content in /tmp/print-job-data.save is wider than high ("landscape") or higher than wide ("portrait") run the following command (all on one single command line):

gs -sDEVICE=bbox -dBATCH -dNOPAUSE /tmp/print-job-data.save 2>&1 | grep '%BoundingBox'

This command runs Ghostscript which outputs the actual bounding box values that show the actual size of the content in the form of a DSC bounding box comment:

%%BoundingBox: llx lly urx ury 

The four arguments correspond to the lower left (llx, lly) and upper right corners (urx, ury) of the content measured in 1/72 inch (0.35 mm) units (see the background information and explanation below). For example when the bounding box values are like "%%BoundingBox: 40 50 540 750" the content is higher than wide (content width is 500 = 540 - 40 and height is 700 = 750 - 50). In contrast bounding box values like "%%BoundingBox: 50 40 750 540" show that the content is wider than high (content width is 700 = 750 - 50 and height is 500 = 540 - 40).

6.)
To view the content in /tmp/print-job-data.save in its actual orientation (i.e. without an automated rotation by a viewer program to match the intended viewing orientation) display it with Ghostscript:

gs -r50 -g900x900 /tmp/print-job-data.save

This opens a X11-window that shows the graphical content of a PostScript or PDF page. At the command line where you typed the "gs" command type "quit" or press the [Ctrl/Strg]+[C] keys to exit Ghostscript. The "-r" parameter specifies the resolution so that "-r100" shows the graphical content at double size compared to "-r50". The "-g" parameter specifies the window size in pixels on the screen. The graphical content that is shown by Ghostscript is what your printer should print (see SDB:How to Report a Printing Issue).

Background information and explanation

PostScript

The Adobe DSC Specification (see Wikipedia: Document Structuring Conventions) reads:

PostScript Language Document Structuring Conventions Specification

...

Even though the DSC comments are a layer of communication beyond the PostScript language and do not affect the final output, their use is considered to be good PostScript language programming style.

...

%% Orientation: Portrait | Landscape

This comment indicates the orientation of the pages in the document. It can be used by previewing applications and post-processors to determine how to orient the viewing window. A portrait orientation indicates that the longest edge of the paper is parallel to the vertical (y) axis. A landscape orientation indicates that the longest edge of the paper is parallel to the horizontal (x) axis. If more than one orientation applies to the document, an individual page should specify its orientation by using the %%PageOrientation: comment.

The DSC comment "%% Orientation: Landscape" is meant to specify the orientation for viewing but it is not meant to "affect the final output" so that a DSC comment "%% Orientation: Landscape" is irrelevant for the printing output.

DSC comments are just comments for the PostScript language and therefore cannot affect the output.

In contrast for functions like "Fit on Paper" or "Autorotate Scale and Center" there is a DSC comment that can be used by special tools to implement such functionality (excerpt from the Adobe DSC Specification):

%%BoundingBox: llx lly urx ury

This comment specifies the bounding box that encloses all marks painted on all pages of a document. That is, it must be a "high water mark" in all directions for marks made on any page. The four arguments correspond to the lower left (llx, lly) and upper right corners (urx, ury) of the bounding box in the default user coordinate system (PostScript units). See also the %%PageBoundingBox: comment.

In the PostScript default user coordinate system the origin (x=0,y=0) is the lower left corner of the page, the x axis is horizontal (x increasing to the right), the y axis is vertical (y increasing upwards), and the unit of measure is the PostScript unit (1/72 inch). Therefore the PostScript default user coordinate system is a cartesian coordinate system with coordinates in 1/72 inch units.

The DSC bounding box comments specify the size of the content of the pages.

The PPD file (see Concepts printing) specifies in particular the printer specific printable area on the paper via "ImageableArea" entries for each paper size.

With the DSC bounding box values plus the ImageableArea values it is posible to autorotate, scale, and center the content to make it fit in the printable area of the paper regardless what the orientation for viewing the printed paper is.

Both the DSC orientation and bounding box comments are needed because the viewing orientation cannot be determined from the bounding box values in a reliable way.

Assume this is one content:


    ##    ##
    ###   ##
    ## ## ##
    ##   ###
    ##    ##

This content looks like a capital letter 'N' in portrait orientation and like a capital letter 'Z' in landscape orientation.

And that is another content:


    ########
         ##
       ##
     ##
    ########

This content looks like a capital letter 'Z' in portrait orientation and like a capital letter 'N' in landscape orientation.

Both contents have same bounding box values so that the viewing orientation needs to be specified separately.

PDF

Remains to be done...

See also

Related articles

External links