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:

Qt Code:
  1. setupdialog = QPrintDialog()
  2. if setupdialog.exec() == QPrintDialog.Accepted:
  3. printer = setupdialog.printer()
  4. 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:
Qt Code:
  1. printer.setPageMargins(0.1, 0.1, 0.1, 0.1, QPrinter.Millimeter) #left top right bottom
  2. printer.setFullPage(True)
  3. printer.setPageMargins(QPrinter.Millimeter)
  4. printer.setPageRect(QPrinter.Millimeter)
  5. printer.setPaperRect(QPrinter.Millimeter)
  6. printer.setPageSizeMM()
  7. printer.setResolution()
  8. printer.setPaperName()
  9. textReport.setContentsMargins(0, 0, 0, 0)
  10. 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