Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
In jsPDF, image size is controlled in the PDF document’s units—not automatically in CSS pixels. For a direct image, pass x, y, width, and height to addImage(). For HTML conversion with doc.html(), set the target width and position in jsPDF units, and coordinate those values with html2canvas’s scale and windowWidth options.
The reliable workflow is: choose the page format and unit system, calculate the available content box, preserve the source aspect ratio, then check pagination and cross-origin loading.
Understand the two size systems
HTML-to-PDF workflows involve at least two coordinate systems:
- PDF placement units: millimeters, points, inches, or another unit selected when creating the jsPDF instance.
addImage()uses these units for position and size. - Canvas pixels: html2canvas renders HTML into a pixel-based canvas. Its pixel width and height are not automatically equivalent to millimeters, points, or inches in the PDF.
Confusing these systems is the main reason an image appears unexpectedly large, tiny, stretched, or clipped.
#1 Best Overall
- INNOVATIVE CARTRIDGE-FREE PRINTING — No more dealing with lots of tiny ink cartridges; With this wireless document and photo printer each ink bottle set is equivalent to about 90 individual cartridges²
- LESS FREQUENT INK REPLACEMENT — Replacement ink bottles don't have to be changed nearly as often as ink cartridges¹; When you choose this combination printer, scanner and copier you can print up to 4,500 pages black/7,500 color³
- COLOR PRINTING — Up to 2 years of ink in the box4 (and with every replacement ink set) for fewer out-of-ink frustrations
- ZERO CARTRIDGE WASTE — By using an Epson EcoTank printer you can help reduce the amount of cartridge waste ending up in landfills
- HOME PRINTER DESIGNED FOR RELIABILITY — The Epson EcoTank ET-2800 All-in-One Supertank Color Printer creates vivid, detailed prints and documents thanks to Micro Piezo Heat-Free Technology; Fire off 10 ISO pages per minute1 to easily finish large jobs
Choose the page and unit system first
Create the document with the paper format, orientation, and units you intend to use. jsPDF defaults to A4 portrait with millimeter units, but you can select another orientation, unit, or custom page format.
import { jsPDF } from "jspdf";
const doc = new jsPDF({
orientation: "portrait",
unit: "mm",
format: "a4"
});
Every later image measurement must use the same unit. If the document uses pt, a width of 200 means 200 points; it does not mean 200 CSS pixels.
Set an image size with addImage()
The direct API is doc.addImage(imageData, format, x, y, width, height, ...). The API accepts data URLs and image, canvas, or buffer forms. x and y measure from the page’s left and top edges; width and height are in the configured PDF units.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteconst imageData = "data:image/png;base64,...";
doc.addImage(
imageData,
"PNG",
20, // x in mm
30, // y in mm
170, // width in mm
95 // height in mm
);
doc.save("image.pdf");
The method description in the jsPDF API is straightforward: it “Adds an Image to the PDF.” Because the API receives both dimensions, it will use exactly the rectangle you provide. It does not infer a proportional height for you.
Preserve the image’s aspect ratio
To avoid distortion, derive one dimension from the other and the image’s intrinsic dimensions:
targetHeight = intrinsicHeight × targetWidth ÷ intrinsicWidth
getImageProperties() can provide the intrinsic width and height for image data. The following pattern fits an image between left and right margins while retaining its proportions.
Free tools Windows power users keep installed
One-click scans. No signup required.
Rank #2
- CARTRIDGE-FREE PRINTING — Print lab-quality photos, graphics and creative projects; Get vibrant colors and sharp text with Epson's high-accuracy printhead and Claria ET Premium 6-color inks
- INK BOTTLES — Save on photos1 and creative projects with affordable in-house printing; All-in-one printer allows you to print 4" x 6" photos for about 4 cents each vs. 40 cents with traditional ink cartridges1
- LESS FREQUENT INK REPLACEMENT — Replacement ink bottles don't have to be changed nearly as often as ink cartridges¹; Printer, scanner and copier lets you print up to 6,200 color pages³
- PRINT FOR LONGER — Up to 2 years of ink in the box² (and with every replacement ink set) for fewer out-of-ink frustrations with this wireless printer
- ZERO CARTRIDGE WASTE — Epson EcoTank printer helps reduce the amount of cartridge waste ending up in landfills; Cartridge-free printer uses high-yield ink bottles; Each replacement ink bottle set is equivalent to about 100 individual ink cartridges⁴
const leftMargin = 20;
const rightMargin = 20;
const top = 30;
const pageWidth = doc.internal.pageSize.getWidth();
const targetWidth = pageWidth - leftMargin - rightMargin;
const props = doc.getImageProperties(imageData);
const targetHeight = (props.height * targetWidth) / props.width;
doc.addImage(
imageData,
"PNG",
leftMargin,
top,
targetWidth,
targetHeight
);
This is an aspect-ratio calculation, not a special automatic sizing mode. If you instead know the desired height, calculate targetWidth = intrinsicWidth × targetHeight ÷ intrinsicHeight.
Keep the result inside the page
Fitting the width does not guarantee that the image fits vertically. Calculate the usable height from the page height and your top and bottom margins:
const pageHeight = doc.internal.pageSize.getHeight();
const bottomMargin = 20;
const availableHeight = pageHeight - top - bottomMargin;
let width = targetWidth;
let height = targetHeight;
if (height > availableHeight) {
height = availableHeight;
width = (props.width * height) / props.height;
}
doc.addImage(imageData, "PNG", leftMargin, top, width, height);
If the image is taller than one page even after scaling, choose a policy explicitly: scale it to one page, crop it, or split it across pages. A single addImage() call does not make one oversized image flow naturally through multiple pages.
Size HTML rendered with doc.html()
When the source is a DOM element, doc.html(element, options) renders the element through html2canvas and places the result in the PDF. Its documented x, y, and target width are jsPDF units.
const element = document.querySelector("#invoice");
const doc = new jsPDF({
unit: "mm",
format: "a4",
orientation: "portrait"
});
doc.html(element, {
x: 15,
y: 15,
width: 180,
autoPaging: "text",
html2canvas: {
useCORS: true,
windowWidth: element.scrollWidth
},
callback: (pdf) => pdf.save("invoice.pdf")
});
The width option is connected to html2canvas configuration. jsPDF’s documentation warns that the target width has no effect when html2canvas.scale is specified or when windowWidth is not specified. Treat these as one layout configuration: set the viewport you want html2canvas to reproduce, set a PDF target width, and verify the output with the jsPDF version installed in your project.
Do not equate CSS pixels with PDF units
Your element may be 1200 pixels wide in the browser while the PDF target is 180 mm. html2canvas’s canvas dimensions remain pixels; the final placement width remains millimeters (or whichever unit you chose). Changing scale changes rasterization density, not the meaning of the PDF’s placement units.
Control image quality and file size
Rendering scale and image encoding affect sharpness and output size independently of placement dimensions. A larger html2canvas scale can create a denser raster image, but it can also increase memory use and PDF size. JPEG, PNG, and WebP have different size and transparency characteristics; a wrapper such as html2pdf.js exposes encoding and quality controls, but those controls belong to that wrapper and should not be treated as guarantees for every direct doc.html() configuration.
Rank #3
- SET IT UP ONCE AND PRINT WITH CONFIDENCE. No complicated maintenance. Just easy, reliable printing you can count on.
- INK FOR YEARS. NOT MONTHS. Up to 2 years of ink included. Get thousands of pages of cartridge-free printing. More pages, less hassle
- KEEPS PRINTING WELL AFTER COMPETITORS HAVE QUIT. No complex maintenance. Sharper text, richer colors.[2] Only with HP Smart Tank
- PREMIUM SUPPORT - Strong technical expertise to solve issues faster
- THE LAST PRINTER YOU'LL EVER NEED. Enjoy years of refillable, cartridge-free printing.
Use PNG when lossless detail or transparency matters. Consider JPEG for photographic content when transparency is unnecessary. Choose a scale high enough for the intended viewing or printing size, then test memory use on your largest page.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Choose between html() and addImage()
| Approach | Best for | Size control | Trade-offs |
|---|---|---|---|
doc.html() |
Capturing a DOM element’s layout | Target width, x, and y in jsPDF units, coordinated with html2canvas options |
Rendering depends on browser layout, cross-origin access, canvas limits, and the installed version |
addImage() |
Placing a known image precisely | Explicit x, y, width, and height |
You must calculate aspect ratio and pagination yourself |
| html2pdf.js wrapper | Convenient page-break controls around HTML capture | Wrapper options for page breaks, image type, and quality | It rasterizes rendered content and documents canvas and output-size limitations |
Make cross-origin images render
An image can have correct dimensions and still be blank. Browser security rules may prevent html2canvas from reading pixels hosted on another origin. The html2canvas options include useCORS and proxy, but success depends on the source server’s headers and your browser environment.
- Serve images with appropriate cross-origin permissions.
- Try
useCORS: truewhen the image server permits it. - Use a proxy only when you control or trust that proxy and understand its caching and security behavior.
- Wait until images have loaded before calling
doc.html().
Troubleshooting common sizing failures
The image is much too large or too small
Check the document’s unit and the values passed to addImage(). A canvas width in pixels is not automatically a width in millimeters, points, or inches. Convert or calculate dimensions in the document’s configured units.
html() ignores my width
Review whether you explicitly set html2canvas.scale and whether windowWidth is present. The jsPDF documentation ties target-width behavior to these options. Remove an unnecessary scale override, provide the intended window width, and retest with your installed version.
The image is stretched
You supplied width and height that do not share the source aspect ratio. Read intrinsic dimensions with getImageProperties() and derive the second dimension rather than hard-coding unrelated values.
The image is clipped or runs off the page
Compare the final rectangle with doc.internal.pageSize.getWidth() and getHeight(), subtracting all margins. For HTML, inspect the rendered element’s width and the selected autoPaging behavior. Decide whether to scale, crop, or paginate; do not assume an oversized image will flow automatically.
The PDF is blank or an image is missing
Check that the source data is valid, that the image has finished loading, and that cross-origin access is allowed. For HTML conversion, confirm html2canvas is available as the optional rendering dependency and inspect browser console errors.
Rank #4
- Wireless Bluetooth Printer: Portable thermal printer compatible with iPhone, Android phones, iPad and tablet computers via Bluetooth. For smartphones, please download the "Nada Print" App. You can also connect to laptops and computers for printing using a USB-C cable. (Note: Laptops and computers can only be connected via USB and require the installation of a driver first. Bluetooth connection is not supported.)
- No-ink printing: Only supports US Letter and A4 size thermal paper.(Doesn't support regular paper) The no-ink portable thermal printer uses direct thermal technology, requiring no ink, toner or ribbons, making it environmentally friendly, cost-effective and time-saving. The thermal printer package comes with a roll of US Letter thermal printing paper. Note: When installing the paper, remember to switch the paper size switch on APP
- Clear Print: NDYIN N80 portable thermal printer adopts high-definition printing technology, with a 203DPI resolution to provide you with clear printing results. This mobile printer is compatible with roll paper, folded paper and tattoo transfer paper, supporting printing from your mobile phone PDF, Word, pictures and web pages anytime and anywhere. It is recommended to use our NDYIN thermal paper to achieve good printing quality
- Portable wireless printer for travel: The thermal printer is equipped with a built-in 1500mAh rechargeable battery, which can print 160 sheets of 8.5" x 11" thermal paper after being fully charged. It weighs only 1.5 pounds and is compact in size. This ink-free portable printer can be easily carried in a backpack or briefcase! It is perfect for business travel, cars, small offices, construction sites, schools and homes. You can print documents, contracts, invoices and boarding passes anytime and anywhere
- The N80 thermal printer has a wide range of uses. The package includes the N80 printer, a roll of US Letter paper(7m/roll), a user manual, a guide card, a type-C soft cable and a type C adapter. Note: The charging adapter is not included. Special thermal paper is required for use; ordinary paper cannot be used. This ink-free portable thermal printer is suitable for various scenarios such as home, school, travel, office, and outdoor, meeting the printing needs of different groups of people. This tattoo template printer is also compatible with tattoo transfer paper, making it an ideal choice for tattoo art
The output is blurry or unexpectedly large
Adjust rendering scale and encoding separately from placement width. Higher scale can improve detail while increasing memory and file size. Choose PNG, JPEG, or WebP according to transparency and photographic-detail needs, and test the largest document your users will generate.
Or skip the browser setup
If your goal is a clean screenshot or PDF of a web page rather than a client-side jsPDF workflow, ScreenshotNeo provides a single HTTP request. Its capture pipeline accepts cookie and consent banners like a visitor, then removes more than 60 known consent platforms, newsletter popups, and chat widgets before the shot. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteUse the API with your target URL (replace it as needed):
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Python:
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
Node.js:
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
See the complete parameter reference in the ScreenshotNeo documentation. It also offers an MCP server so Claude, Cursor, and other MCP clients can call take_screenshot, get_page_info, and capture_pdf. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Create a free ScreenshotNeo account to start.
Frequently Asked Questions
Can jsPDF automatically keep an image’s proportions?
No. Because addImage() accepts both width and height, calculate one dimension from the other using the source image’s intrinsic aspect ratio.
Should I size an image in pixels or millimeters?
Use the PDF document’s configured units for addImage() and html() placement. Pixels describe the html2canvas raster and are a separate concern.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Why does html2canvas scale change sharpness but not my PDF width?
Scale changes the rasterization density of the canvas. The PDF placement width is still controlled by the jsPDF target width and unit system.
When should I use a wrapper such as html2pdf.js?
Use it when its page-break and encoding conveniences outweigh rasterization, selectable-text, canvas-size, and output-file trade-offs for your document.
Quick Recap
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.

