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: Unresolved
    • P3: Somewhat important
    • None
    • 6.3.0, 6.3.1, 6.3.2
    • PDF
    • None
    • All

    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

          Activity

            People

              srutledg Shawn Rutledge
              zhaohongjian000 zhao hongjian
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: