Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

open pdf from pyqt in the same folder

import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *


if __name__ == '__main__':
    app = QApplication(sys.argv)
    w = QLabel()
    path = r"C:UsersShauryaDocumentsTo be savedhello.pdf"
    # or
    # path = QDir.home().filePath(r"DocumentsTo be savedhello.pdf")
    # or
    # path = QDir(QStandardPaths.writableLocation(QStandardPaths.DocumentsLocation)).filePath(r"To be savedhello.pdf")
    url = bytearray(QUrl.fromLocalFile(path).toEncoded()).decode() # file:///C:/Users/Shaurya/Documents/To%20be%20saved/hello.pdf
    text = "<a href={}>Reference Link> </a>".format(url)
    w.setText(text)
    w.setOpenExternalLinks(True)
    w.show()
    sys.exit(app.exec_())
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #open #pdf #pyqt #folder
ADD COMMENT
Topic
Name
1+1 =