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

search for text strings in PDF



    • Type: Task
    • Status: Closed
    • Priority: P1: Critical
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: PDF
    • Labels:


      PDFium API provides FPDFText_LoadPage to get a model representing the text on a page, FPDFText_FindStart to start searching, FPDFText_FindNext, and more functions to find the rectangular area from the character index where the matching text begins to where it ends. So the easiest feature we can add is to be able to search the current page in the kind of PDF viewer that only shows one page at a time.

      https://codereview.qt-project.org/c/qt/qtdeclarative/+/260751 allows rendering sequences of polygons using QtQuick.Shapes. So it's possible for some sort of search model to provide them, and then render them all with one Item, as translucent rectangles on top of the page, or as rectangles under the text as long as the page background is transparent. In practice though, PDFs can have opaque backgrounds, so it seems necessary to put the highlighting on top.

      Going beyond that, it might be better to provide a way of iterating through all matches on all pages, and populating a ListView with them, such that clicking on a row in the list will jump to the page (or area of a page) where the match is found. Other PDF readers (such as Preview on macOS) do it that way. But this needs to be done in an incremental way, populating more matches as the user scrolls through the list, or populating them in a background thread, in case the document is long. We should assume it's too expensive to iterate every page and populate the search results all at once. It's not clear yet whether current customers need the multi-page search, but we should design it in a way that adding that feature will be possible.

      Current customers do want to be able to build multi-page PDF viewers though. So far I have a prototype using ListView. It should be possible to search for text on all visible pages in that case, at least.

      Current customers are using Qt Quick. But it would be good to add the search feature to the widget-based example too, somehow.


          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.



              srutledg Shawn Rutledge
              srutledg Shawn Rutledge
              0 Vote for this issue
              1 Start watching this issue



                  Gerrit Reviews

                  There are no open Gerrit changes