QPdfDocument
(5.15.2), in the QtPDF module (part of QtWebEngine), seems to not be fully documented yet (presumably because it's fairly new, first appearing in 5.14).
What are the units of the size returned by QPdfDocument::pageSize()
(don't bother checking those docs, it's not there)?
It appears to be some reasonable (albeit seemingly low-res) pixel-like units except I'm not sure how it is deducing the document's DPI. Also I've only tested on a limited set of PDF's all generated from the same source, so I'm not sure how normal my observations are, especially given it's a QSizeF
rather than a QSize
(which raises the possibility of e.g. other non-pixel units in other as-of-yet unencountered contexts).
Ultimately what I'd like to do is get the page size of a loaded document's page in physical units (e.g. inches) then determine a rendered output size in pixels given a user-specified DPI.
An example of the values I've observed:
#include <QCoreApplication>
#include <QDebug>
#include <QtNetwork>
#include <QtPdf>
int main (int argc, char *argv[]) {
QCoreApplication app(argc, argv);
QUrl url("http://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf");
QNetworkAccessManager internet;
QNetworkReply *reply = internet.get(QNetworkRequest(url));
QObject::connect(reply, &QNetworkReply::finished, [reply] () {
QPdfDocument pdf;
pdf.load(reply);
qDebug() << reply->url() << ":";
for (int k = 0; k < pdf.pageCount(); ++ k)
qDebug() << k << pdf.pageSize(k);
QCoreApplication::exit();
});
return app.exec();
}
Outputs:
QUrl("http://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf") :
0 QSizeF(595, 842)
Looks like the implementation is done with PDFium. Qt calls FPDF_GetPageSizeByIndex and the docs state the height/width is in points:
This is also noted in the PDFium SDK manual.