Binary builds are also provided via Marketplace: It's available under GPL, LGPL and commercial licenses.įor rendering pages or elements from existing PDF documents to image files or in-memory pixmaps (useful e.g. You can build it using these instructions. It is supported on all platforms that support Qt WebEngine, plus iOS.
Since then, Qt Quick support has been added and now the source code lives in the qtwebengine repository. It was introduced as a Qt Labs module in this blog post. At this point, more of the feature set is complete for Qt Quick applications than for widget-based ones but both are possible. It includes an image plugin so that most image-viewing applications can view PDF files too (however most of those do not have multi-frame image support, so they will only render the first page). The QtPDF module is a wrapper around PDFium which supports rendering, navigating pages, bookmarks, links, document metadata, search, text selection and copying to the clipboard.
The conversion tool could be bundled with your application or specified as a prerequisite, and controlled via QProcess. If all else fails, there is always the option of using an existing tool to automatically convert between PDF files and a more manageable format, and let your Qt application read/write that format instead.
If you need more control over the output when creating PDF documents, or you need to parse existing PDF documents (anything from extracting specific information to assembling a full in-memory document object tree) and maybe even modify their structure or content before writing them back to disk, refer to third-party PDF reading/writing libraries: To export the content of a graphics scene or view (or a part of it) to PDF, you need to manually initialize a QPainter configured to paint on a PDF-creating QPrinter (as described above), and pass it to QGraphicsScene::render() or QGraphicsView::render(). Qt's Graphics View framework can be a more suitable alternative for creating PDF documents with content that is mainly based on arbitrarily positioned and transformed 2D graphical items rather than continuous flowed rich text. You can export the whole document with QTextDocument::print(), or a part of it with QTextEdit::print() (see Exporting a document to PDF for more details). Just pass the QPrinter object as a reference to the constructor of QPainter (or, alternatively, to QPainter::begin() for an already existing QPainter) and then perform any painting operations with that QPainter instance like you usually would (with intermittent calls to QPrinter::newPage() whenever you want to move on to the next PDF page).įor a more high-level API for creating structured rich-text documents, use Qt's Scribe framework (see Handling Document Formats), which is based on a cursor interface that mimics the behavior of a cursor in a text editor. The most basic (but not necessarily simplest) way of creating PDF documents with QPrinter is by manually painting the document's content with Qt's Arthur paint system. tOutputFileName("path/to/file.pdf") Since QPrinter inherits QPaintDevice, anything that supports outputting graphical content to a QPaintDevice (or has convenience API for printing with QPrinter) can thus be used for generating PDFs: To do so you can set up a QPrinter instance like this: QPrinter printer(QPrinter::HighResolution) Please also read the general considerations outlined on the Handling Document Formats page.įor creating PDF documents from scratch, you can use Qt's built-in print support which also allows "printing" to PDF files.
This page discusses various available options for working with Portable Document Format (PDF) documents in your Qt application. 3.5 Embedding a third-party browser plugin.3.4 Embedding a third-party ActiveX control.3.2 Calling an external viewer application.