Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Layout] Geospatial PDF has slightly incorrect dimensions (e.g. A4: 297 x 210.3 instead of 297 x 210) #60267

Open
2 tasks done
agiudiceandrea opened this issue Jan 24, 2025 · 0 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Print Layouts Related to QGIS Print Layouts, Atlas or Reporting frameworks

Comments

@agiudiceandrea
Copy link
Contributor

agiudiceandrea commented Jan 24, 2025

What is the bug or the crash?

Exporting a layout as Geospatial PDF, the exported PDF may have slightly incorrect dimensions e.g.:

  • page size A4 landascape (297mm x 210mm): PDF size 297mm x 210.3mm (instead of 297mm x 210mm) A4L.pdf
  • page size A0 portrait (841mm x 1189mm): PDF size 841mm x 1189.2mm (instead of 841mm x 1189mm) A0P.pdf

Steps to reproduce the issue

  1. export a layout as a Geospatial PDF with A4 page size
  2. open the export PDF with a PDF reader and check the page size

Versions

QGIS version3.40.2-Bratislava
QGIS code revision14826ca1
 
Libraries
Qt version5.15.13
Python version3.12.8
GDAL/OGR version3.9.3
PROJ version9.5.0
EPSG Registry database versionv11.016 (2024-08-31)
GEOS version3.13.0-CAPI-1.19.0
SQLite version3.46.1
PDAL version2.8.1
PostgreSQL client version16.2
SpatiaLite version5.1.0
QWT version6.3.0
QScintilla2 version2.14.1
OS versionWindows 10 Version 1903
 
Active Python plugins
db_manager0.1.20
grassprovider2.12.99
MetaSearch0.3.6
processing2.12.99

Supported QGIS version

  • I'm running a supported QGIS version according to the roadmap.

New profile

Additional context

It looks like the issue may be due to the fact that the "page size in PDF units" written in the composition.xml file is rounded using the std::ceil function instead of std::round

QDomElement width = doc.createElement( QStringLiteral( "Width" ) );
const double pageWidthPdfUnits = std::ceil( details.pageSizeMm.width() / 25.4 * 72 );
width.appendChild( doc.createTextNode( qgsDoubleToString( pageWidthPdfUnits ) ) );
page.appendChild( width );
QDomElement height = doc.createElement( QStringLiteral( "Height" ) );
const double pageHeightPdfUnits = std::ceil( details.pageSizeMm.height() / 25.4 * 72 );
height.appendChild( doc.createTextNode( qgsDoubleToString( pageHeightPdfUnits ) ) );
page.appendChild( height );

That leads to e.g. an A4 landascape Geospatial PDF having /MediaBox [ 0 0 842 596 ] instead of /MediaBox [ 0 0 842 595 ] or an A0 portrait Geospatial PDF having /MediaBox [ 0 0 2384 3371 ] instead of /MediaBox [ 0 0 2384 3370 ]

See, for reference: "International standard paper sizes in PostScript and PDF"

@agiudiceandrea agiudiceandrea added Bug Either a bug report, or a bug fix. Let's hope for the latter! Print Layouts Related to QGIS Print Layouts, Atlas or Reporting frameworks labels Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Print Layouts Related to QGIS Print Layouts, Atlas or Reporting frameworks
Projects
None yet
Development

No branches or pull requests

1 participant