Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. What are the units of QPdfDocument::pageSize?
QtWS25 Last Chance

What are the units of QPdfDocument::pageSize?

Scheduled Pinned Locked Moved Solved QtWebEngine
4 Posts 2 Posters 913 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mnbv
    wrote on last edited by
    #1

    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.

    jsulmJ 1 Reply Last reply
    0
    • M Offline
      M Offline
      mnbv
      wrote on last edited by mnbv
      #4

      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)
      
      1 Reply Last reply
      1
      • M mnbv

        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.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @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

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        M 1 Reply Last reply
        0
        • jsulmJ jsulm

          @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

          M Offline
          M Offline
          mnbv
          wrote on last edited by mnbv
          #3

          @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.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mnbv
            wrote on last edited by mnbv
            #4

            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)
            
            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved