从 QtextEdit pyside2 导出 pdf打印按钮有效,但 pdf 没有保存在我的电脑中,它是空白的

问题描述

import sys
import platform
from PySide2 import QtCore,QtGui,QtWidgets
from PySide2.QtCore import (QCoreApplication,QPropertyAnimation,QDate,QDateTime,QMetaObject,QPoint,QRect,QSize,QTime,QUrl,QEvent)
from PySide2.QtGui import (QBrush,QColor,QConicalGradient,QCursor,QFont,QFontDatabase,QIcon,QKeySequence,QLinearGradient,QPainter,QPixmap,QRadialGradient)
from PySide2.QtWidgets import *
from PySide2.QtCore import QFileInfo
from PySide2.QtPrintSupport import QPrinter

from ui_interface import Ui_MainWindow


class MainWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.start_btn.clicked.connect(lambda: self.ui.textEdit.setText("Hello World"))
        self.ui.printbutton.clicked.connect(lambda: self.SavetoPDF())
        self.show()

    def SavetoPDF(self):
        filename = QFileDialog.getSaveFileName(self,'Save to PDF',None,'PDF files(.pdf);; All Files')
        if filename != "":
            if QFileInfo(filename).suffix() == "": filename += '.pdf'
            printer = QPrinter(QPrinter.HighResolution)
            printer.setOutputFormat(QPrinter.PdfFormat)
            printer.setOutputFileName(filename)
            print(self.ui.textEdit.document())


if __name__ == '__main__':
    app = QApplication(sys.argv)`
    window = MainWindow()
    sys.exit(app.exec_())   

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...