Python Forum
[PyQt] Saving file to html or pdf stopped working in PyQt6
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Saving file to html or pdf stopped working in PyQt6
#3
(Mar-12-2024, 03:28 PM)deanhystad Wrote: Why not this?
def export_html1(self, tableV, file_path):
    with open(file_path, "w") as file:
        file.write(self.formHTML(tableV))

Thank you, this worked for html. Apparently i went too far with Qt way on this one. Right now looking for some other way to create pdf...


Ok, i've found the problem. I don't know how to control Margins but at least without them it works:

    def export_pdf(self, tableV, file_path):
        html = self.formHTML(tableV)

        document = QTextDocument()
        document.setHtml(html)

        printer = QPrinter(QPrinter.PrinterMode.HighResolution)
        printer.setOutputFormat(QPrinter.OutputFormat.PdfFormat)
        printer.setOutputFileName(file_path)
        printer.setPageSize(QPageSize(QPageSize.PageSizeId.A4))

        document.print(printer)
Reply


Messages In This Thread
RE: Saving file to html or pdf stopped working in PyQt6 - by ejKDE - Mar-12-2024, 05:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] Tutorial bug with PyQt6 canvas Mike88 5 1,371 Jan-02-2025, 10:37 PM
Last Post: Mike88
  [PyQt] [solved] How to display a pdf-file in a PyQt6 widget BigMan 13 26,281 May-06-2023, 09:27 AM
Last Post: Axel_Erfurt
  event driven coding PyQt6 on Combobox change merrittr 3 4,541 May-03-2023, 03:35 AM
Last Post: merrittr
Question [PyQt] Application desktop toolbar with PyQt6 bunz 4 3,045 Mar-09-2023, 08:09 PM
Last Post: bunz
  PyQt6 QAction with icon and string malonn 2 3,296 Sep-12-2022, 11:59 AM
Last Post: malonn
  [PyQt] Embed Google Maps in PyQt6 Widget Raures 2 4,421 Sep-11-2021, 04:32 PM
Last Post: Raures
  [Tkinter] logical error - saving file rwahdan 4 3,490 Jul-01-2021, 12:59 PM
Last Post: rwahdan
  [PyQt] saving text file by FileDialog option atlass218 14 7,334 Feb-19-2020, 09:22 AM
Last Post: atlass218
  Part of code is adding extra new line when saving to text file. lovepeace 9 8,459 Aug-24-2019, 12:52 PM
Last Post: lovepeace
  [PyQt5] [QWebEngineView] HTML file download nolme 0 6,047 May-08-2018, 08:41 PM
Last Post: nolme

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020