Hi,
I have a QTextEdit filled with just HTML and I want to print it (either to any print or as PDF). However, the output file always shows way too much margins or borders and I want to remove them.

This is my PyQt5 Code:
printer = setupdialog.printer()
textReport.print(printer)
setupdialog = QPrintDialog()
if setupdialog.exec() == QPrintDialog.Accepted:
printer = setupdialog.printer()
textReport.print(printer)
To copy to clipboard, switch view to plain text mode
textReport is a QtextEdit() created with Qt Creator for a .ui file (I can control how the html looks like inside the QtextEdit that way and I can guarantee it show no margins at all in Qt Creator Design mode).
I've also tried all of this options separately:
printer.
setPageMargins(0.1,
0.1,
0.1,
0.1,
QPrinter.
Millimeter) #left top right bottomprinter.setFullPage(True)
printer.
setPageMargins(QPrinter.
Millimeter)printer.
setPageRect(QPrinter.
Millimeter)printer.
setPaperRect(QPrinter.
Millimeter)printer.setPageSizeMM()
printer.setResolution()
printer.setPaperName()
textReport.setContentsMargins(0, 0, 0, 0)
printer.setPageMargins(0.1, 0.1, 0.1, 0.1, QPrinter.Millimeter) #left top right bottom
printer.setFullPage(True)
printer.setPageMargins(QPrinter.Millimeter)
printer.setPageRect(QPrinter.Millimeter)
printer.setPaperRect(QPrinter.Millimeter)
printer.setPageSizeMM()
printer.setResolution()
printer.setPaperName()
textReport.setContentsMargins(0, 0, 0, 0)
QTextDocument.setIndentWidth()
To copy to clipboard, switch view to plain text mode
I also tried to use a QtextDocument instead. No luck so far. Any insight?
Note: This attempt is the result of a research trying to print a Widget to PDF as you can check here: https://stackoverflow.com/questions/...and-python-3-5
Bookmarks