# Export and download (Features)

URL: https://qrdx.dev/docs/features/downloads
Source: https://github.com/qrdxinc/qrdx/blob/main/apps/docs/content/docs/features/downloads.mdx

Save a QR code as PNG, JPG, WebP, GIF, BMP, ICO, TIFF, SVG, PDF or EPS with downloadQRCode, get a data URL, Blob or SVG markup, copy it, or make a PNG in Node.

`downloadQRCode(props, options)` saves the code described by `props` as a file in the browser, in any of six formats. Its siblings return the same file as a data URL, a Blob or markup instead, and `qrdx/node` makes a PNG on a server. Every function takes the same `props` as `QRCode`, so the file matches the code on screen.

Downloading from the playground or the dashboard instead? See [Download and print a QR code](https://qrdx.dev/docs/help/getting-started/download-and-print) in Help.

## Download a file [#download-a-file]

```ts title="lib/download.ts"
import { downloadQRCode } from "qrdx";

await downloadQRCode(
  {
    value: "https://example.com",
    fgColor: "#1d4ed8",
    bodyPattern: "rounded",
    frame: { style: "banner-bottom", text: "Scan me" },
  },
  {
    format: "png",
    size: { width: 1024, height: 1024 },
    filename: "menu.png",
  }
);
```

![What menu.png holds: the code from the snippet, blue with rounded modules, and a Scan me banner under it.](https://qrdx.dev/docs-static/shots/lib-download-result.light.webp)

The browser saves `menu.png`. `size` is the pixel width and height of the code itself, from 50 to 5000 and square; a frame makes the file bigger than that. `filename` is optional: without it the file is named `qr-code.<ext>`, with the exact pixel size added for raster formats (`qr-code-1024x1024.png`, or `qr-code-1270x1454.png` with a bottom banner). `quality` (0 to 1) applies to WebP only.

Props are the same as on `QRCode`, except that a logo goes in `imageSettings`. To export the code a `QRCode` draws, including its `logo` and `logoOptions`, pass `getQRData(props)` or `resolveQRCodeProps(props)` instead of the raw props.

## Formats [#formats]

| `format` | File | Notes |
| --- | --- | --- |
| `png` | Image | Keeps a transparent background. The default for most uses |
| `jpg` | Image | Solid background only, smaller file |
| `webp` | Image | PNG's pixels in a smaller file; lossless unless `quality` is set |
| `gif` | Image | At most 256 colors, with one transparent color, for older tools and email builders. A design that needs more colors is reduced, and refused if it would stop scanning |
| `bmp` | Image | Uncompressed 24-bit bitmap for legacy systems; a transparent background comes out white |
| `ico` | Image | A favicon: the code at 16, 32, 48 and 256 px in one file, with transparency kept. `size` doesn't apply |
| `svg` | Vector | Sharp at any size; the file for print shops and design tools |
| `pdf` | Document | One page holding the code as a PNG. Needs the optional `jspdf` package |
| `eps` | Vector | PostScript for Illustrator, CorelDRAW and InDesign. `size.width` is read as points (72 per inch) |

### WebP [#webp]

WebP is lossless by default, so module edges stay exact and a transparent background stays transparent. Where the browser's canvas writes lossless WebP (Chrome and Edge do), the browser makes the file. Where it cannot, the library checks the bytes and encodes the pixels itself with a small built-in lossless encoder: Safari, asked for WebP, returns a PNG. Either way a `.webp` file is always WebP.

`quality` (0 to 1) asks for a smaller lossy file instead, where the browser supports it. Lossy WebP softens module edges and colors, so keep the default for codes that need to scan from far away. `getQRAsWebP` returns the file as a `Blob`:

```ts title="lib/webp.ts"
import { getQRAsWebP } from "qrdx";

const lossless = await getQRAsWebP({ value: "https://example.com", size: 1024 });
const lossy = await getQRAsWebP({ value: "https://example.com", size: 1024 }, { quality: 0.9 });
```

`canvasToWebP(canvas, options)` does the same for any canvas, and `encodeWebPLossless(rgba, width, height)` encodes RGBA pixels with no DOM.

### GIF [#gif]

GIF is for the older tools and email builders that only take it. A GIF holds at most 256 colors and one transparent color. A code in flat colors (a palette of up to 8 included) fits as it is, so the GIF has exactly the pixels of the PNG. A gradient, an image fill or a photo logo has more colors, so it is reduced to a 256-color palette, with no dithering, because dither noise is what stops a code scanning. A pixel under half opaque becomes the transparent color and any other becomes opaque, so the soft edge of a code on a transparent background comes out hard-edged.

After a reduction the library decodes the original and the GIF: if the original reads and the GIF would not, `downloadQRCode` and `getQRAsGIF` throw a `GIFScanError` instead of saving a code that no longer scans, and the download dialog turns the button off and says to use a PNG. A design that doesn't decode to begin with isn't blamed on GIF. The check loads `jsqr` (a dependency of `qrdx`); a page without a bundler maps it in its import map, and without it a reduced GIF is refused, not passed on unchecked.

No browser can write GIF from a canvas (`toBlob("image/gif")` returns a PNG), so the library writes the file itself, in every browser, and checks its header before saving: a `.gif` file is always a GIF. `getQRAsGIF` returns it as a `Blob`:

```ts title="lib/gif.ts"
import { getQRAsGIF, GIFScanError } from "qrdx";

try {
  const gif = await getQRAsGIF({ value: "https://example.com", size: 1024 });
} catch (error) {
  if (error instanceof GIFScanError) {
    // The design needs more than 256 colors and would stop scanning: use PNG
  }
}
```

`canvasToGIF(canvas, expected?)` does the same for any canvas, `pixelsToGIF(pixels, expected?)` for RGBA pixels with no DOM, and `encodeGIF(image)` writes an image you have already reduced to a palette (`quantizeRGBA` does that step).

### BMP [#bmp]

BMP is for the legacy systems and embedded tools that only take it. The file is an uncompressed 24-bit bitmap, so it is much larger than the same code as PNG. 24-bit BMP has no alpha channel, so a transparent background comes out white.

No browser can write BMP from a canvas (`toBlob("image/bmp")` returns a PNG), so the library writes the file itself, in every browser, and checks its header before saving: a `.bmp` file is always a BMP. `getQRAsBMP` returns it as a `Blob`:

```ts title="lib/bmp.ts"
import { getQRAsBMP } from "qrdx";

const bmp = await getQRAsBMP({ value: "https://example.com", size: 1024 });
```

`canvasToBMP(canvas)` does the same for any canvas, and `encodeBMP(rgba, width, height)` writes RGBA pixels with no DOM.

### ICO [#ico]

ICO is the favicon format: one file holding the code at 16, 32, 48 and 256 px, each stored as a PNG inside the ICO, which every browser and Windows since Vista read. A transparent background stays transparent. Because the sizes are fixed, `size` doesn't apply and the file name states none (`qr-code.ico`), and a frame is left out, since every image is square and at most 256 px. The small sizes are for icons, not for scanning.

No browser can write ICO from a canvas (`toBlob("image/x-icon")` returns a PNG), so the library draws the code at each size, takes a PNG of each, writes the ICO itself, and checks its header before saving: a `.ico` file is always an ICO. `getQRAsICO` returns it as a `Blob`:

```ts title="lib/favicon.ts"
import { getQRAsICO } from "qrdx";

const favicon = await getQRAsICO({ value: "https://example.com" });
```

`canvasesToICO(canvases)` writes any canvases of 1 to 256 px, and `encodeICO(images)` wraps PNG files you already have, with no DOM.

### TIFF [#tiff]

TIFF is for print shops that ask for it. `"tiff"` is the code's pixels with its transparency, recorded at 300 dpi; `"tiff-cmyk"` is the same file in CMYK for print. The CMYK one uses the same conversion as the print PDF and EPS: pure black prints as black ink only (no rich black under fine modules), white is no ink, and a transparent background comes out white. No ICC profile is embedded, so ask your printer for a color-managed conversion when exact brand colors matter. Both are saved as `.tif`, the CMYK one with `-cmyk` in its name.

No browser can write TIFF from a canvas (`toBlob("image/tiff")` returns a PNG), so the library writes it itself (Deflate-compressed where the browser has Compression Streams, uncompressed otherwise) and checks its header before saving. `getQRAsTIFF` returns it as a `Blob`:

```ts title="lib/print-tiff.ts"
import { getQRAsTIFF } from "qrdx";

const tiff = await getQRAsTIFF(
  { value: "https://example.com", size: 1200 },
  { colorMode: "cmyk", dpi: 300 },
);
```

`canvasToTIFF(canvas, options)` does the same for any canvas, and `encodeTIFF(rgba, width, height, options)` writes RGBA pixels with no DOM.

### PDF [#pdf]

The PDF download holds the code as a PNG on a page of the same size. It needs the optional `jspdf` package (`npm install jspdf`); without it, PDF downloads throw `PDF export needs the optional "jspdf" package`. For a vector PDF at a physical size, with bleed, crop marks and CMYK, use `downloadPrintPDF`; see [Print-ready export](https://qrdx.dev/docs/features/frames#print-ready-export).

### EPS [#eps]

EPS needs no extra package. `downloadQRCode` reads `size.width` as points, so a 512 px request writes a 512 pt (18 cm) file. For an exact physical size, use `getQRAsEPS`, which returns the EPS as a string: the code is `sizeMm` wide (default 50 mm), and a frame adds to that.

```ts title="lib/eps.ts"
import { downloadPrintEPS, getQRAsEPS } from "qrdx";

const eps = await getQRAsEPS(
  { value: "https://example.com" },
  { sizeMm: 40, bleedMm: 3, colorMode: "cmyk" }
);

await downloadPrintEPS({ value: "https://example.com" }, { sizeMm: 40, filename: "menu.eps" });
```

EPS has no transparency and no crop marks. Linear and radial gradients print as smooth PostScript Level 3 shadings; angular gradients print as a fan of thin wedges. See-through colors are mixed with the background, and the background with white paper. PNG and JPEG logos are embedded. EPS cannot carry an [image fill](https://qrdx.dev/docs/features/colors-gradients#image-fills): `getQRAsEPS` throws `EPS_IMAGE_FILL_REASON`, and the dashboard's download dialog offers PDF, SVG and PNG instead.

## Data URLs, Blobs and markup [#data-urls-blobs-and-markup]

```ts title="lib/export.ts"
import { copyQRCodeToClipboard, getQRCodeDataUrl, getSVGString } from "qrdx";

const props = { value: "https://example.com", size: 512 };

// The same file as a data URL, for an <img> or a form field
const png = await getQRCodeDataUrl(props, "png", { width: 512, height: 512 });

// A PNG on the clipboard, for pasting into a document
await copyQRCodeToClipboard(props, { width: 512, height: 512 });

// The SVG markup, for inlining in a page or an email template
const svg = await getSVGString(props);
```

- `getQRCodeDataUrl(props, format, size, { quality })` takes every format `downloadQRCode` takes.
- `copyQRCodeToClipboard` writes a PNG. Call it from a click handler: browsers refuse clipboard writes outside a user gesture.
- `getSVGString` embeds the logo as a data URL, so the markup stands on its own. `toSVGString` from `qrdx/core` is the synchronous version without that step.

## Preset sizes [#preset-sizes]

```ts title="lib/sizes.ts"
import { PRESET_SIZES, validateSize } from "qrdx";

PRESET_SIZES.small; // { width: 200, height: 200 }
PRESET_SIZES.medium; // 400
PRESET_SIZES.large; // 800
PRESET_SIZES.xlarge; // 1200
PRESET_SIZES["2xl"]; // 1600
PRESET_SIZES["3xl"]; // 2000

validateSize(4000, 4000); // { isValid: true }
validateSize(6000, 6000); // { isValid: false, error: "Size must not exceed 5000x5000 pixels" }
```

Pick the size by where the file goes: 256 to 512 px for a web page, 1024 px or more for print at 300 pixels per inch (1024 px prints sharply up to about 8.7 cm wide). For exact print sizes use the print functions, which work in millimeters and inches.

## PNG in Node [#png-in-node]

`getQRAsPNG` from `qrdx/node` returns PNG bytes without a browser. It needs one optional rasterizer installed next to `qrdx`: `@resvg/resvg-js` draws the SVG, logos included, the way browsers do; `sharp` also works.

```ts title="scripts/make-png.ts"
import { writeFile } from "node:fs/promises";
import { getQRAsPNG } from "qrdx/node";

const png = await getQRAsPNG(
  { value: "https://example.com", bodyPattern: "rounded", margin: 4 },
  { size: 1024 }
);
await writeFile("qr-code.png", png);
```

Import it from `qrdx/node`, never from `qrdx`, so browser bundles never see the native modules. A logo that is a data URL is embedded as it is; an `http(s)` URL or a local path is loaded only with `loadExternalLogos: true`, so a server passing a caller's settings through cannot be made to fetch internal URLs or read its own disk. SVG markup needs no rasterizer: `toSVGString` from `qrdx/core` runs anywhere.

## If something goes wrong [#if-something-goes-wrong]

- **`Size must be at least 50x50 pixels`, `Size must not exceed 5000x5000 pixels` or `Width and height must be equal for QR codes`.** `validateSize` rejected the size. Pass a square size in range.
- **`PDF export needs the optional "jspdf" package`.** Install `jspdf` in the same package as `qrdx`.
- **The logo is missing from the file.** The image comes from another origin without CORS headers, so the browser could not copy it. Serve it from your own origin or pass a data URL.
- **`copyQRCodeToClipboard` rejects.** It ran outside a click or key handler, or the page is not served over HTTPS. Call it from the handler itself.
- **`getQRAsPNG` throws about a missing rasterizer.** Install `@resvg/resvg-js` or `sharp` next to `qrdx`.

## Related [#related]

- [Frames, scan score and print files](https://qrdx.dev/docs/features/frames): Vector PDF and SVG at a physical size, with bleed and crop marks.
- [QR Code Download component](https://qrdx.dev/docs/components/qr-code-download): A ready-made download menu for shadcn/ui projects.
- [QR code image API](https://qrdx.dev/docs/developers/image-api): A code as an image URL, with no code at all.
- [Library API reference](https://qrdx.dev/docs/api-reference): Every download and export function, with its signature.
