The export module

Export Pages to different file formats.

class AbstractExporter(page, rect=None)[source]

Bases: object

Base class to export a rectangular area of a Page to a file.

Specialized subclasses implement each format.

You instantiate a subclass with a Page and a rectangle. The rectangle may be None, to specify the full page. After instantiation, you can set attributes to configure the export. The following attributes are supported:

resolution = 300
autocrop = False
oversample = 1
grayscale = False
paperColor = None
forceVector = True  # force the render backend to be Arthur for
                    # exporting PDF pages to vector-based formats

After setting the attributes, you call one or more of save(), copyData(), copyFile(), mimeData() or tempFileMimeData(), which will trigger the export because they internally call data(), which caches its return value until setPage() is called again.

Not all exporters support all attributes, the supportXXX attributes specify whether an attribute is supported or not.

resolution = 300
antialiasing = True
autocrop = False
oversample = 1
grayscale = False
paperColor = None
forceVector = True
wantsVector = True
supportsResolution = True
supportsAntialiasing = True
supportsAutocrop = True
supportsOversample = True
supportsGrayscale = True
supportsPaperColor = True
mimeType = 'application/octet-stream'
filename = ''
defaultBasename = 'document'
defaultExt = ''
setPage(page, rect=None)[source]
page()[source]

Return our page, setting the renderer to our preferences.

autoCroppedRect()[source]

Return the rect, autocropped if desired.

export()[source]

Perform the export, based on the settings, and return the exported data object.

successful()[source]

Return True when export was successful.

data()[source]

Return the export result, assuming it is binary data of the exported file.

document()[source]

Return a one-page Document to display the image to export.

Internally calls createDocument(), and caches the result, setting the papercolor to the papercolor attribute if the exporter supports papercolor.

createDocument()[source]

Create and return a one-page Document to display the image to export.

renderer()[source]

Return a renderer for the document(). By default, None is returned.

copyData()[source]

Copy the QMimeData() to the clipboard.

mimeData()[source]

Return a QMimeData() object representing the exported data.

save(filename)[source]

Save the exported image to a file.

suggestedFilename()[source]

Return a suggested file name for the file to export.

The name is based on the filename (if set) and also contains the directory path. But the name will never be the same as the filename set in the filename attribute.

tempFilename()[source]

Save data() to a tempfile and returns the filename.

tempFileMimeData()[source]

Save the exported image to a temp file and return a QMimeData object for the url.

copyFile()[source]

Save the exported image to a temp file and copy its name to the clipboard.

pixmap(size=100)[source]

Return a small pixmap to use for dragging etc.

drag(parent, mimeData)[source]

Called by dragFile and dragData. Execs a QDrag on the mime data.

dragData(parent)[source]

Start dragging the data. Parent can be any QObject.

dragFile(parent)[source]

Start dragging the data. Parent can be any QObject.

class ImageExporter(page, rect=None)[source]

Bases: qpageview.export.AbstractExporter

Export a rectangular area of a Page (or the whole page) to an image.

wantsVector = False
defaultBasename = 'image'
defaultExt = '.png'
export()[source]

Create the QImage representing the exported image.

image()[source]
createDocument()[source]

Create and return a one-page Document to display the image to export.

copyData()[source]

Copy the QMimeData() to the clipboard.

mimeData()[source]

Return a QMimeData() object representing the exported data.

save(filename)[source]

Save the exported image to a file.

class SvgExporter(page, rect=None)[source]

Bases: qpageview.export.AbstractExporter

Export a rectangular area of a Page (or the whole page) to a SVG file.

mimeType = 'image/svg'
supportsGrayscale = False
supportsOversample = False
defaultBasename = 'image'
defaultExt = '.svg'
export()[source]

Perform the export, based on the settings, and return the exported data object.

createDocument()[source]

Create and return a one-page Document to display the image to export.

class PdfExporter(page, rect=None)[source]

Bases: qpageview.export.AbstractExporter

Export a rectangular area of a Page (or the whole page) to a PDF file.

mimeType = 'application/pdf'
supportsGrayscale = False
supportsOversample = False
defaultExt = '.pdf'
export()[source]

Perform the export, based on the settings, and return the exported data object.

createDocument()[source]

Create and return a one-page Document to display the image to export.

class EpsExporter(page, rect=None)[source]

Bases: qpageview.export.AbstractExporter

Export a rectangular area of a Page (or the whole page) to an EPS file.

mimeType = 'application/postscript'
supportsGrayscale = False
supportsOversample = False
defaultExt = '.eps'
export()[source]

Perform the export, based on the settings, and return the exported data object.

createDocument()[source]

Create and return a one-page Document to display the image to export.

pdf(filename, pageList, resolution=72, paperColor=None)[source]

Export the pages in pageList to a PDF document.

filename can be a string or any QIODevice. The pageList is a list of the Page objects to export.

Normally vector graphics are rendered, but in cases where that is not possible, the resolution will be used to determine the DPI for the generated rendering.

The computedRotation attribute of the pages is used to determine the rotation.

Make copies of the pages if you run this function in a background thread.