Tools · Making-of

PDF to JPG & PNG

About this project

What it is

A tool that turns each page of a PDF into a JPG or PNG image: one slide to drop into a chat, a scanned form for a site that only accepts images, a figure from a paper for your own slides. The key point is that your file is never uploaded. Reading and drawing the PDF all happens inside this browser, so documents you would rather not send anywhere, like contracts or ID copies, can be converted as they are.

How to use it

Data and method

Pages are drawn with pdf.js (3.11.174), Mozilla's open-source PDF engine, and ZIPs are built with JSZip (3.10.1). Both load from a public CDN, along with pdf.js character maps (CMaps) for PDFs that embed CJK fonts. Each page is drawn onto a white canvas at the chosen resolution and saved as JPG or PNG by the browser's own image encoder. The images are already compressed, so the ZIP stores them without compressing again. This page carries the site's shared analytics and ad scripts, but neither your PDF nor the converted images are sent anywhere.

Limits

It started with a question: could the site take a PDF and hand back JPGs or PNGs? Search for that and you get dozens of sites, and nearly all of them upload your file to a server, convert it there and send it back. So I decided to change one thing. The file would never leave your computer.

Drawing without a server

pdf.js, the engine inside Firefox, already draws PDFs well. Draw a page onto a canvas, save the canvas as an image file, and that is the core of it. Resolution is a multiplier on PDF units (72 points to the inch): about 2.08x for 150 dpi and about 4.17x for 300 dpi. An A4 page at 300 dpi comes out at 2480 × 3508 pixels.

iPhone Safari's canvas limit

A large drawing at 300 dpi can need a canvas of hundreds of millions of pixels. iPhone Safari returns a blank image, with no error, once a single canvas passes about 16.7 million pixels. So any page over 16 million pixels is drawn at a smaller scale that fits, and the result message says how many pages were reduced. Each finished canvas is shrunk to zero right away to hand its memory back; without that, converting hundreds of pages in a row kills the phone's tab.

Korean PDFs and passwords

PDFs that do not embed their Korean fonts need pdf.js character maps (CMaps) to show the text correctly. Those load from the same CDN as the library, only when needed. When pdf.js asks for a password, the page asks you in an input box on screen, and asks again in the same box if it is wrong.

The ZIP is not compressed

Several pages are bundled into one ZIP. JPG and PNG are already compressed, so compressing them again inside the ZIP saves almost nothing and costs time; the ZIP simply stores them. File names are the original PDF name plus a three-digit page number, so sorting by name in a file browser keeps the pages in order.

Try PDF to JPG & PNG Go to ghmun.com/en/pdf →