28 QString QgsLayoutAtlasToPdfAlgorithm::name()
const
30 return QStringLiteral(
"atlaslayouttopdf" );
33 QString QgsLayoutAtlasToPdfAlgorithm::displayName()
const
35 return QObject::tr(
"Export atlas layout as PDF" );
38 QStringList QgsLayoutAtlasToPdfAlgorithm::tags()
const
40 return QObject::tr(
"layout,atlas,composer,composition,save" ).split(
',' );
43 QString QgsLayoutAtlasToPdfAlgorithm::group()
const
45 return QObject::tr(
"Cartography" );
48 QString QgsLayoutAtlasToPdfAlgorithm::groupId()
const
50 return QStringLiteral(
"cartography" );
53 QString QgsLayoutAtlasToPdfAlgorithm::shortDescription()
const
55 return QObject::tr(
"Exports an atlas layout as a PDF." );
58 QString QgsLayoutAtlasToPdfAlgorithm::shortHelpString()
const
60 return QObject::tr(
"This algorithm outputs an atlas layout as a PDF file.\n\n"
61 "If a coverage layer is set, the selected layout's atlas settings exposed in this algorithm "
62 "will be overwritten. In this case, an empty filter or sort by expression will turn those "
66 void QgsLayoutAtlasToPdfAlgorithm::initAlgorithm(
const QVariantMap & )
71 addParameter(
new QgsProcessingParameterExpression( QStringLiteral(
"FILTER_EXPRESSION" ), QObject::tr(
"Filter expression" ), QString(), QStringLiteral(
"COVERAGE_LAYER" ),
true ) );
72 addParameter(
new QgsProcessingParameterExpression( QStringLiteral(
"SORTBY_EXPRESSION" ), QObject::tr(
"Sort expression" ), QString(), QStringLiteral(
"COVERAGE_LAYER" ),
true ) );
73 addParameter(
new QgsProcessingParameterBoolean( QStringLiteral(
"SORTBY_REVERSE" ), QObject::tr(
"Reverse sort order (used when a sort expression is provided)" ),
false,
true ) );
77 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 );
79 addParameter( layersParam.release() );
81 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 );
83 addParameter( dpiParam.release() );
85 std::unique_ptr< QgsProcessingParameterBoolean > forceVectorParam = qgis::make_unique< QgsProcessingParameterBoolean >( QStringLiteral(
"FORCE_VECTOR" ), QObject::tr(
"Always export as vectors" ),
false );
87 addParameter( forceVectorParam.release() );
89 std::unique_ptr< QgsProcessingParameterBoolean > appendGeorefParam = qgis::make_unique< QgsProcessingParameterBoolean >( QStringLiteral(
"GEOREFERENCE" ), QObject::tr(
"Append georeference information" ),
true );
91 addParameter( appendGeorefParam.release() );
93 std::unique_ptr< QgsProcessingParameterBoolean > exportRDFParam = qgis::make_unique< QgsProcessingParameterBoolean >( QStringLiteral(
"INCLUDE_METADATA" ), QObject::tr(
"Export RDF metadata (title, author, etc.)" ),
true );
95 addParameter( exportRDFParam.release() );
97 std::unique_ptr< QgsProcessingParameterBoolean > disableTiled = qgis::make_unique< QgsProcessingParameterBoolean >( QStringLiteral(
"DISABLE_TILED" ), QObject::tr(
"Disable tiled raster layer exports" ),
false );
99 addParameter( disableTiled.release() );
101 std::unique_ptr< QgsProcessingParameterBoolean > simplify = qgis::make_unique< QgsProcessingParameterBoolean >( QStringLiteral(
"SIMPLIFY" ), QObject::tr(
"Simplify geometries to reduce output file size" ),
true );
103 addParameter( simplify.release() );
105 QStringList textExportOptions
107 QObject::tr(
"Always Export Text as Paths (Recommended)" ),
108 QObject::tr(
"Always Export Text as Text Objects" )
111 std::unique_ptr< QgsProcessingParameterEnum > textFormat = qgis::make_unique< QgsProcessingParameterEnum >( QStringLiteral(
"TEXT_FORMAT" ), QObject::tr(
"Text export" ), textExportOptions,
false, 0 );
113 addParameter( textFormat.release() );
116 QgsProcessingAlgorithm::Flags QgsLayoutAtlasToPdfAlgorithm::flags()
const
121 QgsLayoutAtlasToPdfAlgorithm *QgsLayoutAtlasToPdfAlgorithm::createInstance()
const
123 return new QgsLayoutAtlasToPdfAlgorithm();
129 QgsPrintLayout *l = parameterAsLayout( parameters, QStringLiteral(
"LAYOUT" ), context );
131 throw QgsProcessingException( QObject::tr(
"Cannot find layout with name \"%1\"" ).arg( parameters.value( QStringLiteral(
"LAYOUT" ) ).toString() ) );
133 std::unique_ptr< QgsPrintLayout > layout( l->
clone() );
136 QString expression, error;
137 QgsVectorLayer *layer = parameterAsVectorLayer( parameters, QStringLiteral(
"COVERAGE_LAYER" ), context );
143 expression = parameterAsString( parameters, QStringLiteral(
"FILTER_EXPRESSION" ), context );
145 if ( !expression.isEmpty() && !error.isEmpty() )
151 expression = parameterAsString( parameters, QStringLiteral(
"SORTBY_EXPRESSION" ), context );
152 if ( !expression.isEmpty() )
154 const bool sortByReverse = parameterAsBool( parameters, QStringLiteral(
"SORTBY_REVERSE" ), context );
172 if ( parameters.value( QStringLiteral(
"DPI" ) ).isValid() )
174 settings.
dpi = parameterAsDouble( parameters, QStringLiteral(
"DPI" ), context );
176 settings.
forceVectorOutput = parameterAsBool( parameters, QStringLiteral(
"FORCE_VECTOR" ), context );
177 settings.
appendGeoreference = parameterAsBool( parameters, QStringLiteral(
"GEOREFERENCE" ), context );
178 settings.
exportMetadata = parameterAsBool( parameters, QStringLiteral(
"INCLUDE_METADATA" ), context );
179 settings.
simplifyGeometries = parameterAsBool( parameters, QStringLiteral(
"SIMPLIFY" ), context );
182 if ( parameterAsBool( parameters, QStringLiteral(
"DISABLE_TILED" ), context ) )
187 const QList< QgsMapLayer * > layers = parameterAsLayerList( parameters, QStringLiteral(
"LAYERS" ), context );
188 if ( layers.size() > 0 )
190 const QList<QGraphicsItem *> items = layout->items();
191 for ( QGraphicsItem *graphicsItem : items )
203 const QString dest = parameterAsFileOutput( parameters, QStringLiteral(
"OUTPUT" ), context );
204 switch ( exporter.exportToPdf( atlas, dest, settings, error, feedback ) )
208 feedback->
pushInfo( QObject::tr(
"Successfully exported layout to %1" ).arg( QDir::toNativeSeparators( dest ) ) );
213 throw QgsProcessingException( QObject::tr(
"Cannot write to %1.\n\nThis file may be open in another application." ).arg( QDir::toNativeSeparators( dest ) ) );
220 "resulted in a memory overflow.\n\n"
221 "Please try a lower resolution or a smaller paper size." ) );
235 outputs.insert( QStringLiteral(
"OUTPUT" ), dest );