JPG to PDF Converter
Combine your JPG, PNG, or WebP photos into one PDF — fully inside your browser, no signup, no upload. Pick page size, orientation, and margin; reorder pages with a tap. The PDF is built locally and downloads instantly. Sources cited.
How it works
A PDF is, in essence, a small text envelope wrapped around image and graphics streams. Embedding a JPEG is the easiest case in the whole specification — PDF's default user space is measured in points (1 point = 1/72 inch), and the format defines a native filter called DCTDecode that says “this stream is JPEG data, render it as an image” (ISO 32000-2 §7.4.5). That means a JPEG byte stream can be written into a PDF Image XObject with zero re-encoding. PNG and WebP do not have a direct PDF equivalent, so this tool transcodes them to JPEG in the browser canvas (92% quality) before embedding.
The PDF builder is hand-written and lives in lib/data/jpg-to-pdf.ts. Per image, three PDF objects are emitted: a Page node, a Contents stream, and an Image XObject. The Contents stream uses two PDF operators — cm (concatenate the current transformation matrix; encodes scale and position) and Do (invoke the named XObject). The image is intrinsically one unit wide and one unit tall in user space, so the cm matrix encodes both the on-page size in points and the bottom-left placement coordinate.
For each image the tool does five deterministic things:
- Validate the file. Confirms the image type (JPG / PNG / WebP), a non-zero size, and a per-image cap of 50.0 MB. JPEGs are checked for the literal 0xFFD8 SOI marker; PNG and WebP fall through to the canvas transcoder.
- Extract the natural size. For JPEGs, the Start-Of-Frame marker is parsed directly from the byte stream (ITU-T T.81 §B.2.2) — no decode required. For PNG and WebP, the canvas reports the natural width and height after the browser has decoded the image.
- Resolve the page size. One of 6standard page sizes, or “Fit to image” which makes each page exactly match the image at 72 DPI. Orientation can be Portrait, Landscape, or Auto — Auto picks the orientation closer to the image's aspect ratio.
- Solve the placement. The image is placed inside the page's content rectangle (the page minus margins) using the chosen fit mode. The math is cross-checked two ways: a scale-factor formula (min vs max of widthScale and heightScale) and an aspect-ratio formula (image ratio compared to content-rectangle ratio). The two agree to the millimetre.
- Assemble the PDF. Objects are written sequentially, byte offsets recorded as we go, then an xref table and trailer close the file. The resulting byte stream is wrapped in a Blob and offered as a download via an object URL. No bytes leave the browser tab.
Worked examples
Frequently asked questions
Sources & references
- ISO 32000-2 — PDF 2.0 specification (DCTDecode filter, Image XObject, page tree, content streams)
- ITU-T T.81 — JPEG specification (Start-Of-Frame marker, sample precision, components)
- ISO 216 — A-series paper sizes (A4, A3, A5)
- ANSI/ASME Y14.1 — US paper sizes (Letter, Legal, Tabloid)
- MDN — HTMLCanvasElement.toBlob (canvas-side PNG→JPEG transcoding)
The PDF and JPEG handling code was cross-checked against the above specifications on 2026-05-11. The page is reviewed whenever either standard publishes errata that affect Image XObject or DCTDecode encoding.
Related tools
Comments & feedback
Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.
Found a bug, edge case, or want to suggest an improvement?
Email me at [email protected] — most fixes ship within 24 hours.