I am trying to print an image file on printer using QWebview but instead of image blank page is printed. Please find the below code.
void ChartViewer::onprintBtnClicked()
{
QString fileName = QFileDialog::getOpenFileName(this,"Open File",QString(),"Pdf File(*.png)");
qDebug()<<"Print file name is "<<fileName;
if(fileName.endsWith(".png"))
{
QPrinter printer;
QWebView *view = new QWebView;
QPrintDialog *dlg = new QPrintDialog(&printer,this);
printer.setOutputFileName(fileName);
if(dlg->exec() != QDialog::Accepted)
return;
view->load(fileName);
view->print(&printer);
}
}
If I use view->show() then it has shown the image properly but printed page is coming blank. Request you to please look into the above code and correct me where I am doing wrong.
Regards,
Lekhraj
You load some png file into fileName. Then you set
QPrinterto print to that png file withprinter.setOutputFileName(fileName);.I suppose it is wrong, it should be some different pdf file probably.I’m not sure if I understand what are you trying to do? How to print image file using QPrinter? Into pdf file? Why are trying to use QWebView?
You can use QImage to load image file and then paint with QPainter on QPrinter.
Some of your issues may overlap with your other question
https://stackoverflow.com/questions/8297239/how-to-print-pdf-file-in-qt