Class: QgsPdfRenderer

class qgis.core.QgsPdfRenderer

Bases: sip.wrapper

Utility class for rendering PDF documents.

This functionality is not available on all platforms – it requires a build with the PDF4Qt library support enabled. On other platforms calling these methods will raise a QgsNotSupportedException.

Added in version 3.36.

QgsPdfRenderer(path: str) Constructs a PDF renderer for the file at the specified path.

Methods

pageCount

Returns the number of pages in the PDF.

pageMediaBox

Returns the media box for the specified page.

path

Returns the file path of the associated PDF file.

render

Renders the PDF from the specified path to a painter.

pageCount(self) int

Returns the number of pages in the PDF.

Raises:

QgsNotSupportedException – on QGIS builds without PDF4Qt library support.

Return type:

int

pageMediaBox(self, pageNumber: int) QRectF

Returns the media box for the specified page. Units are in PDF points.

Raises:

QgsNotSupportedException – on QGIS builds without PDF4Qt library support.

Parameters:

pageNumber (int)

Return type:

QRectF

path(self) str

Returns the file path of the associated PDF file.

Return type:

str

render(self, painter: QPainter, painterRect: QRectF, pageIndex: int) bool

Renders the PDF from the specified path to a painter.

The painterRect argument specifies the target rectangle for the PDF page in painter coordinates.

Raises:

QgsNotSupportedException – on QGIS builds without PDF4Qt library support.

Parameters:
  • painter (QPainter)

  • painterRect (QRectF)

  • pageIndex (int)

Return type:

bool