Fetching latest headlines…

Dev

Building a Private PDF-to-JPG Converter with Next.js and PDF.js

Dev.toUnited States · NORTH AMERICA

I built Free PDF to JPG Tool to make converting PDF pages into images easier, without requiring registration, installing software or uploading documents to a server. The goal was simple: choose a PDF,...

0 views0 likes0 comments

I built Free PDF to JPG Tool to make converting PDF pages into images easier, without requiring registration, installing software or uploading documents to a server.

The goal was simple: choose a PDF, select the pages you need, adjust the quality and download the images.

How conversion works in the browser

The website uses Next.js for its interface and content pages, PDF.js to read PDF documents, and HTML canvas to render pages.

The conversion follows these steps:

  1. Read the selected PDF into browser memory.
  2. Open it with PDF.js.
  3. Create a viewport at the requested resolution.
  4. Render the page onto a canvas.
  5. Encode the canvas as a JPEG or PNG.
  6. Create a temporary download URL for the resulting image.

PDF.js uses a worker to handle PDF processing separately from the main interface. Rendering and exporting still consume device resources, so large documents need careful handling.

The document conversion happens locally in the browser. The tool does not send the selected PDFs or generated images to our server.

Batch processing and page selection

Users can select one PDF or multiple PDFs. They can review documents in a three-panel workspace, choose specific pages, and rotate or crop pages before conversion.

Batch output filenames include document identifiers and page numbers, helping prevent collisions when two uploaded PDFs have the same filename.

Quality presets

Different tasks need different output sizes. The tool provides five presets:

Preset Output setting Intended use
High Quality 300 DPI; JPEG or PNG Printing and fine text
Web & Social Media 150 DPI; 85% JPEG quality Everyday sharing
Email & Compact 96 DPI; 70% JPEG quality Smaller attachments
Presentation 1920 × 1080 canvas Slide decks
Thumbnails Up to 600 px wide; 50% JPEG quality Quick previews

Higher resolution creates more pixels and generally larger files. It cannot recover detail that is missing from the original PDF.

The Presentation preset fits the page inside a white slide-sized canvas while preserving its proportions.

Individual images and ZIP downloads

Users can download individual images or collect completed exports into a ZIP.

One important detail is waiting for the ZIP archive to finish before creating the download. Starting a download too early can produce an incomplete archive.

I added an automated test that extracts the generated ZIP and compares its entries with the original image bytes.

Challenges I fixed

PDF worker loading

A missing or incorrectly configured worker can stop the PDF reader from starting.

I corrected the worker configuration and included the worker asset in the deployment. Checking that the deployed worker URL returns JavaScript is an important release check.

Cancellation and stale operations

Users can cancel loading, conversion or export with Escape. Completed images remain available after conversion is cancelled.

The tricky part is preventing an older operation from updating a newer session. I used operation identifiers and task-reference checks so cancelled work cannot overwrite current state or clear a newer task.

Thumbnail retries

Thumbnail generation is queued to avoid starting too many renders together. I fixed an issue where stale jobs could block retries after cancellation.

Memory cleanup

Canvas exports and temporary object URLs consume browser memory. Temporary canvases are released after processing, and image URLs are revoked when results are cleared or replaced.

Large batches still depend on the device’s available memory, so the tool applies file and batch limits.

Languages and feedback

The interface is available in English, Hindi, French and Simplified Chinese.

Try it here:

https://pdf2jpgtool.com

I’d appreciate feedback on the conversion workflow, output quality and mobile experience. What would make a browser-based PDF converter more useful for you?

PDF to JPG

Comments (0)

Sign in to join the discussion

Be the first to comment!