Results 1 to 6 of 6

Thread: QPainter does not print html file as expected, ideas workarounds?

  1. #1
    Join Date
    Oct 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QPainter does not print html file as expected, ideas workarounds?

    Hi, I used the snipet provided by this thread to print a html file, however, I have a nasty html file, with tables, and styles inside the table, and stuff like that:

    Qt Code:
    1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    2.  
    3. <html xmlns="http://www.w3.org/1999/xhtml">
    4. <HEAD>
    5. <meta name="tipo_contenido" content="text/html;" http-equiv="content-type" charset="utf-8">
    6. </HEAD>
    7. <table border="1" cellspacing="0" cellpadding="0" width="100%" style="font-size:12px;line-height:20px;">
    8. <tbody>
    9. <tr>
    10. <td valign="middle" align="left" width="40%" height="30">
    11. Nombre:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>
    12. Razon social:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>
    13. </td>
    14. <td valign="middle" align="left" width="20%" size="80">
    15. <span style="font-size:8em;">&nbsp;</span>
    16. </td>
    17.  
    18. <td valign="middle" align="left" width="40%" height="120">
    19. Nro Comprobante: <br/>
    20. Fecha y hora:<br/>
    21. </td>
    22.  
    23. </tr>
    24. <tr>
    25. <td valign="TOP" colspan="2">
    26. Domicilio comercial:<br/>
    27. Domicilio Fiscal:<br/>
    28. Iva: <br/>
    29. </td>
    30. <td valign="TOP" align="left" colspan="1">
    31. Cuit: <br/>
    32. Ing Brutos: <br/>
    33. Inicio Actividades:<br/>
    34. </td>
    35. </tr>
    36. <tr>
    37. <td valign="middle" colspan="4" height="">
    38. Identificacion:<br/>
    39. Senior(es): <br/>
    40. Domicilio: <br/>
    41. Iva: <br/>
    42. Cuit: <br/>
    43. </td>
    44. </tr>
    45. </tbody>
    46. </table>
    47. <table border="1" RULES=COLS cellspacing="1" cellpadding="4" width="100%">
    48. <tr>
    49. <td width="96" align="right" height="22" align="middle" style="font-size:12px">NETO</td>
    50. <td width="96" align="right" height="22" align="middle" style="font-size:12px">IVA FACT</td>
    51. <td width="96" align="right" height="22" align="middle" style="font-size:12px">IVA SOB</td>
    52. <td width="96" align="right" height="22" align="middle" style="font-size:12px">IVA 21%</td>
    53. <td width="96" align="right" height="22" align="middle" style="font-size:12px">IVA 27%</td>
    54. <td width="96" align="right" height="22" align="middle" style="font-size:12px">IVA 10.5%</td>
    55. <td width="96" align="right" height="22" align="middle" style="font-size:12px">TOTAL</td>
    56. </tr>
    57. </table>
    58. </html>
    To copy to clipboard, switch view to plain text mode 

    However Qt print it very different as how Chrome, firefox and IE do it... any idea or workaround? thanks!

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

    Default Re: QPainter does not print html file as expected, ideas workarounds?

    Define "very different"...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QPainter does not print html file as expected, ideas workarounds?

    You are lucky it does anything at all. That "HTML" contains no <body></body> and is absolutely nothing like the XHTML it claims to be.

    Have you tried feeding that mess through QtWebKit?

  4. #4
    Join Date
    Oct 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPainter does not print html file as expected, ideas workarounds?

    No, I didn't try it, I was hoping that "setHtml" would have the same effect as feeding that html to a webKit Browser, but it didn't, chrome display that POS very nice, also, I have no clue on how to use QtWebKit to print an html file, any snipet? thanks

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QPainter does not print html file as expected, ideas workarounds?

    You couldn't search for "print" in the manual?
    Qt Code:
    1. QPrinter *printer;
    2. // set up printer
    3.  
    4. QWebView v;
    5. v.setHtml(html);
    6. v.show();
    7. v.print(printer);
    8.  
    9. // or without the view widget
    10. QWebPage page;
    11. page.mainFrame()->setHtml(html);
    12. page.mainFrame()->print(printer);
    To copy to clipboard, switch view to plain text mode 

    QTextDocument has a limited range of allowable HTML and does not cater for the huge range of malformed HTML in the wild. The browser components do, but they are much heavier components.
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

  6. #6
    Join Date
    Oct 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPainter does not print html file as expected, ideas workarounds?

    Quote Originally Posted by ChrisW67 View Post
    You couldn't search for "print" in the manual?
    Qt Code:
    1. QPrinter *printer;
    2. // set up printer
    3.  
    4. QWebView v;
    5. v.setHtml(html);
    6. v.show();
    7. v.print(printer);
    8.  
    9. // or without the view widget
    10. QWebPage page;
    11. page.mainFrame()->setHtml(html);
    12. page.mainFrame()->print(printer);
    To copy to clipboard, switch view to plain text mode 

    QTextDocument has a limited range of allowable HTML and does not cater for the huge range of malformed HTML in the wild. The browser components do, but they are much heavier components.
    Right, QWebPage could handle that monstruosity pretty well, thanks a lot!

Similar Threads

  1. Suggestions/Ideas about a file browser
    By SkripT in forum Qt Programming
    Replies: 31
    Last Post: 6th April 2011, 23:17
  2. how to print an html file?
    By patcito in forum Qt Programming
    Replies: 5
    Last Post: 31st August 2008, 16:50
  3. Replies: 4
    Last Post: 18th December 2007, 08:31
  4. Print html on fixed size
    By mamyte03@gmail.com in forum Qt Programming
    Replies: 1
    Last Post: 19th September 2007, 10:33
  5. 2 questions on QPainter and html
    By jiveaxe in forum Qt Programming
    Replies: 3
    Last Post: 4th September 2007, 11:30

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.