Problem with image in PDF using QTextDocument.
-
I'm using QTextDocument to print PDF file from HTML. But, the image was broken in the PDF file.
This is HTML syntax:
@<html><head></head><body><img src="file:///home/user/Pictures/avatar.jpg"></body></html>@And my Qt/C++ code is:
@QPrinter printer;
printer.setOrientation(QPrinter::Portrait);
printer.setPaperSize(QPrinter::A4);
printer.setResolution(300);
printer.setFullPage(true);
printer.setCopyCount(1);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(location);QTextDocument document;
document.setHtml(htmlText);
document.print(&printer);@How can I fix this?
-
Try using Portable Network Graphics (.png) instead of JPEGs. I had several problems with JPEGs, too, and using PNGs fixed the problem.
To convert your image, you could use any image manipulation program (e.g. GIMP), load the image and export it as Portable Network Graphic.