Build and work on Qt before 6.8

QPdfWriter::setDocumentId() is new in Qt 6.8, QTimeZone::UTC in 6.5 and
QHashSeed in 6.2, so the build failed on Qt 6.4 (Ubuntu 24.04). Qt before
6.8 also writes no /ModDate and no XMP metadata, and setDocumentDate()
then gave up and left the time of the export in the file. Those two are
now rewritten when present, and no document id is set where Qt writes
none.

tst_pdfreproducible also checks that the xref table still matches the
file after the dates are rewritten.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJw3u5AdKQgQVPug8CzuMQ
This commit is contained in:
ispyisail
2026-10-03 09:30:11 +13:00
parent 51d20abca4
commit 8361a1efce
4 changed files with 78 additions and 35 deletions
+5 -2
View File
@@ -165,7 +165,7 @@ QDateTime sourceDateEpoch()
err << "SOURCE_DATE_EPOCH '" << value << "' is not a number of seconds; ignored.\n";
return {};
}
return QDateTime::fromSecsSinceEpoch(seconds, QTimeZone::UTC);
return QDateTime::fromSecsSinceEpoch(seconds, QTimeZone::utc());
}
int exportPdf(QETProject &project, const QString &output,
@@ -190,8 +190,10 @@ int exportPdf(QETProject &project, const QString &output,
// SOURCE_DATE_EPOCH (reproducible-builds.org) asks for the same file
// from the same input: the time it names instead of now, and a document
// id from the project file instead of a random one. Qt has no setter for
// the dates, so they are rewritten once the file is written.
// the dates, so they are rewritten once the file is written. Before
// Qt 6.8 there is no document id to set: it is only written for PDF/A.
const QDateTime sourceDate = sourceDateEpoch();
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
if (sourceDate.isValid()) {
QCryptographicHash hash(QCryptographicHash::Sha256);
QFile file(project.filePath());
@@ -199,6 +201,7 @@ int exportPdf(QETProject &project, const QString &output,
hash.addData(&file);
writer.setDocumentId(QUuid::createUuidV5(project.uuid(), hash.result()));
}
#endif
QPainter painter;
bool first = true;