Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. Scale's problem while printing
Forum Updated to NodeBB v4.3 + New Features

Scale's problem while printing

Scheduled Pinned Locked Moved Qt WebKit
2 Posts 1 Posters 2.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lery
    wrote on last edited by
    #1

    Hi,

    I have a strange problem when trying to print to PDF : when I'm printing to a real printer, no problem, when I print to pdf printer using the QPrintDialog, no problem either...

    But when I'm trying to print directly to PDF using :

    @void pdfPrint()
    {
    QPrinter pdfprinter(QPrinter::ScreenResolution);
    pdfprinter.setPageSize(QPrinter::A4);
    pdfprinter.setPaperSize(QSizeF(595,842),QPrinter::Point);
    pdfprinter.setOutputFormat(QPrinter::PdfFormat);
    QString Filename= QFileDialog::getSaveFileName(0, "Export as PDF",QString(), "*.pdf");

    if (!Filename.isEmpty()) {
        if (QFileInfo(Filename).suffix().isEmpty())
        Filename.append(".pdf");
    }
    pdfprinter.setOutputFileName(Filename);
    
    MyWebView->print(&printer);
    

    }@
    it's printing fine... But it's scaling down to an A6 page size !!! So it only prints on a quarter of my page and I get a PDF with everything printed fine but scaled down to the upper left quarter of the page.
    I would like my page to be an entire A4 page.
    Any hint ??? I was thinking about some DPI problem, but wasn't able to figure out how to correct it. (Already tried to change printer's resolution and everything...)

    I also tried to find a workaround using QPainter, which works fine printing with the right scaling, but isn't able to print the entire page, since I have to scroll to see the bottom part...
    @QPainter painter(&pdfprinter);
    maVue->render(&painter, maVue->pos(), QWidget::rect());@

    1 Reply Last reply
    0
    • L Offline
      L Offline
      Lery
      wrote on last edited by VRonin
      #2

      So I solved my problem using some ugly workaround, for those who have the same problem, here is my way out :

              QPainter q(&pdfprinter);
              q.setRenderHint(QPainter::HighQualityAntialiasing, true);
              QWebView* tempp = new QWebView(this);
              tempp->setHtml(maVue->page()->mainFrame()->toHtml());
              tempp->show();
      
              q.scale(11,10.9);
      
              tempp->setGeometry(QRect(QPoint(0,0),QSize(9920, 28066)));
              tempp->page()->mainFrame()->render(&q,QRect(QPoint(0,0),QSize(9920, 28066)));
      
              delete tempp;
      

      The problem now is that the quality is pretty bad... (Since I've got to magnify it 10 times to get it to the size of my page...)

      And yes, I do need a temporary QWebView for it because I can't setGeometry on my main QWebView and because I want my whole page to be displayed, not only the part displayed by my main QWebView...

      If anyone as a better solution, please, feel free to contribute.
      I won't research it further but would be happy to get a better way to do it.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved