Blog · PDF tips

PDF to PNG for crisp and transparent-friendly exports

Someone titled a ticket “export the logo with transparency.” The file they attached was a one-page PDF of a wordmark sitting on what looked like a clear artboard. I ran it through PDF to PNG and sent back a PNG. They replied with a screenshot of a white box on a dark webpage. They were right about the box. I was wrong to let the filename “transparent-exports” do the thinking.

The canvas does not keep alpha

Same renderer as the JPG path. PDF.js viewport at scale 2. The call is explicit: getContext('2d', { alpha: false }) and background: '#ffffff'. Then toBlob with image/png. PNG as a format can store transparency. This export does not ask it to. Every page is flattened onto white, then encoded losslessly. You get crisp edges and a guaranteed backdrop. You do not get a knockout.

That distinction is the whole article. If your source is a real PDF page — a slide, a diagram, a UI capture someone printed to PDF — white is usually what you wanted, because the page already had a paper color. If your source is a logo that only lived in a PDF because someone hit export without picking SVG, this tool will disappoint you, and an editor that understands the original art will not.

SourcePNG from this toolWhat I do instead
Diagram with hairline rulesEdges stay binary. No JPEG blocks.Use the PNG
Full-page photoLarge file, little visual gain over JPG 0.92JPG
Logo expecting a clear surroundWhite rectangleExport SVG or PNG from the design file
Page with a soft drop shadow meant to sit on a colored layoutShadow ends at a hard white edgeRebuild the shadow in the layout app

Where the lossless part earns its size

A flowchart I pulled out of a spec was 11 boxes and a lot of 1-pixel lines. JPG at the sibling tool’s 0.92 chewed the lines into dashed gray. PNG held them. The file was 2.4 MB for one letter page. I placed it in a Confluence page at 900 pixels wide. It looked like the spec, not like a photo of the spec. That is the case I say yes to.

A product photo on the next page of the same PDF was 4.8 MB as PNG and visually identical, at slide size, to a 700 KB JPG. I kept the JPG in the draft and left the PNG in a folder I did not upload. Lossless is not a moral good. It is a file-size decision you can see.

Scale 2 on a large-format sheet — an A1 plan stuffed into one PDF page — produces a canvas that can exhaust a laptop. The loop is one page at a time, which helps, but a single viewport can still be enormous. If the tab dies on page 1, the page is too big for this render, not “unsupported.” Split is useless if the heavy thing is one page. Rasterize from the CAD app at a known DPI instead, or render on a machine with more RAM.

Reading order and the pages I skip

The script walks every page. There is no “only page 3” control. I split page 3 out when the PDF is long, then convert the one-page file. Downloading 40 PNGs to delete 39 of them is how disks fill up with spec-page-17.png that nobody will open.

Text on the PNG is not text. I learned to stop pasting these into OCR as a first step when the PDF already had a text layer. PDF to Word reads the text layer. The PNG is for eyes. Using the picture as the source of truth, then OCRing it, adds errors the original file did not have. I only OCR a PNG when the PDF page was a scan and I already failed to get text another way.

A placement note for people who composite

If you drop the PNG onto a colored slide, you will see a white card unless you mask it. I mask in the slide tool with a rough rectangle when the diagram has margin. I do not pretend the margin was transparent. Cropping the margin off in an editor, tightly, is the honest fix. Feathering the edge to fake transparency looks like a mistake at the exact zoom your boss will use.

Color: PNG from canvas is ordinary 8-bit RGBA displayed as opaque. Do not expect a CMYK print match. The PDF might have been tagged. The canvas is sRGB-ish browser pixels. For a web article that is fine. For a brand guide’s color chip, export the chip from the source, not from a PDF screenshot pipeline. I have watched a navy turn into a slightly different navy and a designer spend an hour blaming the CMS. It was the canvas.

Password-protected pages do not render. Unlock first if you are allowed to. Rotated pages render in their rotated orientation. Fix rotation in the PDF if the diagram needs to be upright in the PNG. The image tool will not restyle the page. It photographs it.

I name files fig-4-scale2.png so the next edit knows the pixel density was “PDF.js scale 2,” not 300 DPI print. When someone asks for a 300 DPI TIFF later, I do not upscale this PNG. I go back to the PDF or the design file. Upscaling a scale-2 screenshot to satisfy a printer checkbox is how soft diagrams get into print bids.

The ticket about the logo ended with the designer exporting PNG from Figma. The PDF tool was the wrong door. I still use it weekly for figures that are trapped in reports and need to be sharp on a page that is not a PDF. I just stopped promising clear backgrounds the renderer never offered.

A figure that had to survive a dark slide

The diagram was black lines on a transparent-looking PDF page that was actually drawn as white. On a navy slide the white card screamed. I cropped to the linework in an editor until the remaining margin was a few pixels, then placed it. You still see a thin white rim if you look. I preferred the rim to a fake feather. The rim says “this was a page.” The feather says “someone got nervous.” For a second diagram that had been exported from the design tool as a real transparent PNG, I did not run it through the PDF path at all. Putting a good PNG into a PDF and back out is how you acquire the white card. Direction matters. PDF to PNG is for when the PDF is the only source. It is not a purification step for assets you already have.

File names from the batch include the page index. I rename spec-page-3.png to the figure number in the report, fig-2.png, only after I have checked it is figure 2 and not figure 2’s caption page. I once labeled a caption page as the figure and built a whole article section around the wrong image. The pixels were sharp. The subject was the previous page. Sharpness does not check identity. The thumbnail strip does.

If the PNG is destined for print anyway, I tell the printer the pixel dimensions and that it came from a scale-2 screen render. Some will refuse it, which is a useful refusal. They would rather have the PDF. I send the PDF. The PNG was for the webpage. Two outputs, two recipients, no argument about why the lines looked soft on a proof. They looked soft because I sent the wrong file to the wrong machine.