- Qt 6.6
- Qt GUI
- C++ Classes
- QPdfWriter
- Qt 6.6.3 Reference Documentation

# QPdfWriter Class

The QPdfWriter class is a class to generate PDFs that can be used as a paint device. More...

Header: | #include <QPdfWriter>
CMake: | find_package(Qt6 REQUIRED COMPONENTS Gui) target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: | QT += gui
Inherits: | QObject and QPagedPaintDevice

- List of all members, including inherited members
- QPdfWriter is part of Painting Classes.

## Public Functions

| QPdfWriter(const QString &filename)
| QPdfWriter(QIODevice *device)
virtual | ~QPdfWriter()
void | addFileAttachment(const QString &fileName, const QByteArray &data, const QString &mimeType = QString())
QString | creator() const
QByteArray | documentXmpMetadata() const
QPagedPaintDevice::PdfVersion | pdfVersion() const
int | resolution() const
void | setCreator(const QString &creator)
void | setDocumentXmpMetadata(const QByteArray &xmpMetadata)
void | setPdfVersion(QPagedPaintDevice::PdfVersion version)
void | setResolution(int resolution)
void | setTitle(const QString &title)
QString | title() const

## Reimplemented Public Functions

virtual bool | newPage() override

## Reimplemented Protected Functions

virtual QPaintEngine * | paintEngine() const override

## Detailed Description

QPdfWriter generates PDF out of a series of drawing commands using QPainter. The newPage() method can be used to create several pages.

## Member Function Documentation

### `[explicit]` QPdfWriter::QPdfWriter(const QString &filename)

Constructs a PDF writer that will write the pdf to filename.

### `[explicit]` QPdfWriter::QPdfWriter(QIODevice *device)

Constructs a PDF writer that will write the pdf to device.

### `[virtual noexcept]` QPdfWriter::~QPdfWriter()

Destroys the pdf writer.

### void QPdfWriter::addFileAttachment(const QString &fileName, const QByteArray &data, const QString &mimeType = QString())

Adds fileName attachment to the PDF with (optional) mimeType. data contains the raw file data to embed into the PDF file.

### QString QPdfWriter::creator() const

Returns the creator of the document.

See also setCreator().

### QByteArray QPdfWriter::documentXmpMetadata() const

Gets the document metadata, as it was provided with a call to setDocumentXmpMetadata. It will not return the default metadata.

See also setDocumentXmpMetadata().

### `[override virtual]` bool QPdfWriter::newPage()

Reimplements: QPagedPaintDevice::newPage().

### `[override virtual protected]` QPaintEngine *QPdfWriter::paintEngine() const

Reimplements: QPaintDevice::paintEngine() const.

### QPagedPaintDevice::PdfVersion QPdfWriter::pdfVersion() const

Returns the PDF version for this writer. The default is `PdfVersion_1_4`.

See also setPdfVersion().

### int QPdfWriter::resolution() const

Returns the resolution of the PDF in DPI.

See also setResolution().

### void QPdfWriter::setCreator(const QString &creator)

Sets the creator of the document to creator.

See also creator().

### void QPdfWriter::setDocumentXmpMetadata(const QByteArray &xmpMetadata)

Sets the document metadata. This metadata is not influenced by the setTitle / setCreator methods, so is up to the user to keep it consistent. xmpMetadata contains XML formatted metadata to embed into the PDF file.

See also documentXmpMetadata().

### void QPdfWriter::setPdfVersion(QPagedPaintDevice::PdfVersion version)

Sets the PDF version for this writer to version.

If version is the same value as currently set then no change will be made.

See also pdfVersion().

### void QPdfWriter::setResolution(int resolution)

Sets the PDF resolution in DPI.

This setting affects the coordinate system as returned by, for example QPainter::viewport().

See also resolution().

### void QPdfWriter::setTitle(const QString &title)

Sets the title of the document being created to title.

See also title().

### QString QPdfWriter::title() const

Returns the title of the document.

See also setTitle().