27 QString QgsLayoutToPdfAlgorithm::name()
const
29 return QStringLiteral(
"printlayouttopdf" );
32 QString QgsLayoutToPdfAlgorithm::displayName()
const
34 return QObject::tr(
"Export print layout as PDF" );
37 QStringList QgsLayoutToPdfAlgorithm::tags()
const
39 return QObject::tr(
"layout,composer,composition,save" ).split(
',' );
42 QString QgsLayoutToPdfAlgorithm::group()
const
44 return QObject::tr(
"Cartography" );
47 QString QgsLayoutToPdfAlgorithm::groupId()
const
49 return QStringLiteral(
"cartography" );
52 QString QgsLayoutToPdfAlgorithm::shortDescription()
const
54 return QObject::tr(
"Exports a print layout as a PDF." );
57 QString QgsLayoutToPdfAlgorithm::shortHelpString()
const
59 return QObject::tr(
"This algorithm outputs a print layout as a PDF file." );
62 void QgsLayoutToPdfAlgorithm::initAlgorithm(
const QVariantMap & )
66 std::unique_ptr< QgsProcessingParameterMultipleLayers > layersParam = qgis::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 = qgis::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 = qgis::make_unique< QgsProcessingParameterBoolean >( QStringLiteral(
"FORCE_VECTOR" ), QObject::tr(
"Always export as vectors" ),
false );
76 addParameter( forceVectorParam.release() );
78 std::unique_ptr< QgsProcessingParameterBoolean > appendGeorefParam = qgis::make_unique< QgsProcessingParameterBoolean >( QStringLiteral(
"GEOREFERENCE" ), QObject::tr(
"Append georeference information" ),
true );
80 addParameter( appendGeorefParam.release() );
82 std::unique_ptr< QgsProcessingParameterBoolean > exportRDFParam = qgis::make_unique< QgsProcessingParameterBoolean >( QStringLiteral(
"INCLUDE_METADATA" ), QObject::tr(
"Export RDF metadata (title, author, etc.)" ),
true );
84 addParameter( exportRDFParam.release() );
86 std::unique_ptr< QgsProcessingParameterBoolean > disableTiled = qgis::make_unique< QgsProcessingParameterBoolean >( QStringLiteral(
"DISABLE_TILED" ), QObject::tr(
"Disable tiled raster layer exports" ),
false );
88 addParameter( disableTiled.release() );
90 std::unique_ptr< QgsProcessingParameterBoolean > simplify = qgis::make_unique< QgsProcessingParameterBoolean >( QStringLiteral(
"SIMPLIFY" ), QObject::tr(
"Simplify geometries to reduce output file size" ),
true );
92 addParameter( simplify.release() );
94 QStringList textExportOptions
96 QObject::tr(
"Always Export Text as Paths (Recommended)" ),
97 QObject::tr(
"Always Export Text as Text Objects" )
100 std::unique_ptr< QgsProcessingParameterEnum > textFormat = qgis::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"TEXT_FORMAT" ), QObject::tr(
"Text export" ), textExportOptions,
false, 0 );
102 addParameter( textFormat.release() );
104 std::unique_ptr< QgsProcessingParameterBoolean > layeredExport = qgis::make_unique< QgsProcessingParameterBoolean >( QStringLiteral(
"SEPARATE_LAYERS" ), QObject::tr(
"Export layers as separate PDF files" ),
false );
106 addParameter( layeredExport.release() );
111 QgsProcessingAlgorithm::Flags QgsLayoutToPdfAlgorithm::flags()
const
116 QgsLayoutToPdfAlgorithm *QgsLayoutToPdfAlgorithm::createInstance()
const
118 return new QgsLayoutToPdfAlgorithm();
124 QgsPrintLayout *l = parameterAsLayout( parameters, QStringLiteral(
"LAYOUT" ), context );
126 throw QgsProcessingException( QObject::tr(
"Cannot find layout with name \"%1\"" ).arg( parameters.value( QStringLiteral(
"LAYOUT" ) ).toString() ) );
127 std::unique_ptr< QgsPrintLayout > layout( l->
clone() );
129 const QList< QgsMapLayer * > layers = parameterAsLayerList( parameters, QStringLiteral(
"LAYERS" ), context );
130 if ( layers.size() > 0 )
132 const QList<QGraphicsItem *> items = layout->items();
133 for ( QGraphicsItem *graphicsItem : items )
145 const QString dest = parameterAsFileOutput( parameters, QStringLiteral(
"OUTPUT" ), context );
150 if ( parameters.value( QStringLiteral(
"DPI" ) ).isValid() )
152 settings.
dpi = parameterAsDouble( parameters, QStringLiteral(
"DPI" ), context );
155 settings.
forceVectorOutput = parameterAsBool( parameters, QStringLiteral(
"FORCE_VECTOR" ), context );
156 settings.
appendGeoreference = parameterAsBool( parameters, QStringLiteral(
"GEOREFERENCE" ), context );
157 settings.
exportMetadata = parameterAsBool( parameters, QStringLiteral(
"INCLUDE_METADATA" ), context );
158 settings.
exportMetadata = parameterAsBool( parameters, QStringLiteral(
"INCLUDE_METADATA" ), context );
159 settings.
simplifyGeometries = parameterAsBool( parameters, QStringLiteral(
"SIMPLIFY" ), context );
163 if ( parameterAsBool( parameters, QStringLiteral(
"DISABLE_TILED" ), context ) )
168 switch ( exporter.exportToPdf( dest, settings ) )
172 feedback->
pushInfo( QObject::tr(
"Successfully exported layout to %1" ).arg( QDir::toNativeSeparators( dest ) ) );
177 throw QgsProcessingException( QObject::tr(
"Cannot write to %1.\n\nThis file may be open in another application." ).arg( QDir::toNativeSeparators( dest ) ) );
184 "resulted in a memory overflow.\n\n"
185 "Please try a lower resolution or a smaller paper size." ) );
197 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );