Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image is blurred in generated pdf #173

Open
parag-bhole opened this issue Feb 7, 2018 · 6 comments
Open

Image is blurred in generated pdf #173

parag-bhole opened this issue Feb 7, 2018 · 6 comments

Comments

@parag-bhole
Copy link

Hi, I am trying to create a pdf from html source, which has certain images loaded from URLs. Few png images of size 16x16 pixels are getting rendered blurred, while other images on page are looks fine. Please see the attached pdf and html files. In pdf images in "Priority" column in tables are not rendered properly. How can I fix this?
generated.pdf
from_html.html.txt

@danfickle
Copy link
Owner

Hi @parag-bhole

They certainly look blurry in the PDF. Could you upload a sample of the working image and non working image (I can’t download from localhost)? Thanks.

@parag-bhole
Copy link
Author

parag-bhole commented Feb 13, 2018

Hi @danfickle
Thanks for checking out, please see attached here 2 images -
Working fine - story_working
Blurred - medium_not_working

@danfickle
Copy link
Owner

I tested your two images with the file command on Mac. It turns out the non-working arrow is 16 bits per channel and PDFBOX doesn't like this. I think the easiest way would be to convert the 16bit image to a standard 8bit image. I did this with an online converter and upload it here for you.

file output:

issue-173-not-working.png: PNG image data, 16 x 16, 16-bit/color RGBA, non-interlaced
issue-173-working.png: PNG image data, 16 x 16, 8-bit/color RGBA, non-interlaced
issue-173-now-working.png: PNG image data, 16 x 16, 8-bit/color RGBA, non-interlaced

issue-173-now-working

@parag-bhole
Copy link
Author

Ok thanks @danfickle for the pointing out where the issue is. Unfortunately image comes from webapp we don't own and all we have is URL to include in html, so may be we will have to live with it.

@rototor
Copy link
Contributor

rototor commented Apr 7, 2018

FYI: I've created a patch and ticket for this upstream: https://issues.apache.org/jira/browse/PDFBOX-4184

In your case the alpha mask of the images is not correctly converted, the image looks broken because of that.

When you want pixelated images (i.e. without interpolation) we must set

	pdImage.setInterpolate(false);

on the image, so that it does not get blured. To do so we should add support for the image-rendering CSS property (see https://developer.mozilla.org/de/docs/Web/CSS/image-rendering). This does not work with all PDF reader, but at least Acrobat and the PDFBox Debugger render interpolate=false images correctly. (Mac Preview does not...)

@THausherr
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants