What are the units of QPdfDocument::pageSize?
-
QPdfDocument (5.15.2) seems to not be fully documented yet.
What are the units of the size returned by pageSize()?
It appears to be some reasonable pixel-like units except I'm not sure what it's assuming the document's DPI to be. 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 in physical units (e.g. inches) then determine a rendered output size in pixels given a user-specified DPI.
-
I broke down and asked on SO, where user Mike dug into the source (which I guess I should've done).
Long story short, the size returned by
pageSize()
is in points, and a little further research confirmed it uses the DTP definition where 72 points = 1 inch. The results I'm seeing agree with that scaling.
#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) << pdf.pageSize(k) / 72.0f; QCoreApplication::exit(); }); return app.exec(); }
Outputs:
QUrl("http://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf") : 0 QSizeF(595, 842) QSizeF(8.26389, 11.6944)
-
QPdfDocument (5.15.2) seems to not be fully documented yet.
What are the units of the size returned by pageSize()?
It appears to be some reasonable pixel-like units except I'm not sure what it's assuming the document's DPI to be. 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 in physical units (e.g. inches) then determine a rendered output size in pixels given a user-specified DPI.
@mnbv What Qt version do you use? I can't find anything like size() or pageSize() in https://doc-snapshots.qt.io/qt5-5.15/qpdfdocument-members.html
-
@mnbv What Qt version do you use? I can't find anything like size() or pageSize() in https://doc-snapshots.qt.io/qt5-5.15/qpdfdocument-members.html
@jsulm said in What are the units of QPdfDocument::pageSize?:
@mnbv What Qt version do you use? I can't find anything like size() or pageSize() in https://doc-snapshots.qt.io/qt5-5.15/qpdfdocument-members.html
@mnbv said in What are the units of QPdfDocument::pageSize?:
QPdfDocument (5.15.2) seems to not be fully documented yet.
-
I broke down and asked on SO, where user Mike dug into the source (which I guess I should've done).
Long story short, the size returned by
pageSize()
is in points, and a little further research confirmed it uses the DTP definition where 72 points = 1 inch. The results I'm seeing agree with that scaling.
#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) << pdf.pageSize(k) / 72.0f; QCoreApplication::exit(); }); return app.exec(); }
Outputs:
QUrl("http://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf") : 0 QSizeF(595, 842) QSizeF(8.26389, 11.6944)