|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the documentation of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 /*! |
|
43 \group printing |
|
44 \title Printer and Printing APIs |
|
45 \brief Classes for producing printed output |
|
46 \ingroup groups |
|
47 */ |
|
48 |
|
49 /*! |
|
50 \page printing.html |
|
51 \title Printing with Qt |
|
52 |
|
53 \previouspage Styling |
|
54 \contentspage The Paint System |
|
55 |
|
56 \brief A guide to producing printed output with Qt's paint system and widgets. |
|
57 |
|
58 Qt provides extensive cross-platform support for printing. Using the printing |
|
59 systems on each platform, Qt applications can print to attached printers and |
|
60 across networks to remote printers. Qt's printing system also enables PostScript |
|
61 and PDF files to be generated, providing the foundation for basic report |
|
62 generation facilities. |
|
63 |
|
64 \tableofcontents |
|
65 |
|
66 \section1 Classes Supporting Printing |
|
67 |
|
68 The following classes support the selecting and setting up of printers and |
|
69 printing output. |
|
70 |
|
71 \annotatedlist printing |
|
72 |
|
73 \section1 Paint Devices and Printing |
|
74 |
|
75 In Qt, printers are represented by QPrinter, a paint device that provides |
|
76 functionality specific to printing, such as support for multiple pages and |
|
77 double-sided output. As a result, printing involves using a QPainter to paint |
|
78 onto a series of pages in the same way that you would paint onto a custom |
|
79 widget or image. |
|
80 |
|
81 \section2 Creating a QPrinter |
|
82 |
|
83 Although QPrinter objects can be constructed and set up without requiring user |
|
84 input, printing is often performed as a result of a request by the user; |
|
85 for example, when the user selects the \gui{File|Print...} menu item in a GUI |
|
86 application. In such cases, a newly-constructed QPrinter object is supplied to |
|
87 a QPrintDialog, allowing the user to specify the printer to use, paper size, and |
|
88 other printing properties. |
|
89 |
|
90 \snippet examples/richtext/orderform/mainwindow.cpp 18 |
|
91 |
|
92 It is also possible to set certain default properties by modifying the QPrinter |
|
93 before it is supplied to the print dialog. For example, applications that |
|
94 generate batches of reports for printing may set up the QPrinter to |
|
95 \l{QPrinter::setOutputFileName()}{write to a local file} by default rather than |
|
96 to a printer. |
|
97 |
|
98 \section2 Painting onto a Page |
|
99 |
|
100 Once a QPrinter object has been constructed and set up, a QPainter can be used |
|
101 to perform painting operations on it. We can construct and set up a painter in |
|
102 the following way: |
|
103 |
|
104 \snippet doc/src/snippets/printing-qprinter/object.cpp 0 |
|
105 |
|
106 Since the QPrinter starts with a blank page, we only need to call the |
|
107 \l{QPrinter::}{newPage()} function after drawing each page, except for the |
|
108 last page. |
|
109 |
|
110 The document is sent to the printer, or written to a local file, when we call |
|
111 \l{QPainter::}{end()}. |
|
112 |
|
113 \section2 Coordinate Systems |
|
114 |
|
115 QPrinter provides functions that can be used to obtain information about the |
|
116 dimensions of the paper (the paper rectangle) and the dimensions of the |
|
117 printable area (the page rectangle). These are given in logical device |
|
118 coordinates that may differ from the physical coordinates used by the device |
|
119 itself, indicating that the printer is able to render text and graphics at a |
|
120 (typically higher) resolution than the user's display. |
|
121 |
|
122 Although we do not need to handle the conversion between logical and physical |
|
123 coordinates ourselves, we still need to apply transformations to painting |
|
124 operations because the pixel measurements used to draw on screen are often |
|
125 too small for the higher resolutions of typical printers. |
|
126 |
|
127 \table |
|
128 \row \o \bold{Printer and Painter Coordinate Systems} |
|
129 |
|
130 The \l{QPrinter::}{paperRect()} and \l{QPrinter::}{pageRect()} functions |
|
131 provide information about the size of the paper used for printing and the |
|
132 area on it that can be painted on. |
|
133 |
|
134 The rectangle returned by \l{QPrinter::}{pageRect()} usually lies inside |
|
135 the rectangle returned by \l{QPrinter::}{paperRect()}. You do not need to |
|
136 take the positions and sizes of these area into account when using a QPainter |
|
137 with a QPrinter as the underlying paint device; the origin of the painter's |
|
138 coordinate system will coincide with the top-left corner of the page |
|
139 rectangle, and painting operations will be clipped to the bounds of the |
|
140 drawable part of the page. |
|
141 |
|
142 \o \inlineimage printer-rects.png |
|
143 \endtable |
|
144 |
|
145 The paint system automatically uses the correct device metrics when painting |
|
146 text but, if you need to position text using information obtained from |
|
147 font metrics, you need to ensure that the print device is specified when |
|
148 you construct QFontMetrics and QFontMetricsF objects, or ensure that each QFont |
|
149 used is constructed using the form of the constructor that accepts a |
|
150 QPaintDevice argument. |
|
151 |
|
152 \section1 Printing from Complex Widgets |
|
153 |
|
154 Certain widgets, such as QTextEdit and QGraphicsView, display rich content |
|
155 that is typically managed by instances of other classes, such as QTextDocument |
|
156 and QGraphicsScene. As a result, it is these content handling classes that |
|
157 usually provide printing functionality, either via a function that can be used |
|
158 to perform the complete task, or via a function that accepts an existing |
|
159 QPainter object. Some widgets provide convenience functions to expose underlying |
|
160 printing features, avoiding the need to obtain the content handler just to call |
|
161 a single function. |
|
162 |
|
163 The following table shows which class and function are responsible for |
|
164 printing from a selection of different widgets. For widgets that do not expose |
|
165 printing functionality directly, the content handling classes containing this |
|
166 functionality can be obtained via a function in the corresponding widget's API. |
|
167 |
|
168 \table |
|
169 \header \o Widget \o Printing function \o Accepts |
|
170 \row \o QGraphicsView \o QGraphicsView::render() \o QPainter |
|
171 \row \o QSvgWidget \o QSvgRenderer::render() \o QPainter |
|
172 \row \o QTextEdit \o QTextDocument::print() \o QPrinter |
|
173 \row \o QTextLayout \o QTextLayout::draw() \o QPainter |
|
174 \row \o QTextLine \o QTextLine::draw() \o QPainter |
|
175 \endtable |
|
176 |
|
177 QTextEdit requires a QPrinter rather than a QPainter because it uses information |
|
178 about the configured page dimensions in order to insert page breaks at the most |
|
179 appropriate places in printed documents. |
|
180 */ |
|
181 |
|
182 /*! |
|
183 \page pdf-licensing.html |
|
184 \title Notes about PDF Licensing |
|
185 \ingroup licensing |
|
186 \brief Details of restrictions on the use of PDF-related trademarks. |
|
187 |
|
188 Please note that Adobe\reg places restrictions on the use of its trademarks |
|
189 (including logos) in conjunction with PDF; e.g. "Adobe PDF". Please refer |
|
190 to \l{http://www.adobe.com}{www.adobe.com} for guidelines. |
|
191 */ |