其他分享
首页 > 其他分享> > pyqt5加载pdf文档失败

pyqt5加载pdf文档失败

作者:互联网

import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog
from PyPDF2 import PdfFileReader, PdfFileWriter
from main_form import *


class MyWindow(QMainWindow, Ui_MainWindow):
    def __init__(self, parent=None):
        super(MyWindow, self).__init__(parent)
        self.setupUi(self)
        self.actionLoad_File_L.triggered.connect(self.showDialog)

    def showDialog(self):
        infn = QFileDialog.getOpenFileName(self,
                                            'Open file',
                                            'd:')

        with open(infn, 'rb') as f:
            pdf = PdfFileReader(f)
            info = pdf.getDocumentInfo()
            number_of_pages = pdf.getNumPages()

        print(info, number_of_pages)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    win = MyWindow()
    win.show()
    sys.exit(app.exec_())

标签:__,self,pyqt5,sys,import,pdf,MyWindow,加载
来源: https://www.cnblogs.com/asworm/p/11287188.html