Class: QgsPdfRenderer

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.

class qgis.core.QgsPdfRenderer[source]

Bases: object

__init__(path: str | None)

Constructs a PDF renderer for the file at the specified path.

Parameters:

path (Optional[str])

pageCount(self) int[source]

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[source]

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[source]

Returns the file path of the associated PDF file.

Return type:

str

render(self, painter: QPainter | None, painterRect: QRectF, pageIndex: int) bool[source]

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 (Optional[QPainter])

  • painterRect (QRectF)

  • pageIndex (int)

Return type:

bool