Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to close the Pdf file while closing the application?



  • I have a pyqt5 application in which I have opened a pdf now when the user exits the application pdf should also close.
    I have tried the following

          destinationTemp = QDir.fromNativeSeparators(path)
          if os.path.exists(destinationTemp + fileName + ".pdf"):
             os.remove(destinationTemp + fileName + ".pdf")
          QFile.copy(":/newPrefix/sample.pdf", destinationTemp + 
           fileName + ".pdf")
            
         QDesktopServices.openUrl(QUrl.fromLocalFile(" destinationTemp + 
         
                    fileName + ".pdf"))

  • Lifetime Qt Champion

    Hi
    Well you ask the OS to open any app that is tied to the extension pdf.
    Its not really possible to ask it to close without using platform native api calls
    to find this window and try to close it.

    You could use
    https://doc.qt.io/qt-5/qtpdf-index.html
    to display the pdf yourself and hence be able to close the pdf view.


Log in to reply