diff --git a/sources/cli_export.cpp b/sources/cli_export.cpp index a132a8e29..aa6c96052 100644 --- a/sources/cli_export.cpp +++ b/sources/cli_export.cpp @@ -227,6 +227,7 @@ int exportPdf(QETProject &project, const QString &output, // Rewrite the URI link annotations into native internal GoTo actions, so // the cross-references jump inside the document in any PDF viewer. PdfLinks::convertUriToGoTo(output); + PdfLinks::removeUnusedPdfxNamespace(output); out << "Exported " << diagrams.size() << " page(s) -> " << output << "\n"; return 0; diff --git a/sources/pdf_links.cpp b/sources/pdf_links.cpp index 5458f396b..6bdf563c1 100644 --- a/sources/pdf_links.cpp +++ b/sources/pdf_links.cpp @@ -388,6 +388,29 @@ void convertUriToGoTo(const QString &pdfPath) out.close(); } +void removeUnusedPdfxNamespace(const QString &pdfPath) +{ + QFile f(pdfPath); + if (!f.open(QIODevice::ReadOnly)) return; + QByteArray data = f.readAll(); + f.close(); + + // Qt only fills the pdfxid namespace in when it writes PDF/X-4. + if (data.contains("pdfxid:GTS_PDFXVersion")) return; + + static const QByteArray decl = + " xmlns:pdfxid=\"http://www.npes.org/pdfx/ns/id/\""; + const int pos = data.indexOf(decl); + if (pos == -1) return; + + // Same length, so the stream /Length and the xref offsets stay valid. + data.replace(pos, decl.size(), QByteArray(decl.size(), ' ')); + + if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate)) return; + f.write(data); + f.close(); +} + void convertComponentInfoAnnotations(const QString &pdfPath, const QList &annotations) { diff --git a/sources/pdf_links.h b/sources/pdf_links.h index 27e266420..325367c53 100644 --- a/sources/pdf_links.h +++ b/sources/pdf_links.h @@ -74,6 +74,15 @@ namespace PdfLinks { */ void convertUriToGoTo(const QString &pdfPath); + /** + Post-process a Qt-generated PDF file: blank out the PDF/X namespace + declaration Qt 6 writes into the XMP metadata of every PDF. Adobe + Acrobat draws small text too bold when it is present (bugtracker #340). + Replaced in place with spaces, so no offset changes. No-op for a real + PDF/X file or when the declaration is absent. + */ + void removeUnusedPdfxNamespace(const QString &pdfPath); + struct ComponentInfo { QString contents; }; diff --git a/sources/print/projectprintwindow.cpp b/sources/print/projectprintwindow.cpp index e6b86efa5..3204a8527 100644 --- a/sources/print/projectprintwindow.cpp +++ b/sources/print/projectprintwindow.cpp @@ -874,6 +874,7 @@ void ProjectPrintWindow::print() // Convert URI link annotations into native internal GoTo/FitR // actions so cross-references jump inside the document. PdfLinks::convertUriToGoTo(pdfFile); + PdfLinks::removeUnusedPdfxNamespace(pdfFile); this->close(); });