1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include <qpdfwriter.h>
43 #include <QtCore/private/qobject_p.h>
44 #include "private/qpdf_p.h"
45 #include <QtCore/qfile.h>
49 class QPdfWriterPrivate : public QObjectPrivate
55 engine = new QPdfEngine();
71 \brief The QPdfWriter class is a class to generate PDFs
72 that can be used as a paint device.
76 QPdfWriter generates PDF out of a series of drawing commands using QPainter.
77 The newPage() method can be used to create several pages.
81 Constructs a PDF writer that will write the pdf to \a filename.
83 QPdfWriter::QPdfWriter(const QString &filename)
84 : QObject(*new QPdfWriterPrivate)
88 d->engine->setOutputFilename(filename);
92 Constructs a PDF writer that will write the pdf to \a device.
94 QPdfWriter::QPdfWriter(QIODevice *device)
95 : QObject(*new QPdfWriterPrivate)
99 d->engine->d_func()->outDevice = device;
103 Destroys the pdf writer.
105 QPdfWriter::~QPdfWriter()
111 Returns the title of the document.
113 QString QPdfWriter::title() const
115 Q_D(const QPdfWriter);
116 return d->engine->d_func()->title;
120 Sets the title of the document being created.
122 void QPdfWriter::setTitle(const QString &title)
125 d->engine->d_func()->title = title;
129 Returns the creator of the document.
131 QString QPdfWriter::creator() const
133 Q_D(const QPdfWriter);
134 return d->engine->d_func()->creator;
138 Sets the creator of the document.
140 void QPdfWriter::setCreator(const QString &creator)
143 d->engine->d_func()->creator = creator;
150 QPaintEngine *QPdfWriter::paintEngine() const
152 Q_D(const QPdfWriter);
160 void QPdfWriter::setPageSize(PageSize size)
162 Q_D(const QPdfWriter);
164 QPagedPaintDevice::setPageSize(size);
165 d->engine->d_func()->paperSize = pageSizeMM() * 25.4/72.;
171 void QPdfWriter::setPageSizeMM(const QSizeF &size)
173 Q_D(const QPdfWriter);
175 QPagedPaintDevice::setPageSizeMM(size);
176 d->engine->d_func()->paperSize = pageSizeMM() * 25.4/72.;
182 Returns the metric for the given \a id.
184 int QPdfWriter::metric(PaintDeviceMetric id) const
186 Q_D(const QPdfWriter);
187 return d->engine->metric(id);
193 bool QPdfWriter::newPage()
197 return d->engine->newPage();
204 void QPdfWriter::setMargins(const Margins &m)
208 const qreal multiplier = 72./25.4;
209 d->engine->d_func()->leftMargin = m.left*multiplier;
210 d->engine->d_func()->rightMargin = m.right*multiplier;
211 d->engine->d_func()->topMargin = m.top*multiplier;
212 d->engine->d_func()->bottomMargin = m.bottom*multiplier;