27QString QgsLayoutToPdfAlgorithm::name()
 const 
   29  return QStringLiteral( 
"printlayouttopdf" );
 
   32QString QgsLayoutToPdfAlgorithm::displayName()
 const 
   34  return QObject::tr( 
"Export print layout as PDF" );
 
   37QStringList QgsLayoutToPdfAlgorithm::tags()
 const 
   39  return QObject::tr( 
"layout,composer,composition,save" ).split( 
',' );
 
   42QString QgsLayoutToPdfAlgorithm::group()
 const 
   44  return QObject::tr( 
"Cartography" );
 
   47QString QgsLayoutToPdfAlgorithm::groupId()
 const 
   49  return QStringLiteral( 
"cartography" );
 
   52QString QgsLayoutToPdfAlgorithm::shortDescription()
 const 
   54  return QObject::tr( 
"Exports a print layout as a PDF." );
 
   57QString QgsLayoutToPdfAlgorithm::shortHelpString()
 const 
   59  return QObject::tr( 
"This algorithm outputs a print layout as a PDF file." );
 
   62void QgsLayoutToPdfAlgorithm::initAlgorithm( 
const QVariantMap & )
 
   66  std::unique_ptr< QgsProcessingParameterMultipleLayers > layersParam = std::make_unique< QgsProcessingParameterMultipleLayers>( QStringLiteral( 
"LAYERS" ), QObject::tr( 
"Map layers to assign to unlocked map item(s)" ), 
QgsProcessing::TypeMapLayer, QVariant(), 
true );
 
   68  addParameter( layersParam.release() );
 
   70  std::unique_ptr< QgsProcessingParameterNumber > dpiParam = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( 
"DPI" ), QObject::tr( 
"DPI (leave blank for default layout DPI)" ), 
QgsProcessingParameterNumber::Double, QVariant(), 
true, 0 );
 
   72  addParameter( dpiParam.release() );
 
   74  std::unique_ptr< QgsProcessingParameterBoolean > forceVectorParam = std::make_unique< QgsProcessingParameterBoolean >( QStringLiteral( 
"FORCE_VECTOR" ), QObject::tr( 
"Always export as vectors" ), 
false );
 
   76  addParameter( forceVectorParam.release() );
 
   78  std::unique_ptr< QgsProcessingParameterBoolean > forceRasterParam = std::make_unique< QgsProcessingParameterBoolean >( QStringLiteral( 
"FORCE_RASTER" ), QObject::tr( 
"Always export as raster" ), 
false );
 
   80  addParameter( forceRasterParam.release() );
 
   82  std::unique_ptr< QgsProcessingParameterBoolean > appendGeorefParam = std::make_unique< QgsProcessingParameterBoolean >( QStringLiteral( 
"GEOREFERENCE" ), QObject::tr( 
"Append georeference information" ), 
true );
 
   84  addParameter( appendGeorefParam.release() );
 
   86  std::unique_ptr< QgsProcessingParameterBoolean > exportRDFParam = std::make_unique< QgsProcessingParameterBoolean >( QStringLiteral( 
"INCLUDE_METADATA" ), QObject::tr( 
"Export RDF metadata (title, author, etc.)" ), 
true );
 
   88  addParameter( exportRDFParam.release() );
 
   90  std::unique_ptr< QgsProcessingParameterBoolean > disableTiled = std::make_unique< QgsProcessingParameterBoolean >( QStringLiteral( 
"DISABLE_TILED" ), QObject::tr( 
"Disable tiled raster layer exports" ), 
false );
 
   92  addParameter( disableTiled.release() );
 
   94  std::unique_ptr< QgsProcessingParameterBoolean > simplify = std::make_unique< QgsProcessingParameterBoolean >( QStringLiteral( 
"SIMPLIFY" ), QObject::tr( 
"Simplify geometries to reduce output file size" ), 
true );
 
   96  addParameter( simplify.release() );
 
   98  const QStringList textExportOptions
 
  100    QObject::tr( 
"Always Export Text as Paths (Recommended)" ),
 
  101    QObject::tr( 
"Always Export Text as Text Objects" )
 
  104  std::unique_ptr< QgsProcessingParameterEnum > textFormat = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral( 
"TEXT_FORMAT" ), QObject::tr( 
"Text export" ), textExportOptions, 
false, 0 );
 
  106  addParameter( textFormat.release() );
 
  108  const QStringList imageCompressionOptions
 
  110    QObject::tr( 
"Lossy (JPEG)" ),
 
  111    QObject::tr( 
"Lossless" )
 
  114  std::unique_ptr< QgsProcessingParameterEnum > imageCompression = std::make_unique< QgsProcessingParameterEnum >( QStringLiteral( 
"IMAGE_COMPRESSION" ), QObject::tr( 
"Image compression" ), imageCompressionOptions, 
false, 0 );
 
  116  addParameter( imageCompression.release() );
 
  118  std::unique_ptr< QgsProcessingParameterBoolean > layeredExport = std::make_unique< QgsProcessingParameterBoolean >( QStringLiteral( 
"SEPARATE_LAYERS" ), QObject::tr( 
"Export layers as separate PDF files" ), 
false );
 
  120  addParameter( layeredExport.release() );
 
  125QgsProcessingAlgorithm::Flags QgsLayoutToPdfAlgorithm::flags()
 const 
  130QgsLayoutToPdfAlgorithm *QgsLayoutToPdfAlgorithm::createInstance()
 const 
  132  return new QgsLayoutToPdfAlgorithm();
 
  138  QgsPrintLayout *l = parameterAsLayout( parameters, QStringLiteral( 
"LAYOUT" ), context );
 
  140    throw QgsProcessingException( QObject::tr( 
"Cannot find layout with name \"%1\"" ).arg( parameters.value( QStringLiteral( 
"LAYOUT" ) ).toString() ) );
 
  141  std::unique_ptr< QgsPrintLayout > layout( l->
clone() );
 
  143  const QList< QgsMapLayer * > layers = parameterAsLayerList( parameters, QStringLiteral( 
"LAYERS" ), context );
 
  144  if ( layers.size() > 0 )
 
  146    const QList<QGraphicsItem *> items = layout->items();
 
  147    for ( QGraphicsItem *graphicsItem : items )
 
  159  const QString dest = parameterAsFileOutput( parameters, QStringLiteral( 
"OUTPUT" ), context );
 
  164  if ( parameters.value( QStringLiteral( 
"DPI" ) ).isValid() )
 
  166    settings.
dpi = parameterAsDouble( parameters, QStringLiteral( 
"DPI" ), context );
 
  169  settings.
forceVectorOutput = parameterAsBool( parameters, QStringLiteral( 
"FORCE_VECTOR" ), context );
 
  170  settings.
rasterizeWholeImage = parameterAsBool( parameters, QStringLiteral( 
"FORCE_RASTER" ), context );
 
  171  settings.
appendGeoreference = parameterAsBool( parameters, QStringLiteral( 
"GEOREFERENCE" ), context );
 
  172  settings.
exportMetadata = parameterAsBool( parameters, QStringLiteral( 
"INCLUDE_METADATA" ), context );
 
  173  settings.
simplifyGeometries = parameterAsBool( parameters, QStringLiteral( 
"SIMPLIFY" ), context );
 
  174  settings.
textRenderFormat = parameterAsEnum( parameters, QStringLiteral( 
"TEXT_FORMAT" ), context ) == 0 ? Qgis::TextRenderFormat::AlwaysOutlines : Qgis::TextRenderFormat::AlwaysText;
 
  177  if ( parameterAsBool( parameters, QStringLiteral( 
"DISABLE_TILED" ), context ) )
 
  182  if ( parameterAsEnum( parameters, QStringLiteral( 
"IMAGE_COMPRESSION" ), context ) == 1 )
 
  187  switch ( exporter.exportToPdf( dest, settings ) )
 
  191      feedback->
pushInfo( QObject::tr( 
"Successfully exported layout to %1" ).arg( QDir::toNativeSeparators( dest ) ) );
 
  196      throw QgsProcessingException( QObject::tr( 
"Cannot write to %1.\n\nThis file may be open in another application." ).arg( QDir::toNativeSeparators( dest ) ) );
 
  203                                    "resulted in a memory overflow.\n\n" 
  204                                    "Please try a lower resolution or a smaller paper size." ) );
 
  216  outputs.insert( QStringLiteral( 
"OUTPUT" ), dest );
 
void setProgress(double progress)
Sets the current progress for the feedback object.
 
Handles rendering and exports of layouts to various formats.
 
@ Canceled
Export was canceled.
 
@ MemoryError
Unable to allocate memory required to export.
 
@ PrintError
Could not start printing to destination device.
 
@ IteratorError
Error iterating over layout.
 
@ FileError
Could not write to destination file, likely due to a lock held by another application.
 
@ Success
Export was successful.
 
@ SvgLayerError
Could not create layered SVG file.
 
Layout graphical items for displaying a map.
 
bool keepLayerSet() const
Returns whether a stored layer set should be used or the current layer set from the project associate...
 
void setKeepLayerSet(bool enabled)
Sets whether the stored layer set should be used or the current layer set of the associated project.
 
bool followVisibilityPreset() const
Returns whether the map should follow a map theme.
 
void setLayers(const QList< QgsMapLayer * > &layers)
Sets the stored layers set.
 
Base class for graphical items within a QgsLayout.
 
Stores information relating to the current rendering settings for a layout.
 
@ FlagLosslessImageRendering
Render images losslessly whenever possible, instead of the default lossy jpeg rendering used for some...
 
@ FlagDisableTiledRasterLayerRenders
If set, then raster layers will not be drawn as separate tiles. This may improve the appearance in ex...
 
Print layout, a QgsLayout subclass for static or atlas-based layouts.
 
QgsPrintLayout * clone() const override
Creates a clone of the layout.
 
virtual Flags flags() const
Returns the flags indicating how and when the algorithm operates and should be exposed to users.
 
Contains information about the context in which a processing algorithm is executed.
 
Custom exception class for processing related exceptions.
 
Base class for providing feedback from a processing algorithm.
 
virtual void pushInfo(const QString &info)
Pushes a general informational message from the algorithm.
 
@ FlagAdvanced
Parameter is an advanced parameter which should be hidden from users by default.
 
A generic file based destination parameter, for specifying the destination path for a file (non-map l...
 
A print layout parameter, allowing users to select a print layout.
 
@ Double
Double/float values.
 
@ TypeMapLayer
Any map layer type (raster, vector, mesh, point cloud, annotation or plugin layer)
 
Contains settings relating to exporting layouts to PDF.
 
bool forceVectorOutput
Set to true to force vector object exports, even when the resultant appearance will differ from the l...
 
bool rasterizeWholeImage
Set to true to force whole layout to be rasterized while exporting.
 
bool exportMetadata
Indicates whether PDF export should include metadata generated from the layout's project's metadata.
 
bool appendGeoreference
Indicates whether PDF export should append georeference data.
 
QgsLayoutRenderContext::Flags flags
Layout context flags, which control how the export will be created.
 
double dpi
Resolution to export layout at. If dpi <= 0 the default layout dpi will be used.
 
bool exportLayersAsSeperateFiles
true if individual layers from the layout should be rendered to separate PDF files.
 
bool simplifyGeometries
Indicates whether vector geometries should be simplified to avoid redundant extraneous detail,...
 
Qgis::TextRenderFormat textRenderFormat
Text rendering format, which controls how text should be rendered in the export (e....