【问题标题】:QPrinter PDF output is tinyQPrinter PDF 输出很小
【发布时间】:2021-09-28 01:12:35
【问题描述】:

我在 PYQT5 Designer 中设置了一个页面,当在屏幕上正常打开时它看起来很棒,所以我尝试保存为 PDF。

from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtWidgets import QApplication, QFileDialog, QWidget, QMainWindow, QComboBox, 
from PyQt5.QtPrintSupport import QPrinter

from export_pdf_ui import *
import sys


class MainWindow(QMainWindow):
    def __init__(self, *args, **kwargs):
        super(MainWindow, self).__init__(*args,**kwargs)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.export()
    def export(self):
        printer = QPrinter(QPrinter.HighResolution)
        printer.setOutputFormat(QPrinter.PdfFormat)
        printer.setOutputFileName("test.pdf")
        printer.setPaperSize(QPrinter.A4)
        printer.setPageSize(QPrinter.A4)
        printer.setFullPage(True)
        self.ui.centralwidget.render(printer)


app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec_()

它工作正常并输出PDF文件,但内容很小而且在角落里,即使完全放大也无法真正阅读。如何让它填满整个页面?还是设计问题?在屏幕上看起来不错

【问题讨论】:

    标签: python pyqt5


    【解决方案1】:

    尝试使用 QPrinter::ScreenResolution 而不是 QPrinter.HighResolution 创建打印机。

    我在将 QTextDocument 打印到使用 QPrinter::HighResolution 创建的物理打印机时遇到了类似的问题。如果我调用 QTextDocument::setPageSize 来消除页码,那么纸上的输出将是大约 50 毫米宽。我不知道您是否遇到了同样的问题,但对我来说,我的最后一个难题是我创建 QPrinter 对象时使用的分辨率。

    【讨论】:

      猜你喜欢
      • 2015-07-05
      • 2017-03-28
      • 1970-01-01
      • 2016-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-10
      • 1970-01-01
      相关资源
      最近更新 更多