[Qt-interest] Qt > My Images > Export PDF = Blurry

blit test bltlblttst at gmail.com
Tue Nov 17 21:14:42 CET 2009


Hello,

I don't seem to be able to create a PDF (with an image embedded in it) where
the quality of the image is not "blurry". After days of trying with a
variety of sized images to work, I still can not get a sharp image in a
8.5x11 QT created PDF sadly, every image I try and place in my PDF has a
soft blurriness to it. I was hoping someone that has some Qt / PDF
experience could let me know their experiences.

Short Version:

Adding an image (even a hi-rez / 1944 x 2880 72dpi image) to the QPrinter /
QPainter (for the QPrinter->PdfFormat) will output the image in the PDF as
"blurry".


Long Version:

Creating a QPrinter with output format of "PdfFormat"
Loading an image from my hard drive
Drawing it using painter.drawImage(0,0,img)
Saving the PDF out to my hard drive
Opening the PDF up in Apple Preview App and the resulting image inside of
the PDF is "blurry"

Strangely, opening the PDF in Adobe Photoshop correctly displays the image
but no "white border" around it. So this might be related to how the Qt->PDF
page size is handled with images?

Code:


QPrinter *printer = new QPrinter;
printer->setOutputFormat(QPrinter::PdfFormat);
printer->setPaperSize(QPrinter::Letter);
printer->setOutputFileName("/Users/Me/Desktop/output_sample.pdf");

QPainter painter;

if (!painter.begin(printer)) {
 qWarning("failed to create file.");
 return ;
}

//painter.setRenderHint(QPainter::HighQualityAntialiasing,true); //does not
seem to have effect



QString name();

QImage img("/Users/Me/Desktop/bandslam.jpg");

//472 = the width of the image after I do a scaledToHeight = 700 later in
the code
painter.setViewport(0,0, 472, 700); //is this even needed?
painter.setWindow(QRect(0,0,472,700));//is this even needed?



img = img.scaledToHeight(700, Qt::SmoothTransformation);
painter.drawImage(0,0,img);





Note: Since our images are so large I need to resize them down so they are
no taller then 700 pixels (a 8.5 x 11 pdf = 612 x 792 pixels).

sample code:

img = img.scaledToHeight(700, Qt::SmoothTransformation);

The resized image is VERY nice and sharp when saved out to a file so this is
not a case of Garbage in / out.

My fear is that Qt's PDF logic is adding too much compression to the image
upon adding it to the PDF and that there is no way to turn it off.

Or maybe my QPainter Viewport or Window settings are conflicting somehow
with the PDF resolution?

At this point, if its something Qt / PDF just can't do, I'm open to other
suggestions that would also work with Qt.

Or maybe this is a bug with 4.6? (I have not installed 4.6 RC yet, but will)

I am using QT OS X 4.6, but not sure if this is related to 4.6, this problem
may still occur on 4.5.

My sample image is a photo but does have embedded text in it (which looks
sharp when saved out as as PNG or JPG. ) If needed I have a sample image
which will show the results immediately upon running the code above.

My sample image is 1050 x 1556 72dpi so its not like I am using low rez
images. I have used many other images / sizes and still suffer form blurry
images.

Has anyone seen anything like this?

thank you.


-----------------------


Here is some more info which I have uncovered in my search for a solution:


I found three items in the bug database which _may_ be related:

http://bugreports.qt.nokia.com/browse/QTBUG-1792

When printing to PDF, the image compression is set and cannot be changed.
The image compression is usually perfectly fine for photographic images, but
may not be appropriate for technical drawings, due to the artifact
introduced with the compression.
Therefore, it would be nice if it was possible to adjust the level of image
compression when printing to PDF.

http://bugreports.qt.nokia.com/browse/QTBUG-4898

Printing to pdf scales the content, so it have the wrong size on screen, and
in print. This have been reproduced with HTML content but a simple
QPainter::drawRect() test displays (slightly) wrong on screen, but prints
correctly. It happens on both Windows and Linux. When a certain size is set
in inches (or cm) in the HTML document, this is not respected in the final
pdf document.

http://bugreports.qt.nokia.com/browse/QTBUG-2733

Which is a patch for adding "Raw" images to a PDF (Raw being the
uncompressed image format popular on cameras I believe.)

It would be useful if Qt had the option of embedding RAW images directly
into PDF files instead of using JPEG files. The quality of the images is
better and the size of the generated PDF is smaller than using a high
quality JPEG image.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091117/a567534c/attachment.html 


More information about the Qt-interest-old mailing list