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

Overlapping text in jsPDF is almost always a layout-calculation problem: a paragraph wrapped to more lines than your code allowed for, but the next block still uses a fixed one-line y increment. Wrap text with splitTextToSize(), set the font and size before measuring, use a line-height factor that matches your design, and advance the next block by the actual number of rendered lines. Also keep coordinates, widths, and font metrics in the same document units.

Why jsPDF text overlaps

Each doc.text() call is positioned independently. jsPDF does not automatically reserve vertical space for a paragraph unless you provide multiline content and appropriate spacing. A common pattern such as y += 10 works for a single line, then fails when a longer string wraps to three or four lines. The following block is still placed only 10 units lower, so it is drawn over the paragraph.

Other causes include using a width measured in pixels with a document configured in millimetres, changing the font after measuring, setting a very small line-height factor, or asking a standard PDF font to render characters it does not contain. Fix the underlying layout data rather than trying random y offsets.

The reliable fix: wrap first, then calculate the next y position

  1. Select the font and size. Font metrics affect both wrapping and visual height, so do this before measuring text.
  2. Define the available width in the units used by the jsPDF instance.
  3. Call splitTextToSize(text, maxWidth). It returns an array containing the lines that fit the width.
  4. Render the array in one text() call and pass a deliberate lineHeightFactor.
  5. Advance the cursor using the line count. Add a small gap before placing the next block.

The official API documents a default lineHeightFactor of 1.15. A value such as 1.25 or 1.3 is often easier to read, but the right value depends on your font and design. The documented default for a maxWidth option is 0, which means no automatic splitting through that option; explicitly wrapping is safer for predictable layouts.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Complete working example (millimetres)

import jsPDF from "jspdf";

const doc = new jsPDF({ unit: "mm", format: "a4" });
doc.setFont("helvetica", "normal");
doc.setFontSize(12);

const margin = 15;
const pageWidth = doc.internal.pageSize.getWidth();
const contentWidth = pageWidth - margin * 2;
const lineHeightFactor = 1.3;
const paragraph = "A long paragraph can wrap onto several lines. The next block must be placed after every one of those lines, not after an assumed single line.";

const lines = doc.splitTextToSize(paragraph, contentWidth);
const startY = 30;
doc.text(lines, margin, startY, { lineHeightFactor });

// jsPDF font size is in points; convert the line step to the document's mm units.
const lineStep = (12 * lineHeightFactor) / 72 * 25.4;
const gap = 4;
const nextY = startY + lines.length * lineStep + gap;
doc.text("This heading now starts below the complete paragraph.", margin, nextY);

doc.save("no-overlap.pdf");

This is an implementation pattern, not a universal metric for every font. Inspect the PDF after changing the font, size, width, unit, alignment, or line-height. The conversion above is appropriate for a millimetre document because jsPDF font sizes are specified in points; if you create the document in inches or points, calculate the step in those units instead of copying the millimetre conversion.

Keep wrapping and coordinates in the same units

The x and y coordinates use the unit selected in new jsPDF({ unit: ... }). splitTextToSize() also expects its width in the instance’s default units. For example, with unit: "mm", margins and maxWidth must be millimetres. Do not subtract a pixel margin from a millimetre page width.

const doc = new jsPDF({ unit: "in" });
const margin = 0.6;                 // inches
const width = doc.internal.pageSize.getWidth() - margin * 2;
const lines = doc.splitTextToSize(text, width);

If the text appears unexpectedly narrow or extends into a margin, log the page width, margin, and calculated content width. Also check that you did not pass a page-width value from a different document instance.

Three ways to control multiline text

Explicit splitTextToSize() plus manual positioning

This gives the most control. You know the exact line array, can calculate the block height, and can decide when to add a page. It is the best choice for invoices, reports, and mixed content where later elements depend on the paragraph height.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Pass a width to text()

The text() API accepts an array of strings for multiline output and supports options such as maxWidth and lineHeightFactor. This can be convenient for a small, fixed block. You still need to account for the resulting line count when positioning content that follows; do not assume the call consumed one line.

const lines = doc.splitTextToSize(description, 90);
doc.text(lines, 20, 40, { lineHeightFactor: 1.2 });

Use a higher-level layout or table plugin

For tables or repeated rows, a layout plugin can calculate row positions for you. The official material documents the core wrapping and text mechanisms, but it does not establish a particular plugin recommendation. Verify the plugin’s pagination and font behavior against your installed jsPDF version before adopting it.

Preventing overlap across multiple blocks

Maintain a cursor and return the new cursor position from a helper. This avoids scattered magic numbers.

function addParagraph(doc, text, x, y, width, options = {}) {
  const fontSize = options.fontSize ?? 11;
  const lineHeightFactor = options.lineHeightFactor ?? 1.25;
  const gap = options.gap ?? 3;

  doc.setFont(options.font ?? "helvetica", options.style ?? "normal");
  doc.setFontSize(fontSize);
  const lines = doc.splitTextToSize(text, width);
  doc.text(lines, x, y, { lineHeightFactor });

  // For a document configured in millimetres.
  const lineStep = (fontSize * lineHeightFactor) / 72 * 25.4;
  return y + lines.length * lineStep + gap;
}

let y = 25;
y = addParagraph(doc, firstParagraph, 15, y, 180);
y = addParagraph(doc, secondParagraph, 15, y, 180);

If your document uses a unit other than millimetres, replace the conversion with the corresponding points-to-unit conversion. Keep this conversion in one helper so it cannot drift between sections.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Handle page boundaries before drawing

A correctly calculated paragraph can still run off the bottom of a page. Before rendering a block, estimate its height from the line count and compare the final y position with the page’s bottom margin.

function ensureSpace(doc, y, lineCount, lineStep, bottomMargin = 15) {
  const pageHeight = doc.internal.pageSize.getHeight();
  const required = lineCount * lineStep;
  if (y + required > pageHeight - bottomMargin) {
    doc.addPage();
    return 20; // top margin on the new page, in the document's units
  }
  return y;
}

const lines = doc.splitTextToSize(paragraph, contentWidth);
const lineStep = (12 * 1.3) / 72 * 25.4;
y = ensureSpace(doc, y, lines.length, lineStep);
doc.text(lines, margin, y, { lineHeightFactor: 1.3 });

For a block that must stay together, check its full height before drawing. For long content, split it into page-sized chunks and repeat headers or other elements deliberately. Do not place the first half, discover the overflow afterward, and then attempt to move already-rendered text.

When lines inside one text array look too close

An array passed to text() is rendered as multiline text. The API shifts each line according to the active font spacing settings. Set lineHeightFactor in the same call and ensure the font size was set immediately before it.

doc.setFontSize(10);
doc.text(lines, 15, 40, { lineHeightFactor: 1.35 });

If lines still collide, check for a later setFontSize() call, a very large font with a small factor, or a custom font whose visual metrics differ from the default font. Increasing line height fixes vertical crowding; it does not fix incorrect wrapping or overlapping separate blocks.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Fix long lines and margin collisions

splitTextToSize() wraps according to the selected font’s width and kerning tables where available. Set maxWidth to the actual content width, not the page width, and account for both margins, indents, and any column gap.

  • Calculate contentWidth = pageWidth - leftMargin - rightMargin.
  • Use the same unit for page width, margins, and maxWidth.
  • Measure again after changing font family, style, or size.
  • For columns, subtract the gutter before splitting each column’s text.

Words with no break points, such as very long URLs, may still require special handling. Insert an intentional break, shorten the displayed label, or render the URL in a smaller dedicated area rather than allowing it to run through a neighboring column.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Fonts, UTF-8, and “garbled” text

Spacing adjustments cannot repair missing glyphs. jsPDF’s README notes that its 14 standard PDF fonts are limited to ASCII. Accented characters, non-Latin scripts, emoji, and many symbols require a TTF font containing those glyphs.

  1. Obtain a TTF font with the required character coverage and licensing.
  2. Convert and register it using the jsPDF font-vFS workflow described in the project documentation.
  3. Call setFont() and setFontSize() before wrapping.
  4. Re-run splitTextToSize() after selecting the custom font, because its widths differ from Helvetica or another standard font.

A fallback font can change line lengths and therefore every downstream y coordinate. Treat a font change as a layout change, not merely a visual substitution.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Debugging checklist

  • Log every block: print its starting y, line count, line step, and calculated ending y.
  • Draw temporary guides: render a light rectangle for the content width and a horizontal line at each computed baseline.
  • Confirm call order: font, size, wrapping, and rendering should occur in that order.
  • Check the active page: a block may be drawn on a different page than the one whose dimensions you used.
  • Inspect the generated PDF: viewers can have different zoom and font-rendering behavior; compare at 100% and after printing.
  • Lock the jsPDF version: if behavior differs from the current API reference, consult the documentation matching your installed version.

Common symptoms, causes, and fixes

Symptom Likely cause Fix
Next paragraph covers the previous one Fixed y increment after wrapped text Use the returned line count and calculated line step.
Text runs into the right margin maxWidth is missing, too large, or in another unit Compute available width in the document’s configured unit and pass it to splitTextToSize().
Lines in one array touch Line-height factor is too small or font size changed Set lineHeightFactor explicitly and verify the active font size.
Accents or symbols appear as boxes Standard font lacks the glyphs Embed a suitable TTF and wrap after selecting it.
Layout changes after a font update Different glyph widths changed wrapping Re-measure every paragraph and regenerate page-break decisions.
Content disappears below the page No bottom-margin or page-break check Estimate block height before drawing, then add a page when needed.

Or skip the browser setup

If your goal is a clean image or PDF of a web page rather than a locally generated jsPDF document, ScreenshotNeo provides a single screenshot API request. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be disabled. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the result with X-Page-Verdict and X-Billed headers. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients.

See the ScreenshotNeo API documentation for all options. A cURL request:

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}`);

The Free plan includes 1,000 screenshots each month with no card. Paid plans start at $5 for 3,000 screenshots, and every feature is included on every plan. Create a free ScreenshotNeo account.

FAQ

Frequently Asked Questions

Does jsPDF automatically wrap text passed as one long string?

Not reliably for your layout unless you provide a width or create wrapped lines yourself. Explicitly call splitTextToSize() when subsequent positions depend on the paragraph height.

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

Should I use a larger font or a larger line-height factor?

Use line-height to separate baselines when lines within one block collide. Use font size for typography. Changing either requires rewrapping and recalculating later y positions.

Why does the same code overlap only with some languages?

Different glyph widths and missing characters change wrapping. Standard jsPDF fonts cover ASCII only; embed a TTF with the needed UTF-8 glyphs, then measure with that font active.

Can I fix overlap by adding a fixed 20-unit gap after every paragraph?

Only if every paragraph is guaranteed to be one line. A fixed gap must be added after the calculated height, not used instead of it.

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.

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