Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-106565

The coordinate of QPdfSelection seems like to be wrong when pdf page contains non-displayable area

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3: Somewhat important
    • 6.5.6, 6.7.1, 6.8.0 FF
    • 6.3.0, 6.3.1, 6.3.2
    • PDF
    • None
    • All
    • b78c78349 (dev), 5642f33e1 (6.7), 61a65ca96 (6.6), b0e44197d (6.5)

    Description

      I got wrong coordinate when using QPdfSelection on some specific pdf docments. So I do some research and found this:

      Issue 683 in pdfium: FPDFText_GetRect returns rects that have some offset (google.com)

      as it says:
      FPDF_GetPageWidth and FPDF_GetPageHeight only measure the displayable area. 

      so these codes in qpdfdocument.cpp:

       

      QPdfSelection QPdfDocument::getAllText(int page)
      {
          const QPdfMutexLocker lock;
          FPDF_PAGE pdfPage = FPDF_LoadPage(d->doc, page);
          double pageHeight = FPDF_GetPageHeight(pdfPage);
          FPDF_TEXTPAGE textPage = FPDFText_LoadPage(pdfPage);
          int count = FPDFText_CountChars(textPage);
          if (count < 1)
              return QPdfSelection();
          QString text = d->getText(textPage, 0, count);
          QList<QPolygonF> bounds;
          QRectF hull;
          int rectCount = FPDFText_CountRects(textPage, 0, count);
          for (int i = 0; i < rectCount; ++i) {
              double l, r, b, t;
              FPDFText_GetRect(textPage, i, &l, &t, &r, &b);
              QRectF rect(l, pageHeight - t, r - l, t - b);
              if (hull.isNull())
                  hull = rect;
              else
                  hull = hull.united(rect);
              bounds << QPolygonF(rect);
          }
          qCDebug(qLcDoc) << "on page" << page << "got" << count << "chars," << rectCount << "rects within" << hull;    FPDFText_ClosePage(textPage);
          FPDF_ClosePage(pdfPage);    return QPdfSelection(text, bounds, hull, 0, count);
      }
      
      

      probably wrong. It should use  FPDF_PageToDevice to transforming coordinates. I will try this function and reply here later.

       

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-106565
          # Subject Branch Project Status CR V

          Activity

            People

              srutledg Shawn Rutledge
              zhaohongjian000 zhao hongjian
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: