From a3a91c947c8fecb29b3ea488e2e0f2a1fbbde2f2 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Tue, 14 May 2024 17:37:18 +0200 Subject: [PATCH] PDF: write a TrimBox MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is necessary for PDF/X-4 conformance (ยง 6.12), but does not hurt specify it always, matching the MediaBox. This work has been kindly sponsored by the QGIS project (https://qgis.org/). Change-Id: Ifc698f271eb1217da15413e4bf25321dea2e955f Reviewed-by: Tobias Koenig Reviewed-by: Albert Astals Cid --- src/gui/painting/qpdf.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp index aaaf70087c..31e8bbdc12 100644 --- a/src/gui/painting/qpdf.cpp +++ b/src/gui/painting/qpdf.cpp @@ -2126,17 +2126,24 @@ void QPdfEnginePrivate::writePage() qreal userUnit = calcUserUnit(); addXrefEntry(pages.constLast()); + + // make sure we use the pagesize from when we started the page, since the user may have changed it + const QByteArray formattedPageWidth = QByteArray::number(currentPage->pageSize.width() / userUnit, 'f'); + const QByteArray formattedPageHeight = QByteArray::number(currentPage->pageSize.height() / userUnit, 'f'); + xprintf("<<\n" "/Type /Page\n" "/Parent %d 0 R\n" "/Contents %d 0 R\n" "/Resources %d 0 R\n" "/Annots %d 0 R\n" - "/MediaBox [0 0 %s %s]\n", + "/MediaBox [0 0 %s %s]\n" + "/TrimBox [0 0 %s %s]\n", pageRoot, pageStream, resources, annots, - // make sure we use the pagesize from when we started the page, since the user may have changed it - QByteArray::number(currentPage->pageSize.width() / userUnit, 'f').constData(), - QByteArray::number(currentPage->pageSize.height() / userUnit, 'f').constData()); + formattedPageWidth.constData(), + formattedPageHeight.constData(), + formattedPageWidth.constData(), + formattedPageHeight.constData()); if (pdfVersion >= QPdfEngine::Version_1_6) xprintf("/UserUnit %s\n", QByteArray::number(userUnit, 'f').constData());