Class: QgsLayoutExporter¶
-
class
qgis.core.
QgsLayoutExporter
(layout: QgsLayout)¶ Bases:
sip.wrapper
Constructor for QgsLayoutExporter, for the specified
layout
.QgsLayoutExporter(QgsLayoutExporter)
Handles rendering and exports of layouts to various formats.
New in version 3.0: Enums
Methods
Compute world file parameters.
Returns the file name corresponding to the last error encountered during an export.
Exports the layout to the
filePath
, using the specified exportsettings
.Exports the layout as a PDF to the
filePath
, using the specified exportsettings
.Exports a layout
iterator
to multiple PDF files, with the specified exportsettings
.Exports the layout as an SVG to the
filePath
, using the specified exportsettings
.Generates the file name for a page during export.
Georeferences a
file
(image of PDF) exported from the layout.Returns the layout linked to this exporter.
Prints the layout to a
printer
, using the specified exportsettings
.Renders a full page to a destination
painter
.Renders a full page to an image.
Renders a
region
from the layout to apainter
.Renders a
region
of the layout to an image.Signals
Attributes
-
Canceled
= 1¶
-
class
ExportResult
¶ Bases:
int
-
FileError
= 3¶
-
class
ImageExportSettings
¶ Bases:
sip.wrapper
Constructor for ImageExportSettings
QgsLayoutExporter.ImageExportSettings(QgsLayoutExporter.ImageExportSettings)
-
cropMargins
¶
-
cropToContents
¶
-
dpi
¶
-
exportMetadata
¶
-
flags
¶
-
generateWorldFile
¶
-
imageSize
¶
-
pages
¶
-
-
IteratorError
= 6¶
-
MemoryError
= 2¶
-
class
PageExportDetails
¶ Bases:
sip.wrapper
QgsLayoutExporter.PageExportDetails(QgsLayoutExporter.PageExportDetails)
-
baseName
¶
-
directory
¶
-
extension
¶
-
page
¶
-
-
class
PdfExportSettings
¶ Bases:
sip.wrapper
Constructor for PdfExportSettings
QgsLayoutExporter.PdfExportSettings(QgsLayoutExporter.PdfExportSettings)
-
dpi
¶
-
exportMetadata
¶
-
flags
¶
-
forceVectorOutput
¶
-
rasterizeWholeImage
¶
-
textRenderFormat
¶
-
-
PrintError
= 4¶
-
class
PrintExportSettings
¶ Bases:
sip.wrapper
Constructor for PrintExportSettings
QgsLayoutExporter.PrintExportSettings(QgsLayoutExporter.PrintExportSettings)
-
dpi
¶
-
flags
¶
-
rasterizeWholeImage
¶
-
-
Success
= 0¶
-
class
SvgExportSettings
¶ Bases:
sip.wrapper
Constructor for SvgExportSettings
QgsLayoutExporter.SvgExportSettings(QgsLayoutExporter.SvgExportSettings)
-
cropMargins
¶
-
cropToContents
¶
-
dpi
¶
-
exportAsLayers
¶
-
exportMetadata
¶
-
flags
¶
-
forceVectorOutput
¶
-
textRenderFormat
¶
-
-
SvgLayerError
= 5¶
-
computeWorldFileParameters
(self, dpi: float = -1) → Tuple[float, float, float, float, float, float]¶ Compute world file parameters. Assumes the whole page containing the reference map item will be exported.
The
dpi
argument can be set to the actual DPI of exported file, or left as -1 to use the layout’s default DPI.computeWorldFileParameters(self, region: QRectF, dpi: float = -1) -> Tuple[float, float, float, float, float, float] Computes the world file parameters for a specified
region
of the layout.The
dpi
argument can be set to the actual DPI of exported file, or left as -1 to use the layout’s default DPI.
-
errorFile
(self) → str¶ Returns the file name corresponding to the last error encountered during an export.
-
exportToImage
(self, filePath: str, settings: QgsLayoutExporter.ImageExportSettings) → QgsLayoutExporter.ExportResult¶ Exports the layout to the
filePath
, using the specified exportsettings
.If the layout is a multi-page layout, then filenames for each page will automatically be generated by appending “_1”, “_2”, etc to the image file’s base name.
Returns a result code indicating whether the export was successful or an error was encountered. If an error code is returned, errorFile() can be called to determine the filename for the export which encountered the error.
exportToImage(iterator: QgsAbstractLayoutIterator, baseFilePath: str, extension: str, settings: QgsLayoutExporter.ImageExportSettings, feedback: QgsFeedback = None) -> Tuple[QgsLayoutExporter.ExportResult, str] Exports a layout
iterator
to raster images, with the specified exportsettings
.The
baseFilePath
argument gives a base file path, which is modified by the iterator to obtain file paths for each iterator feature.Returns a result code indicating whether the export was successful or an error was encountered. If an error was obtained then
error
will be set to the error description.
-
exportToPdf
(self, filePath: str, settings: QgsLayoutExporter.PdfExportSettings) → QgsLayoutExporter.ExportResult¶ Exports the layout as a PDF to the
filePath
, using the specified exportsettings
.Returns a result code indicating whether the export was successful or an error was encountered.
exportToPdf(iterator: QgsAbstractLayoutIterator, fileName: str, settings: QgsLayoutExporter.PdfExportSettings, feedback: QgsFeedback = None) -> Tuple[QgsLayoutExporter.ExportResult, str] Exports a layout
iterator
to a single PDF file, with the specified exportsettings
.The
fileName
argument gives the destination file name for the output PDF.Returns a result code indicating whether the export was successful or an error was encountered. If an error was obtained then
error
will be set to the error description.See also
-
exportToPdfs
(iterator: QgsAbstractLayoutIterator, baseFilePath: str, settings: QgsLayoutExporter.PdfExportSettings, feedback: QgsFeedback = None) → Tuple[QgsLayoutExporter.ExportResult, str]¶ Exports a layout
iterator
to multiple PDF files, with the specified exportsettings
.The
baseFilePath
argument gives a base file path, which is modified by the iterator to obtain file paths for each iterator feature.Returns a result code indicating whether the export was successful or an error was encountered. If an error was obtained then
error
will be set to the error description.See also
-
exportToSvg
(self, filePath: str, settings: QgsLayoutExporter.SvgExportSettings) → QgsLayoutExporter.ExportResult¶ Exports the layout as an SVG to the
filePath
, using the specified exportsettings
.Returns a result code indicating whether the export was successful or an error was encountered.
exportToSvg(iterator: QgsAbstractLayoutIterator, baseFilePath: str, settings: QgsLayoutExporter.SvgExportSettings, feedback: QgsFeedback = None) -> Tuple[QgsLayoutExporter.ExportResult, str] Exports a layout
iterator
to SVG files, with the specified exportsettings
.The
baseFilePath
argument gives a base file path, which is modified by the iterator to obtain file paths for each iterator feature.Returns a result code indicating whether the export was successful or an error was encountered. If an error was obtained then
error
will be set to the error description.
-
generateFileName
(self, details: QgsLayoutExporter.PageExportDetails) → str¶ Generates the file name for a page during export.
Subclasses can override this method to customize page file naming.
-
georeferenceOutput
(self, file: str, referenceMap: QgsLayoutItemMap = None, exportRegion: QRectF = QRectF(), dpi: float = -1) → bool¶ Georeferences a
file
(image of PDF) exported from the layout.The
referenceMap
argument specifies a map item to use for georeferencing. If left as None, the default layout QgsLayout.referenceMap() will be used.The
exportRegion
argument can be set to a valid rectangle to indicate that only part of the layout was exported.Similarly, the
dpi
can be set to the actual DPI of exported file, or left as -1 to use the layout’s default DPI.The function will return true if the output was successfully georeferenced.
See also
-
layout
(self) → QgsLayout¶ Returns the layout linked to this exporter.
-
print
(self, printer: QPrinter, settings: QgsLayoutExporter.PrintExportSettings) → QgsLayoutExporter.ExportResult¶ Prints the layout to a
printer
, using the specified exportsettings
.Returns a result code indicating whether the export was successful or an error was encountered.
print(iterator: QgsAbstractLayoutIterator, printer: QPrinter, settings: QgsLayoutExporter.PrintExportSettings, feedback: QgsFeedback = None) -> Tuple[QgsLayoutExporter.ExportResult, str] Exports a layout
iterator
to aprinter
, with the specified exportsettings
.Returns a result code indicating whether the export was successful or an error was encountered. If an error was obtained then
error
will be set to the error description.
-
renderPage
(self, painter: QPainter, page: int)¶ Renders a full page to a destination
painter
.The
page
argument specifies the page number to render. Page numbers are 0 based, such that the first page in a layout is page 0.See also
-
renderPageToImage
(self, page: int, imageSize: QSize = QSize(), dpi: float = -1) → QImage¶ Renders a full page to an image.
The
page
argument specifies the page number to render. Page numbers are 0 based, such that the first page in a layout is page 0.The optional
imageSize
parameter can specify the target image size, in pixels. It is the caller’s responsibility to ensure that the ratio of the target image size matches the ratio of the corresponding layout page size.The
dpi
parameter is an optional dpi override. Set to -1 to use the default layout print resolution. This parameter has no effect ifimageSize
is specified.Returns the rendered image, or a null QImage if the image does not fit into available memory.
See also
See also
-
renderRegion
(self, painter: QPainter, region: QRectF)¶ Renders a
region
from the layout to apainter
. This method can be used to render sections of pages rather than full pages.See also
See also
-
renderRegionToImage
(self, region: QRectF, imageSize: QSize = QSize(), dpi: float = -1) → QImage¶ Renders a
region
of the layout to an image. This method can be used to render sections of pages rather than full pages.The optional
imageSize
parameter can specify the target image size, in pixels. It is the caller’s responsibility to ensure that the ratio of the target image size matches the ratio of the specified region of the layout.The
dpi
parameter is an optional dpi override. Set to -1 to use the default layout print resolution. This parameter has no effect ifimageSize
is specified.Returns the rendered image, or a null QImage if the image does not fit into available memory.
See also
See also
-