Results 1 to 4 of 4

Thread: QWebView prints PDF file OK with QPrintDialog only

  1. #1
    Join Date
    Feb 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QWebView prints PDF file OK with QPrintDialog only

    Hi

    I have a small application where I create a report in HTML format that must be shown, print to printer or saved to a PDF file.
    I could save the HTML report file as a PDF file if I use the QPrintDialog input and select the PDF output but I could not print PDF using only QPrinter and setting QPrinter properties myself in the code. Why is that?

    Qt Code:
    1. QWebView *web = new QWebView();
    2. web->load(QUrl(fileHTMLReport));
    3. QPrinter printer;
    4. QPrintDialog *dialog = new QPrintDialog(&printer);
    5. if ( dialog->exec() == QDialog::Accepted)
    6. web->print(&printer);
    To copy to clipboard, switch view to plain text mode 

    So above if I select PDF output into QPrintDialog window I could save fileHTMLReport in PDF format but if I try to do it without using QPrintDialog by setting only the QPrinter parameters result in an empty PDF file?

    Qt Code:
    1. QWebView *web = new QWebView();
    2. web->load(QUrl(fileHTMLReport));
    3. QPrinter printer;
    4. printer.setPrinterName("Print to File (PDF)");
    5. printer.setOutputFormat(QPrinter::PdfFormat);
    6. printer.setPrintRange(QPrinter::AllPages);
    7. printer.setOrientation(QPrinter::Portrait);
    8. printer.setPaperSize(QPrinter::A4);
    9. printer.setResolution(QPrinter::HighResolution);
    10. printer.setFullPage(false);
    11. printer.setNumCopies(1);
    12. printer.setOutputFileName("printYou.pdf");
    13. web->print(&printer);
    To copy to clipboard, switch view to plain text mode 

    result in "printYou.pdf" file being empty and not showing "fileHTMLReport" file as when printing is done through QPrintDialog interface call?

    What do I miss here?

    Sorin
    Last edited by wysota; 26th November 2009 at 09:55. Reason: missing [code] tags

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

    Default Re: QWebView prints PDF file OK with QPrintDialog only

    I would say you forget to set some parameter in your code which is responsible for scaling the painter or something like that. It might be easiest if you looked into source code for QPrintDialog to see what exactly gets set by it.
    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
    Dec 2009
    Posts
    41
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QWebView prints PDF file OK with QPrintDialog only

    Hi !

    I have exactly the same problem here. Have you found a solution ?

  4. #4
    Join Date
    Dec 2009
    Posts
    41
    Thanks
    6
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QWebView prints PDF file OK with QPrintDialog only

    Hi !

    I am here to answer to my problem it could be useful for someone. In fact I just had to connect the loadFinished signal of the QWebView to a method to print. In my code the printing was launched before the end of the page loading which gave me a blank page

Similar Threads

  1. Can Qwebview load xml/xsl file?
    By richardander in forum Qt Programming
    Replies: 3
    Last Post: 26th August 2015, 22:36
  2. QWebView -> load Default Splash Screen from .qrc File
    By RacePhase in forum Qt Programming
    Replies: 0
    Last Post: 26th June 2009, 14:14
  3. How to save a Qwebview as an html file
    By richardander in forum Qt Programming
    Replies: 2
    Last Post: 5th June 2009, 00:07
  4. How to display xml file in qwebview?
    By richardander in forum Qt Programming
    Replies: 2
    Last Post: 31st May 2009, 21:10
  5. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21

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.