Hello,
What I'm trying to do - print a PDF with my app logo, a chart (widget or image of the widget - any of those will do it) and the results - the chart is a container widget, I'm using QCustomPlot.
What I'm doing right now - I'm writing a html and saving it as PDF.
The problems:
1 - I don't know how to insert images from my resources into the doc (solved);
2 - I don't know how to insert the chart (or a screenshot of the chart) into the doc;
3 - (minor problem) I need to remove the page number.
Here's the code I have so far:
doc.setHtml(
"<h1 align='center'>App Title</h1><br>"
"<img src='path_to_applogo/applogo.png'>"
+ui->result_R->text()
);
printer.setOutputFileName(filename);
printer.
setOutputFormat(QPrinter::PdfFormat);
doc.print(&printer);
QTextDocument doc;
doc.setHtml(
"<h1 align='center'>App Title</h1><br>"
"<img src='path_to_applogo/applogo.png'>"
+ui->result_R->text()
);
QPrinter printer(QPrinter::HighResolution);
printer.setOutputFileName(filename);
printer.setOutputFormat(QPrinter::PdfFormat);
doc.print(&printer);
To copy to clipboard, switch view to plain text mode
As you can see, I'm using an image from the user's computer, and not an image from the app's resources.
Also, I don't know how to insert the chart or a screenshot of the chart into the html code, since the code will only accept strings.
Thanks in advance.
Problem 1 solved - After some more researching I found out i need to use the URL like this:
"<p align='center'><img src=':/images/applogo.png'></p>"
"<p align='center'><img src=':/images/applogo.png'></p>"
To copy to clipboard, switch view to plain text mode
Bookmarks