[Python] There is an issue exporting the GUI I designed into a PDF

Discussão em 'Python' iniciado por Stack, Maio 6, 2025.

  1. Stack

    Stack Membro Participativo

    I designed a GUI using QtDesigner and I am running it through Visual Studio Code. After clicking the "Save As" button, I want to export an exact copy of this designed GUI as a PDF. However, I haven't been able to do this properly.

    The data on the GUI goes up to line 89, but when exporting to PDF, it gets cut off around line 23. Also, I would like to enable a vertical scroll bar in the PDF output so that all the data can be seen up to the last line (line 89).

    I would really appreciate your help with this.

    The following figure is my GUI. Also, I am adding the code snippet related to issue.

    enter image description here

    def save_main_window_As_pdf(main_window):
    printer = QPrinter(QPrinter.ScreenResolution)
    printer.setOutputFormat(QPrinter.PdfFormat)
    printer.setOutputFileName("main_window_output.pdf")

    main_window_size = main_window.size()
    printer.setPaperSize(QSizeF(main_window_size), QPrinter.DevicePixel)
    painter = QPainter()
    if not painter.begin(printer):
    print("printing PDF could not start.")
    return

    main_window.render(painter)
    painter.end()
    print("generating PDF has been successful: main_window_output.pdf")

    Continue reading...

Compartilhe esta Página