Results 1 to 5 of 5

Thread: PDF Printer doesn't use font size

  1. #1
    Join Date
    Feb 2008
    Posts
    40
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default PDF Printer doesn't use font size

    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:

    Qt Code:
    1. path = str(QFileDialog.getSaveFileName(None, "Get export file name", \
    2. 'Untitled.pdf', "*.pdf", \
    3. 'Untitled.pdf'))
    4. if path == '':
    5. return
    6. if not path.endswith('.pdf'):
    7. path += '.pdf'
    8. printer = QPrinter(QPrinter.HighResolution)
    9. printer.setOutputFormat(QPrinter.PdfFormat)
    10. printer.setOutputFileName(path)
    11. printer.setPaperSize(QPrinter.A4)
    12. self.document().print_(printer)
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Posts
    132
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: PDF Printer doesn't use font size

    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.
    Last edited by seneca; 18th February 2009 at 16:35.

  3. The following user says thank you to seneca for this useful post:

    gruszczy (18th February 2009)

  4. #3
    Join Date
    Feb 2008
    Posts
    40
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: PDF Printer doesn't use font size

    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?

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: PDF Printer doesn't use font size

    Have you tried setting a font with a pixel size instead of point size?

  6. #5
    Join Date
    Feb 2008
    Posts
    40
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: PDF Printer doesn't use font size

    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?

Similar Threads

  1. Replies: 1
    Last Post: 2nd August 2008, 15:46
  2. Font size of a spinbox
    By SailinShoes in forum Qt Programming
    Replies: 6
    Last Post: 5th May 2008, 14:29
  3. Font size calculation when painting in a QImage
    By Ishark in forum Qt Programming
    Replies: 3
    Last Post: 15th July 2007, 22:22
  4. Replies: 3
    Last Post: 30th January 2007, 07:35
  5. QTreeView font size not being set
    By forrestfsu in forum Qt Tools
    Replies: 2
    Last Post: 12th October 2006, 13:53

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.