Skip to content

Conversation

@gacarrillor
Copy link
Member

This PR allows users to preserve the layer structure (including nested groups) when exporting to Geospatial PDF. It is handy for users that want to export their QGIS layer/group configuration (names, order, visibility) in one go, rather than set a different custom layer/group configuration.

This feature will only be available for layouts and not for map rendering tasks (i.e., Project->Import/Export->Export Map to PDF). Currently, the latter always outputs Geospatial PDFs with a flat layer list anyways.

It is only enabled if there is at least one map item in the layout that is not following map themes nor locked layers, because those are not compatible with the QGIS project's layer tree configuration.

Both visible and invisible layers from the QGIS project are included in the output PDF.

If a user has set a custom layer order (via QGIS' Layer Order Panel) overriding the layer tree order, layers are rendered in the PDF following the custom order. However, the PDF layer tree structure will match the QGIS layer tree structure.

The export will either include feature info (attributes) for ALL layers or ignore feature info (attributes) for ALL layers. This depends on the PdfExportSettings::includeGeoPdfFeatures value. (In an eventual follow-up, users could choose which layers should include feature info.)

GroupLayers are supported and are treated as single map layers in the exported PDF.

When a Geospatial PDF Group has been set for layout items (via Item Properties -> Rendering -> Geospatial PDF Group), there are two options:

  • If the PDF group matches a QGIS layer tree group name, the visibility of the layout item will be handled via that existing group in the PDF layer tree. (Exceptions: GroupLayers, or groups that were considered empty or with only invalid/geometryless layers).
  • If the PDF group has a name that is not present in the QGIS layer tree, then a new group will appear at the bottom of the PDF layer tree, controlling the visibility of the corresponding layout item(s)

Mutually exclusive groups are currently not supported.

Unit tests have been added.

Screenshot:

image

Funded by the city of Bern

…on making the main method much more readable
…orter::PdfExportSettings and QgsAbstractGeospatialPdfExporter::ExportDetails to export a PDF following the main QGIS layer tree configuration properties (e.g., name, order, visibility). Add QgsAbstractGeospatialPdfExporter::createLayerTreeAndContentXmlSectionsFromLayerTree() with initial logic to export qgis layers and groupsfollowing the QGIS layer tree (only valid for layout exports, and not for exports made using a map renderer task).
…end, pictures, and the like) are grouped according to their 'Properties->Rendering->Geospatial PDF group' setting. This includes the option to add graphical layout items to an existent group coming from the QGIS layer tree. Note that in all cases, graphical layout items are not shown in the PDF layer tree individually (but they'll be visible in the PDF pages). Instead, groups of graphical layout items are always shown in the PDF layer tree (note: if a PDF group is composed of graphical layout items only, it will be seen as a layer, that is, it'll not have children nodes).
…nfo, and with and without (grouped) layout items (e.g., scale, picture, title, etc.)
…tion for the export instead of a custom configuration (i.e., layer and group names, orer, etc., as well as map themes)
…invalid or geometryless layers) and invalid/geometryless layers in the PDF layer tree
…p item layers to match project layers (including invisible ones) before rendering the layers to intermediate PDFs. After the rendering operation, restore the layers that map items had before we set the project layers. We only set project layers to those map items that don't follow map themes nor locked layers/styles, and if there's no map where we can set project layers (because all maps follow presets), then we exit the export operation with an error message.
…ation in GUI if there is at least one map item that is not following map themes nor locked layers.
…ayer tree properties (note: the GroupLayer is handled as a single map layer in the exported PDF)
…he Composition XML file (avoiding duplicate code)
…and for obtaining PrintError when all layout map items follow either map themes or locked layers
@github-actions github-actions bot added this to the 4.0.0 milestone Jan 25, 2026
@gacarrillor gacarrillor added Feature Print Layouts Related to QGIS Print Layouts, Atlas or Reporting frameworks Table of contents labels Jan 25, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 25, 2026

🪟 Windows Qt6 builds

Download Windows Qt6 builds of this PR for testing.
(Built from commit e0fe751)

🍎 MacOS Qt6 builds

Download MacOS Qt6 builds of this PR for testing.
This installer is not signed, control+click > open the app to avoid the warning
(Built from commit e0fe751)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature Print Layouts Related to QGIS Print Layouts, Atlas or Reporting frameworks Table of contents

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant