[Python] Not able to get selection of PDF document

Discussão em 'Python' iniciado por Stack, Agosto 28, 2025.

  1. Stack

    Stack Membro Participativo

    With PySide6 when using getAllText I get a valid QPdfSelection.

    from PySide6.QtPdf import QPdfDocument, QPdfSelection
    from PySide6.QtCore import QPointF
    from PySide6.QtPdfWidgets import QPdfView

    pdf_view: QPdfView = main_window.ui.pdfView
    document: QPdfDocument = pdf_view.document()
    current_page: int = pdf_view.pageNavigator().currentPage()

    selection: QPdfSelection = document.getAllText(current_page)
    print(selection.isValid())
    # True
    print(selection.boundingRectangle())
    # PySide6.QtCore.QRectF(73.000000, 118.000000, 450.000000, 682.000000)
    print(selection.text())
    # some text ...


    But when trying to use getSelection (even with the QPointFs of the boundingRectagle above) I get an invalid selection with a QRectF with all its values set to 0.

    top_left: QPointF = selection.boundingRectangle().topLeft()
    bottom_right: QPointF = selection.boundingRectangle().bottomRight()

    selection: QPdfSelection = document.getSelection(current_page, top_left, bottom_right)
    print(selection.isValid())
    # False
    print(selection.boundingRectangle())
    # False PySide6.QtCore.QRectF(0.000000, 0.000000, 0.000000, 0.000000)


    What do I'm missing?

    Continue reading...

Compartilhe esta Página