Pyqt6 auf PDF speichernPython

Python-Programme
Anonymous
 Pyqt6 auf PDF speichern

Post by Anonymous »

Ich versuche, ein PYQT6 -Fenster in eine PDF -Datei zu drucken. Es funktioniert, aber das Fenster scheint in der oberen linken Ecke der PDF -Seite sehr klein zu sein. Wie löste ich es?

Code: Select all

def save_to_pdf(self):
"""Save the display window as a PDF."""
# Create a QPrinter object
printer = QPrinter(QPrinter.PrinterMode.HighResolution)
printer.setOutputFormat(QPrinter.OutputFormat.PdfFormat)

# Ask the user for a file name and location to save the PDF
file_dialog = QFileDialog(self)
file_dialog.setAcceptMode(QFileDialog.AcceptMode.AcceptSave)
file_dialog.setNameFilter("PDF Files (*.pdf)")
file_dialog.setDefaultSuffix("pdf")
file_dialog.setWindowTitle("Save as PDF")
if file_dialog.exec():
file_name = file_dialog.selectedFiles()[0]
printer.setOutputFileName(file_name)

# Create a painter to render the content
from PyQt6.QtGui import QPainter
painter = QPainter(printer)

# Render the window onto the painter
self.render(painter)
painter.end()

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post