20#include "pdfdocumentreader.h"
21#include "pdfrenderer.h"
33class PdfDocumentContainer
36 PdfDocumentContainer(
const QString &path )
37 : reader( nullptr, []( bool * )->QString {return QString(); },
true, false )
38 , document( reader.readFromFile( path ) )
39 , modifiedDocument( &document,
nullptr )
40 , fontCache( 1000, 1000 )
42 fontCache.setDocument( modifiedDocument );
43 renderer = std::make_unique< pdf::PDFRenderer >( &document,
47 pdf::PDFRenderer::Features(),
48 meshQualitySettings );
50 pdf::PDFDocumentReader reader;
51 pdf::PDFDocument document;
52 pdf::PDFModifiedDocument modifiedDocument;
53 pdf::PDFFontCache fontCache;
54 pdf::PDFCMSGeneric pdfCms;
55 pdf::PDFMeshQualitySettings meshQualitySettings;
56 std::unique_ptr< pdf::PDFRenderer > renderer;
64 mDocumentContainer = std::make_unique< PdfDocumentContainer >(
path );
73 const pdf::PDFCatalog *catalog = mDocumentContainer->document.getCatalog();
74 return catalog->getPageCount();
86 if ( pageNumber < 0 || pageNumber >=
pageCount() )
89 const pdf::PDFCatalog *catalog = mDocumentContainer->document.getCatalog();
90 return catalog->getPage( pageNumber )->getMediaBox();
102 mDocumentContainer->renderer->render( painter, rectangle, pageIndex );
Custom exception class which is raised when an operation is not supported.
QgsPdfRenderer(const QString &path)
Constructs a PDF renderer for the file at the specified path.
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.