Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

There are a lot of questions out there about how to convert a PDF file to a PNG image, but I'm looking to take a nice sharp PNG file and just basically wrap it or embed it in a PDF file without having it look blurry or fuzzy.

I realize with imagemagic installed I can do a simple conversion like:

convert sample.png sample.pdf

I've also tried a lot of the switches to set the depth, and also the quality setting:

convert -quality 100 sample.png sample.pdf

However the PDF still comes out looking blurry / fuzzy.

Here's a sample image:

As a png it's crisp and clean. When I convert it to a PDF, even at the same size it looks blurry:

Picture 4.png

How can I convert PNG to a PDF in high quality?

share|improve this question
I hope you find a good answer to your question, but I think it is just a given property of PDF to store images in JPG format. PNG, like the one you show us, has much better quality than JPG. – jippie Jul 12 '12 at 6:32
@cwd: Did you try to put it in a .tex file, and then generate the PDF? With \usepackage[pdftex, final]{graphicx} and \includegraphics[width=516px]{calendar.png}, for example. – Emanuel Berg Jul 13 '12 at 8:17
@jippie: No, PDF can store bitmaps losslessly. The link gives a list of compression algorithms rather than formats, because the bitmap data inside a PDF can't be extracted and viewed directly as a JPEG or TIFF, but you wouldn't go far wrong saying that PDF images are either JPEG (lossy), JPEG 2000 (also lossy) or any of several TIFF variants (lossless). What is true, however, is that a given PDF distiller may default to translating bitmaps into DCT (a.k.a. JPEG) form, and have to be told to use a lossless form instead. – Warren Young Jul 13 '12 at 9:38
@cwd Have you thought about accepting some answer? I think user32208's answer is rather good unix.stackexchange.com/a/64495/16920 – Masi Jun 25 at 7:35

Try using the -density option. The default resolution is 72 dots per inch. So try something like -density 300.

For reference see -density in the ImageMagick command-line options documentation.

share|improve this answer
awesome! Thanks! – Gabriel Samfira Jan 13 '14 at 9:47
Density definitely seems to be the key. Scale and density seem to be inversely related, so I have been playing with both settings to get an optimum result in terms of both appearance and file size... If there is a set formula, I wish I knew it. – Brian Z May 2 '15 at 4:18
How to find the best density option? How much is data lost with density 300 with any example picture? I think the result depends on the input. A new thread about it here unix.stackexchange.com/q/292025/16920 – Masi Jun 25 at 7:34

I am almost certain that what you perceive as a loss of quality in the PDF, is just an effect of your PDF viewer's anti-aliasing feature.

If you use evince to view the PDF, you can see the anti-aliasing feature automatically switched off at a certain zoom (300% in my quick test). You can see that vividly when you keep zooming in - you will notice that at some point, pixels become suddenly clearly visible. That is the point when anti-aliasing must have been switched off to allow precise image inspection.

share|improve this answer
Hmm - that makes sense but I guess I was hoping to be able to somehow set the image and the "initial view" to 100% so that it looks crisper. – cwd Jul 12 '12 at 20:10
@cwd Don't mistake the zoom (a way of examining the file) with the actual cause of image smoothing: anti-aliasing. The image is stored properly. It is the PDF viewer that fools you. But it could be the other way around even - if you'd take some other viewing applications or change their settings. You could then see a sharp image in a PDF file and a smoothed PNG file in an image viewer. – rozcietrzewiacz Jul 13 '12 at 6:37

It can be very complicated to get good pdf output from convert. Try img2pdf instead. From the readme:

Lossless conversion of images to PDF without unnecessarily re-encoding JPEG and JPEG2000 files. Thus, no loss of quality and no unnecessary large output file.

To clarify: PDF can embed lossless JPEG 2000 images (and most readers appear to support them). So this conversion is completely lossless:

convert sample.png -quality 0 sample.jp2
img2pdf -o sample.pdf sample.jp2

(Assuming the JP2 delegate is available of course: check identify -list format | grep JP2.)

share|improve this answer
This is IMHO the best answer here, but you should explain better your point, i.e. that PDF can embed lossless JPEG 2000 images. So the full command for the OP would be something like: convert sample.png -quality 0 sample.jp2; img2pdf -o sample.pdf sample.jp2. (Assuming the JP2 delegate is available of course: check identify -list format | grep JP2.) – Nemo Oct 8 '15 at 20:15
If you want to stick to standard repositories on Ubuntu 14, convert to tiff and then tiff2pdf. – Camille Goudeseune Nov 4 '15 at 17:24

PDF is a vector format (i.e., the file contains a description of lines to draw), while other formats (JPG, PNG) are raster formats (the file describes what color to paint each pixel). If you blow a PDF up, it is still just sharp lines; JPG and PNG show the pixelation.

(OK, OK, I lied. A PDF can also be a raster).

share|improve this answer

I think that for png-to-pdf -density parameter should small rather than large. You could try something like convert -quality 100 -density 50

share|improve this answer
Nope higher density is definitely better, just did a test, 50 results in lots of very visible pixels, 300 is nice and crisp looking. – shaunhusain Sep 28 '14 at 23:13
This has been confusing me, but I think a higher density results in output with lower resolution. That means that if the output is fuzzy (over-aliased, like the example in the original question) then lower density is what you want. But if a PDF is pixelated then indeed you need to convert with a higher density. – Brian Z Apr 22 '15 at 7:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.