Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-2881

QPdfDocument.getSelection(...) always returning empty QPdfSelection

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • Not Evaluated
    • None
    • 6.7.3
    • PySide
    • Windows, Running python 3.12.5 and PySide6 version 6.7.3. No virtual env.
    • Windows

    Description

      I'm unable to retrieve any text from PDF files using the .getSelection() method from QPdfDocument. The QPdfSelection returned is always empty for me (that is: It has an empty .text() and empty boundingRectangle), no matter what I chose as start and end point. Am I doing something wrong? Other methods like getAllText() or getSelectionAtIndex() work fine, so I guess it's not the fault of the pdf files I've tried or a general mistake in creating the QPdfDocument...
       
      Here is some minimal example. I've not found any pdf that works, so I've not included any example pdf - the error seemed to be generic.
       
      from PySide6.QtCore import QPointF
      from PySide6.QtPdf import QPdfDocument

      doc = QPdfDocument(None)
      doc.load(r"path-to-some.pdf")
      page = 10

      print("############### get all ###############")
      all = doc.getAllText(page)
      print(all.text())  # this works just fine
      print(all.boundingRectangle())

      print("############### getSelection ###############")
      selection = doc.getSelection(page, QPointF(11, 49), QPointF(537, 705))
      print(selection.text())  # this is always empty
      print(selection)

      Attachments

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

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            patschke Patrick Mischke
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes