Results 1 to 4 of 4

Thread: QWebView prints PDF file OK with QPrintDialog only

Threaded View

Previous Post Previous Post   Next Post Next Post
  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 10:55. Reason: missing [code] tags

Similar Threads

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