21#include "pdfdocumentreader.h"
22#include "pdfrenderer.h"
34class PdfDocumentContainer
39 nullptr, []( bool * ) -> QString { return QString(); },
true, false
41 , document( reader.readFromFile( path ) )
42 , modifiedDocument( &document,
nullptr )
43 , fontCache( 1000, 1000 )
45 fontCache.setDocument( modifiedDocument );
47 pdf::PDFRenderer::Features features;
50 features.setFlag( pdf::PDFRenderer::Feature::RealText,
true );
52 renderer = std::make_unique< pdf::PDFRenderer >( &document, &fontCache, &pdfCms,
nullptr, features, meshQualitySettings );
54 pdf::PDFDocumentReader reader;
55 pdf::PDFDocument document;
56 pdf::PDFModifiedDocument modifiedDocument;
57 pdf::PDFFontCache fontCache;
58 pdf::PDFCMSGeneric pdfCms;
59 pdf::PDFMeshQualitySettings meshQualitySettings;
60 std::unique_ptr< pdf::PDFRenderer > renderer;
69 mDocumentContainer = std::make_unique< PdfDocumentContainer >(
path, flags );
78 const pdf::PDFCatalog *catalog = mDocumentContainer->document.getCatalog();
79 return static_cast< int >( catalog->getPageCount() );
91 if ( pageNumber < 0 || pageNumber >=
pageCount() )
94 const pdf::PDFCatalog *catalog = mDocumentContainer->document.getCatalog();
95 return catalog->getPage( pageNumber )->getMediaBox();
107 mDocumentContainer->renderer->render( painter, rectangle, pageIndex );
QFlags< PdfRenderFlag > PdfRenderFlags
PDF rendering flags.
@ RenderTextAsText
Render text items as text objects, not painter paths.
Custom exception class which is raised when an operation is not supported.
QRectF pageMediaBox(int pageNumber) const
Returns the media box for the specified page.
int pageCount() const
Returns the number of pages in the PDF.
bool render(QPainter *painter, const QRectF &painterRect, int pageIndex)
Renders the PDF from the specified path to a painter.
QString path() const
Returns the file path of the associated PDF file.
QgsPdfRenderer(const QString &path, Qgis::PdfRenderFlags flags=Qgis::PdfRenderFlags())
Constructs a PDF renderer for the file at the specified path.