What happens to a PNG when you convert it to PDF?
When you convert a PNG to PDF here, the image is decoded into plain pixels, the colour is stored in the PDF as a compressed RGB image, and any transparency is stored separately as a soft mask. The page is sized to the image. Nothing is lost visually, so screenshots, diagrams and logos come out pixel-for-pixel, and the whole job runs in your browser with pdf-lib.
The result downloads as image.pdf, a single page holding one image.
Inside the conversion
Unlike JPEG, which a PDF can carry as-is, PNG data has to be unpacked and rewritten. pdf-lib does this in three steps:
- Decode. The PNG is decompressed into 8-bit red, green, blue and alpha values for every pixel. Greyscale, palette (indexed), truecolour and alpha variants are all accepted (W3C PNG specification lists the five colour types).
- Split. The RGB values become the image. If at least one pixel isn't fully opaque, the alpha values become a separate greyscale image used as a soft mask, the PDF mechanism for per-pixel transparency (ISO 32000-1, section 11.6.5.3).
- Recompress. Both are compressed with Flate, the same lossless deflate algorithm PNG itself uses, and drawn onto a page exactly the image's size.
Transparency in practice
A logo with a transparent background converts to a PDF page where the logo floats on whatever the viewer paints behind it, normally white on screen and paper. Partial transparency, like soft drop shadows and anti-aliased edges, is kept at full 8-bit precision, so edges stay smooth.
If you later place that PDF into a design tool or a layout program, the transparent areas stay transparent. That's the main reason to prefer this over first flattening the image to JPG.
Size: when the PDF grows
Because pixels are stored as RGB, the PDF can be larger than the PNG you started with:
| Kind of PNG | Original storage | In the PDF | Likely size change |
|---|---|---|---|
| Palette screenshot or icon (up to 256 colours) | 1 byte or less per pixel | 3 bytes per pixel, then deflated | Often larger |
| Greyscale scan | 1 byte per pixel | 3 bytes per pixel, then deflated | Often larger |
| Truecolour photo or render | 3 bytes per pixel | 3 bytes per pixel, then deflated | About the same |
| 16-bit-per-channel PNG | 6 bytes per pixel | Reduced to 8 bits per channel | Often smaller, with less colour precision |
There's also fixed PDF overhead: the 68-byte single-pixel PNG used in this site's tests became a 930-byte PDF. For tiny graphics that overhead dominates, for real screenshots it doesn't. If the PDF is too large, shrink the image first with the image resizer, or, for photos with no transparency, convert with PNG to JPG and then use JPG to PDF, which embeds JPEG data without re-encoding it.
Page dimensions
Each image pixel becomes one PDF point (1/72 inch), and the page is exactly that size with no margins. A 1440 x 900 screenshot gives a 20 x 12.5 inch page; the same screen captured on a high-density display at 2880 x 1800 gives 40 x 25 inches. PDF viewers fit it to the window, so this only matters when printing: use your print dialog's "Fit to page" option. Any resolution (pHYs) value stored in the PNG is not used.
Converting step by step
- Click Choose a PNG image and select your file.
- Click Convert.
- Click Download to save
image.pdf. - To put several images into one document, convert each and join them with the PDF merger.
Errors you might see
- "Choose a PNG image." No file was chosen, or it isn't an image file.
- "Could not convert that image: Animated PNGs are not supported" The file is an APNG with several frames.
- "That file isn't a PNG image." The file doesn't start with the 8-byte PNG signature, for example a JPEG renamed to
.png. Use the JPG to PDF tool for JPEGs. - "Could not convert that image:" followed by a decoder message The file starts like a PNG but its data is cut short or damaged, such as a partly downloaded file. Re-export or re-download it.
An embedded colour profile in the PNG isn't carried into the PDF; the pixels are tagged as plain device RGB, which looks the same on most screens. There's no file size cap in the code, but large images are decoded fully into memory, roughly 4 bytes per pixel, so a 50-megapixel PNG needs a couple of hundred megabytes of RAM while it converts.
Last updated