Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Start by reducing peak image memory. Resize each image to the pixels needed in the PDF, avoid keeping full-resolution canvases and base64 strings alive at the same time, and add images one at a time. Then verify that every addImage argument uses a supported input type and an explicit format when detection could fail. A large PDF and a crashed browser are related symptoms but are not proof of the same cause.

This guide gives a reproducible diagnosis, safer code patterns, browser-specific checks, and recovery options. The available evidence does not establish a universal pixel limit, browser-memory threshold, or guaranteed jsPDF version that fixes every crash.

What usually causes the crash

Image export can exhaust the browser’s JavaScript heap or graphics memory when several large representations coexist: the original image, a decoded bitmap, one or more canvas buffers, a base64 data URL, and jsPDF’s internal image data. A page rendered from many HTML elements can create multiple canvas contexts; a 2025 jsPDF issue reports memory rising during that process and proposes canvas reuse, but its estimated improvements are unverified and should not be treated as benchmarks (issue 3900).

Other failures have different signatures:

  • Immediate exception: an unsupported or malformed value was passed to addImage, or format detection failed.
  • Slowdown followed by tab termination: peak memory is probably too high for the target browser and workload.
  • PDF opens but is unexpectedly large: encoding, dimensions, or compression may be inefficient. A historical report documents a canvas-to-PDF output that was much larger than expected; it does not prove that data URLs inherently crash browsers (issue 1787).
  • Only untrusted GIFs trigger failure: malicious dimensions are a security concern. GitLab’s advisory for CVE-2026-25535 describes an out-of-memory/denial-of-service vector; check its current affected and fixed-version information before processing attacker-controlled files (CVE-2026-25535 advisory).

Confirm the workload before changing code

  1. Record the exact jsPDF version, browser and version, operating system, image format, pixel dimensions, image count, and whether each source is an HTMLImageElement, HTMLCanvasElement, data URL, Uint8Array, or RGBA object.
  2. Run a one-image export. Repeat while increasing only the image’s pixel dimensions, then restart and increase only the image count. This separates dimension pressure from count pressure.
  3. Use browser DevTools Performance and Memory panels to watch the tab during decoding, canvas creation, and doc.save(). Capture a heap snapshot before and after a batch; a growing detached-canvas or string population indicates references are being retained.
  4. Test the same workload in the browsers you support. Do not infer a universal limit from one machine: the available reports provide no reliable browser/version reproduction matrix.

Use addImage with a documented input

The current API documentation lists base64 data URL strings, HTMLImageElement, HTMLCanvasElement, Uint8Array, and RGBA data as accepted inputs. The call includes format, x/y position, width and height, followed by optional alias, compression, and rotation arguments (jsPDF addImage documentation). The repository’s TypeScript declarations corroborate these input types and the compression parameter (TypeScript declarations).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Amazon Basics Multipurpose Copy Printer Paper, 8.5 x 11 Inches, 20 lb, 92 Bright, White, 1 Ream (500 Sheets), Jam-Free
  • 1 ream (500 sheets) of 8.5 x 11 white copier and printer paper for home or office use
  • Multipurpose letter size copy paper works with laser/inkjet printers, copiers and fax machines
  • Smooth 20lb weight paper for consistent ink and toner distribution; dries quickly and resists paper jams
  • Bright white paper (92 GE; 104 Euro) offers great contrast for crisp printing and vivid color
  • Virgin copy paper providing professional quality results; acid-free to prevent yellowing

Supply the format when recognition might fail, especially with a data URL or byte array. JPEG is documented as the default for canvas elements, but an explicit value makes intent clear.

import { jsPDF } from "jspdf";

const doc = new jsPDF({ unit: "mm", format: "a4" });
const image = document.querySelector("#photo");

image.addEventListener("load", () => {
  // Choose dimensions that match the printed size, not the camera's full resolution.
  doc.addImage(image, "JPEG", 15, 20, 180, 120, undefined, "MEDIUM");
  doc.save("report.pdf");
});

Wait for image decoding before calling the API. For an image already in the DOM, await image.decode() is preferable to guessing with a timeout. For a canvas, make sure it contains the intended pixels and pass the canvas directly or convert it once, not repeatedly.

Rank #2
HP Printer Paper | 8.5 x 11 Paper | Copy &Print 20 lb | 1 Ream Case - 500 Sheets| 92 Bright | FSC Certified | 200060
  • HP Papers is sourced from renewable forest resources and has achieved production with 0% deforestation in North America. Each ream is wrapped in a polyurethane coated paper wrapper to protect the cut sheets from moisture damage
  • Sheet size – 8.5 x 11; Thickness – 20 pounds; Brightness – 92 bright white
  • HP Copy&Print20 20 pounds printer paper is Forest Stewardship Council (FSC) certified and contributes toward satisfying credit MR1 under LEED (Leadership in Energy and Environmental Design)
  • All HP Papers provide premium performance on HP equipment, as well as on all other printer and copier equipment; 100% satisfaction guaranteed; ColorLok technology provides more vivid colors, bolder blacks and faster drying
  • Superior quality, reliability, and dependability for high-volume printing at home, at school and in the office; HP Copy&Print20 print and copy paper prevents yellowing over time to ensure a long-lasting appearance for added archival quality

Reduce peak memory before addImage

Resize to the printed result

Calculate the pixel dimensions required by the PDF’s physical size and intended output density, then draw into a smaller canvas. Keeping a 6,000 × 4,000 source for a 180 mm-wide image creates unnecessary decoded pixels. The exact suitable density depends on the document and viewer; choose it deliberately and validate visual quality.

async function resizedCanvas(source, targetWidth, targetHeight) {
  const canvas = document.createElement("canvas");
  canvas.width = targetWidth;
  canvas.height = targetHeight;
  const ctx = canvas.getContext("2d", { alpha: false });
  if (!ctx) throw new Error("2D canvas is unavailable");
  ctx.drawImage(source, 0, 0, targetWidth, targetHeight);
  return canvas;
}

async function addPhoto(doc, image) {
  await image.decode();
  const canvas = await resizedCanvas(image, 1600, 1067);
  try {
    doc.addImage(canvas, "JPEG", 15, 20, 180, 127, undefined, "MEDIUM");
  } finally {
    // Drop the pixel buffer as soon as this image is encoded.
    canvas.width = 1;
    canvas.height = 1;
  }
}

Do not retain duplicate representations

  • Do not keep the original file, decoded image, resized canvas, and data URL in long-lived arrays unless required.
  • Generate a data URL once if that is the chosen input; do not call toDataURL() repeatedly inside a loop.
  • After adding an image, remove references to temporary canvases, object URLs, and strings. Call URL.revokeObjectURL() for object URLs you created.
  • Process images sequentially so only one resize buffer is live at a time.

Prefer byte arrays for large or repeated assets

A base64 data URL is a string representation with additional encoding overhead. If your pipeline already has binary data, use a Uint8Array and pass the correct format. This is a memory-management choice, not proof that data URLs alone cause crashes.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 3 Reams (1,500 Sheets), 92 Bright White for Home Use
  • 3 ream case (1,500 sheets) of 8.5 x 11 white copier and printer paper for home or office use
  • Multipurpose letter size copy paper works with laser/inkjet printers, copiers and fax machines
  • Smooth 20lb weight paper for consistent ink and toner distribution; dries quickly and resists paper jams
  • Bright white paper (92 GE; 104 Euro) offers great contrast for crisp printing and vivid color
  • Virgin copy paper providing professional quality results; acid-free to prevent yellowing
async function addJpegBytes(doc, url, x, y, w, h) {
  const response = await fetch(url);
  if (!response.ok) throw new Error(`Image request failed: ${response.status}`);
  const bytes = new Uint8Array(await response.arrayBuffer());
  doc.addImage(bytes, "JPEG", x, y, w, h, undefined, "MEDIUM");
}

Process large exports in controlled batches

For image-heavy documents, build a page or small group, add the images, and release temporary objects before continuing. Batching does not guarantee success; compare peak memory, output size, and quality in the browsers you support.

async function makePdf(images) {
  const doc = new jsPDF({ unit: "mm", format: "a4" });
  for (let i = 0; i < images.length; i++) {
    if (i > 0) doc.addPage();
    const img = await loadImage(images[i]);
    const canvas = await resizedCanvas(img, 1400, 900);
    doc.addImage(canvas, "JPEG", 15, 20, 180, 116, undefined, "MEDIUM");
    canvas.width = 1;
    canvas.height = 1;
    // Let the event loop run between expensive iterations.
    await new Promise(requestAnimationFrame);
  }
  return doc;
}

function loadImage(src) {
  return new Promise((resolve, reject) => {
    const img = new Image();
    img.onload = () => resolve(img);
    img.onerror = () => reject(new Error(`Could not decode ${src}`));
    img.src = src;
  });
}

If a single image still fails after resizing, isolate it in a minimal page and test another supported representation. If only the complete HTML-to-PDF route fails, reduce concurrent canvas creation or use a rendering architecture that does not retain every intermediate canvas.

Rank #4
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 5 Reams (2,500 Sheets), 92 Bright White
  • 5 ream case (2,500 sheets) of 8.5 x 11 white copier and printer paper for home or office use
  • Multipurpose letter size copy paper works with laser/inkjet printers, copiers and fax machines
  • Smooth 20lb weight paper for consistent ink and toner distribution; dries quickly and resists paper jams
  • Bright white paper (92 GE; 104 Euro) offers great contrast for crisp printing and vivid color
  • Virgin copy paper providing professional quality results; acid-free to prevent yellowing

Check version and security information

Do not assume upgrading alone fixes this crash. A historical report describes PNG rendering problems in jsPDF 2.4.0 and 2.5.0, but it does not establish that those versions cause the browser crash here or that a particular current version resolves it (issue 3359). Check the project’s current release notes and the CVE-2026-25535 advisory when files can be supplied by users. Validate dimensions before decoding GIFs and reject implausibly large or malformed inputs according to limits appropriate for your application.

Common errors and fixes

Symptom Likely cause Action
addImage throws immediately Unsupported value or failed format detection Confirm the input is an allowed type and pass "JPEG", "PNG", or the actual format explicitly.
Tab slows, then crashes Peak decoded/canvas memory Resize, process sequentially, clear temporary canvases, and test smaller batches.
PDF is huge but browser survives Large pixels or inefficient encoding Reduce dimensions, choose an appropriate JPEG quality/compression setting, and compare output quality.
Blank or partially rendered image Image not decoded, cross-origin restrictions, or canvas state lost Await decode(), configure CORS where permitted, and verify canvas dimensions before adding.
Only user-uploaded GIFs fail Potential malicious dimensions Validate dimensions and consult current advisory/version guidance before decoding.
Failure appears after an update Version-specific behavior Record the exact version, reproduce with a minimal case, and check jsPDF’s issue tracker and release information.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your goal is a clean screenshot or PDF rather than client-side PDF assembly, ScreenshotNeo provides a website screenshot API. A single request can return PNG, JPEG, WebP, or PDF, avoiding a browser tab full of canvases:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
HP Printer Paper | 8.5 x 11 Paper | Office 20 lb | 3 Ream Case - 1500 Sheets | 92 Bright | Made in USA - FSC Certified | 112090C, White
  • Made in USA: HP Papers is sourced from renewable forest resources and has achieved production with 0% deforestation in North America.
  • Optimized for HP technology: All HP Papers provide premium performance on HP equipment, as well as on all other printer and copier equipment.
  • Perfect everyday office paper: Superior quality, reliability, and dependability for high-volume printing at home, at school and in the office. Perfect for everyday black and white printing.
  • Certified sustainable: HP Office20 20lb printer paper is Forest Stewardship Council (FSC) certified and contributes toward satisfying credit MR1 under LEED (Leadership in Energy and Environmental Design).
  • ColorLok technology printing paper: ColorLok technology provides more vivid colors, bolder blacks and faster drying.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo documentation for all options. Before capture it accepts cookie/consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing result. It also offers an MCP server with take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.

How to choose a safer architecture

  • Client-side jsPDF: suitable when the user must generate a PDF locally and images are modest; keep dimensions and concurrency bounded.
  • Server-side rendering: useful when exports are large or must be consistent across browsers; enforce upload limits and isolate untrusted decoding.
  • Screenshot/PDF API: useful when the source is a URL and you want capture controls such as full-page lazy-image loading, CSS selectors, custom JavaScript, waiting rules, blocking, device presets, and asynchronous jobs without maintaining browser automation.

Evaluate any architecture with the same measurements: peak memory in target browsers, concurrent image count and pixel dimensions, PDF/image size, visual quality, export time, and whether inputs can be attacker-controlled. The published jsPDF evidence supplies no comparative benchmark, so measure your own representative documents.

Frequently Asked Questions

Is there a maximum image size that always crashes jsPDF?

No reliable universal pixel threshold or browser-memory limit has been established. Limits vary with browser, device, image count, format, and other live allocations.

Should I convert every image to a data URL?

No. jsPDF accepts several representations. Use the form that fits your pipeline, avoid duplicate copies, and provide the format explicitly when recognition may fail.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Does a larger PDF prove a memory leak?

No. Output size and peak working memory are different measurements; a historical large-file report does not establish a universal cause.

Quick Recap

Bestseller No. 1
Amazon Basics Multipurpose Copy Printer Paper, 8.5 x 11 Inches, 20 lb, 92 Bright, White, 1 Ream (500 Sheets), Jam-Free
Amazon Basics Multipurpose Copy Printer Paper, 8.5 x 11 Inches, 20 lb, 92 Bright, White, 1 Ream (500 Sheets), Jam-Free
1 ream (500 sheets) of 8.5 x 11 white copier and printer paper for home or office use; Virgin copy paper providing professional quality results; acid-free to prevent yellowing
$6.97
Bestseller No. 2
HP Printer Paper | 8.5 x 11 Paper | Copy &Print 20 lb | 1 Ream Case - 500 Sheets| 92 Bright | FSC Certified | 200060
HP Printer Paper | 8.5 x 11 Paper | Copy &Print 20 lb | 1 Ream Case - 500 Sheets| 92 Bright | FSC Certified | 200060
Sheet size – 8.5 x 11; Thickness – 20 pounds; Brightness – 92 bright white
$6.97
Bestseller No. 3
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 3 Reams (1,500 Sheets), 92 Bright White for Home Use
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 3 Reams (1,500 Sheets), 92 Bright White for Home Use
Virgin copy paper providing professional quality results; acid-free to prevent yellowing
$23.99
Bestseller No. 4
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 5 Reams (2,500 Sheets), 92 Bright White
Amazon Basics Multipurpose Copy Printer Paper, 20 lb, 8.5 x 11 Inches, 5 Reams (2,500 Sheets), 92 Bright White
Virgin copy paper providing professional quality results; acid-free to prevent yellowing
$34.85

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.