SDB:Landscape Printing
在 openSUSE 上测试
情况
You like to print something in landscape orientation.
本文适用于 Linux 下 CUPS 版本高达 2.x,以及那里的传统过滤系统和后端。
如今的无驱动程序打印工作流程则大不相同。
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
或
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
或
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.
详细信息
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
Adobe DSC 规范(参见 维基百科:文档结构约定)指出
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.
DSC 注释“%% Orientation: Landscape”旨在指定查看方向,但并非旨在“影响最终输出”,因此 DSC 注释“%% Orientation: Landscape”对于打印输出是无关紧要的。
DSC 注释只是 PostScript 语言的注释,因此无法影响输出。
与此相反,对于“适应纸张”或“自动旋转缩放居中”等功能,可以使用 DSC 注释,供专用工具实现这些功能(摘自 Adobe DSC 规范)
%%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.
在 PostScript 默认用户坐标系中,原点 (x=0,y=0) 是页面的左下角,x 轴是水平的(x 增大向右),y 轴是垂直的(y 增大向上),测量单位是 PostScript 单位(1/72 英寸)。因此,PostScript 默认用户坐标系是一个以 1/72 英寸为单位的笛卡尔坐标系。
DSC 边界框注释指定页面内容的尺寸。
PPD 文件(参见 Concepts printing)特别通过每个纸张尺寸的“ImageableArea”条目指定了纸张上打印机特定的可打印区域。
通过 DSC 边界框值加上 ImageableArea 值,可以自动旋转、缩放和居中内容,使其适应纸张的可打印区域,而不管打印纸张的查看方向如何。
需要 DSC 方向和边界框注释,因为无法通过边界框值可靠地确定查看方向。
假设这是一个内容
## ##
### ##
## ## ##
## ###
## ##
该内容在纵向方向看起来像大写字母“N”,在横向方向看起来像大写字母“Z”。
这是另一个内容
########
##
##
##
########
该内容在纵向方向看起来像大写字母“Z”,在横向方向看起来像大写字母“N”。
这两个内容具有相同的边界框值,因此需要单独指定查看方向。
请参阅 Debian wiki “pdftopdfandPageRotation” 文章 https://wiki.debian.org/pdftopdfandPageRotation
参见
相关文章
- Portal:Printing
- PostScript
- SDB:Printing Copies
- SDB:Printing to PDF
- SDB:Print Settings with CUPS
- SDB:How to Report a Printing Issue
- SDB:Using Your Own Filters to Print with CUPS