PDA

View Full Version : PDF Printer doesn't use font size



gruszczy
18th February 2009, 16:25
I am trying to export data from QTextEdit. I am taking QTextDocument and use QPrinter with Pdf format. It prints right, keeps bold and underline formatting, but font is very small and doesn't use font settings from the text edit. The font size formatting is definitely there, because when I export source html, the formatting is all right. What I am doing wrong? The code looks like this:



path = str(QFileDialog.getSaveFileName(None, "Get export file name", \
'Untitled.pdf', "*.pdf", \
'Untitled.pdf'))
if path == '':
return
if not path.endswith('.pdf'):
path += '.pdf'
printer = QPrinter(QPrinter.HighResolution)
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setOutputFileName(path)
printer.setPaperSize(QPrinter.A4)
self.document().print_(printer)

seneca
18th February 2009, 16:51
Qt handles font sizes as dots, which are very small on high resolution printers compared to screen. Of course it would be more convenient if Qt would allways interpret font sizes as typographic points (1/72 inch), instead of device dots - but thats the way it is designed currently and what we must live with.

My workaround to get printed fonts sizes appear equal to screen was to scale up by the factor printer resolution/screen resolution.

If only printing text, a quick fix is to use QPrinter::ScreenResolution instead of HighResolution.

gruszczy
18th February 2009, 20:04
Well, this works, but the fonts aren't smooth now and look very ugly.

Do you know any examples of code, which could be used do print the way you describe, in high resolution?

wysota
19th February 2009, 02:17
Have you tried setting a font with a pixel size instead of point size?

gruszczy
3rd March 2009, 21:39
Have you tried setting a font with a pixel size instead of point size?

I tried doing that and it did change it's size. But it was from extremely small to very small, when I hit pixel size 60 - it was max I think, because making it even bigger didn't help. Could anyone point me to a code snippet doing some good pdf export?