October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
Canvas

How to Remove Top and Bottom Borders From jsPDF Pages

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

Export the canvas as PNG, not JPEG, and pass 'PNG' to addImage. In the documented html2canvas/canvg/jsPDF pipeline, the web page and source canvas had no lines, but JPEG data URLs produced black-looking strips at the top and bottom of each PDF image. A transparent PNG removed the artifact. If a line remains after that change, check image geometry and any separate PDF drawing commands.

Why borders can appear only in the PDF

The rendering pipeline has three different stages:

Stage What it does What to inspect
HTML and SVG Provides the page content, often rendered by html2canvas or canvg. Look for an actual CSS border, SVG stroke, or background line.
Canvas export canvas.toDataURL() encodes pixels as an image. Compare PNG and JPEG exports in an image viewer.
jsPDF placement doc.addImage() decodes and positions the image on a PDF page. Check format, coordinates, dimensions, clipping, and other drawing calls.

The reported case used canvas.toDataURL('image/jpeg', 1.0) and then addImage(..., 'JPEG', ...). The accepted troubleshooting answer identified JPEG handling of transparency as the likely source: transparent pixels can become a black background or edge during encoding. Replacing the export with a transparent PNG fixed the visible top and bottom lines. This is a pipeline artifact, not something that border: none on the canvas can remove.

The published example dates from 2017–2018 and involved Internet Explorer 10/11 support. It does not establish that every current browser, jsPDF release, image viewer, or image format reproduces the same defect. Reproduce the smallest example in the browser and library versions you actually ship.

The minimal code change

Change both the data URL and the type passed to jsPDF. Keep your existing page loop:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Adobe Acrobat Pro | PDF Software | Convert, Edit, E-Sign, Protect | PC/Mac Online Code | Activation Required
  • Create and edit PDFs. Collaborate with ease. E-sign documents and collect signatures. Get everything done in one app, wherever you go.
  • Edit text and images without jumping to another app.
  • E-sign documents or request e-signatures on any device. Recipients don’t need to log in to e-sign.
  • Convert PDFs to editable Microsoft Word, Excel, or PowerPoint documents.
  • Share PDFs for collaboration. Commenting features make it easy for reviewers to comment, mark up, and annotate.
const canvasImg = canvas.toDataURL('image/png');
if (i !== 0) doc.addPage();
doc.addImage(canvasImg, 'PNG', 15, 0, imgWidth, imgHeight);

Do not export PNG and label it 'JPEG', or export JPEG and label it 'PNG'. jsPDF must receive the matching image type. A transparent PNG is particularly useful when the canvas contains transparent areas or when its background is not deliberately painted.

A complete browser example

This example assumes html2canvas and jsPDF are loaded on the page and that sections contains the elements you want to capture. It calculates a width that fits the selected page and keeps the image ratio instead of allowing an accidental edge overflow.

async function exportSectionsToPdf(sections) {
  const { jsPDF } = window.jspdf;
  const doc = new jsPDF({ unit: 'mm', format: 'a4', orientation: 'portrait' });
  const margin = 15;
  const pageWidth = doc.internal.pageSize.getWidth();
  const pageHeight = doc.internal.pageSize.getHeight();
  const usableWidth = pageWidth - margin * 2;
  const usableHeight = pageHeight - margin * 2;

  for (let i = 0; i < sections.length; i += 1) {
    const canvas = await html2canvas(sections[i]);
    const imageData = canvas.toDataURL('image/png');
    const ratio = canvas.height / canvas.width;
    const imageWidth = usableWidth;
    const imageHeight = imageWidth * ratio;

    if (i !== 0) doc.addPage();

    // This example places one captured section per page.
    // A very tall section needs its own pagination strategy.
    const height = Math.min(imageHeight, usableHeight);
    doc.addImage(imageData, 'PNG', margin, margin, imageWidth, height);
  }

  doc.save('export.png.pdf');
}

The filename in save() can be changed to any PDF filename. If you already calculate imgWidth and imgHeight, retain those values while making the PNG/type change first; geometry should be debugged separately.

Check page geometry before changing more code

A genuine image edge can look like a border when it is clipped at the page boundary. Check all four values used by addImage:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Acrobat Pro | 1-Month Subscription | PDF Software |Convert, Edit, E-Sign, Protect |Activation Required [PC/Mac Online Code]
  • Create and edit PDFs. Collaborate with ease. E-sign documents and collect signatures. Get everything done in one app, wherever you go.
  • Edit text and images without jumping to another app.
  • E-sign documents or request e-signatures on any device. Recipients don’t need to log in to e-sign.
  • Convert PDFs to editable Microsoft Word, Excel, or PowerPoint documents.
  • Share PDFs for collaboration. Commenting features make it easy for reviewers to comment, mark up, and annotate.
  • x and y: A y-coordinate of 0 deliberately puts the image against the top edge. Use a margin while testing.
  • width and height: If the height extends beyond the usable page height, the last row of pixels can be clipped or rendered differently by a viewer.
  • page format and orientation: The dimensions must be calculated from the same page size and orientation passed to the jsPDF constructor.
  • pixel-to-unit conversion: Keep the aspect ratio from the canvas. Stretching a raster image can make a one-pixel edge more conspicuous.

As a diagnostic, place the image at (15, 15) with dimensions comfortably inside the page. If the line disappears, restore your intended placement in smaller increments.

Make sure the line is not a separate PDF drawing

Temporarily comment out every operation that can draw a rule or frame:

  • doc.rect() and doc.line()
  • table borders or cell styles from a PDF table helper
  • header and footer routines
  • page backgrounds, separators, or decorative SVGs

Generate a PDF containing only addImage. If the lines remain, compare the PNG data URL itself with the PDF. If the PNG already contains them, inspect the canvas rendering or the SVG supplied to canvg. If the PNG is clean but the PDF is not, verify the image type string, placement, and the jsPDF version in the target browser.

A practical debugging sequence

  1. Save the canvas as canvas.toDataURL('image/png') and inspect that image at 100% zoom.
  2. Pass the resulting string to doc.addImage(imageData, 'PNG', ...).
  3. Keep doc.addPage() before every page after the first; do not add a page before the first image unless your layout requires it.
  4. Use a visible margin and dimensions that fit inside the page.
  5. Remove rectangles, lines, table borders, headers, footers, and backgrounds until only the image remains.
  6. Open the PDF at 100% in more than one viewer. Viewer interpolation can make a one-pixel edge look heavier than it is.
  7. Only after the minimal PNG case is clean, re-enable custom drawing and your original page geometry one item at a time.

PNG versus JPEG for this workflow

Choice Transparency behavior Use when Risk in the reported case
PNG Preserves transparent pixels. The canvas has transparency, sharp text, line art, or you are diagnosing an encoding artifact. The accepted fix used this format.
JPEG Does not preserve transparency and may introduce a black-looking background or edge when transparent canvas pixels are encoded. You have an intentionally opaque photographic canvas and have verified the output in your target browsers. It was the format used when the top and bottom strips appeared.

PNG files can be larger for photographic content, so measure your own documents before changing formats for production. Correctness comes first: a smaller JPEG is not a win if it adds visible rules to every page.

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
PDF Extra Lifetime - Professional PDF Editor - Best Adobe Acrobat Pro Alternative - Lifetime License for Windows PC
  • Perfect Adobe Acrobat Pro alternative – lifetime license for Windows 10 and 11.
  • EDIT text, images, pages, hyperlinks, designs in PDF documents. ORGANIZE PDFs.
  • READ and Comment on PDFs – Intuitive reading modes & document commenting and mark up tools!
  • CREATE, COMBINE, SCAN and COMPRESS PDFs.
  • FILL forms & Digitally Sign PDFs. Work with Digital certificates

Browser and library compatibility

The documented issue was filed for Internet Explorer 11, with Internet Explorer 10+ support required, and used an older html2canvas/canvg/jsPDF combination. Treat that as a compatibility clue rather than a universal diagnosis. Record the browser, jsPDF version, html2canvas version, canvas dimensions, image format, and PDF viewer when reporting a reproduction. Then test a minimal canvas with no application CSS. A current browser may expose a different problem, such as an actual SVG stroke or a page-edge clipping error.

Performance and reliability considerations

  • Memory: A full-page canvas is an uncompressed bitmap in memory before it becomes a PNG or JPEG. Capture one page at a time and release references to canvases that are no longer needed.
  • Long pages: Do not simply shrink an extremely tall canvas to one PDF page; text may become unreadable and the bottom may be clipped. Split content into page-sized canvases or implement explicit pagination.
  • Determinism: Wait for fonts, images, and asynchronous SVG rendering before exporting. A partially rendered canvas can be mistaken for a PDF artifact.
  • Validation: Keep a small fixture with transparent edges and inspect generated PDFs in the viewers your users rely on.
  • Billing and infrastructure: Client-side jsPDF has no ScreenshotNeo service charge because it runs in your page, but you are responsible for browser memory, rendering time, retries, and compatibility testing.

Or skip the browser setup

If your real requirement is a clean screenshot or PDF of a URL—not custom composition of several canvases—ScreenshotNeo can perform the capture through one request. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup 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 provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.

See the ScreenshotNeo API documentation for parameters and response handling. The following calls use the supplied endpoint and target URL:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
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)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

Every feature is available on every plan. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. This is an alternative to maintaining browser setup when a URL capture is sufficient, not a replacement for jsPDF when you need bespoke page composition.

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

Create a free ScreenshotNeo account to use the 1,000 monthly shots without adding a card.

Rank #4
PDF Extra 2024| Complete PDF Reader and Editor | Create, Edit, Convert, Combine, Comment, Fill & Sign PDFs | Lifetime License | 1 Windows PC | 1 User [PC Online code]
  • EDIT text, images & designs in PDF documents. ORGANIZE PDFs. Convert PDFs to Word, Excel & ePub.
  • READ and Comment PDFs – Intuitive reading modes & document commenting and mark up.
  • CREATE, COMBINE, SCAN and COMPRESS PDFs
  • FILL forms & Digitally Sign PDFs. PROTECT and Encrypt PDFs
  • LIFETIME License for 1 Windows PC or Laptop. 5GB MobiDrive Cloud Storage Included.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

FAQ

Will changing CSS border rules fix the PDF?

Only if the line is actually painted by the HTML or SVG. When the canvas preview is clean and the PDF is not, change the image encoding and inspect jsPDF placement instead of adding more CSS.

Can I use a transparent PNG with a non-white PDF page?

Yes. The PNG preserves transparent pixels; the visible result then depends on the page or background you place behind the image. Test the intended background explicitly.

Why should I test more than one PDF viewer?

Raster interpolation and edge antialiasing differ between viewers. A faint one-pixel boundary can be a display effect, while a line that appears consistently in extracted or printed output indicates a real PDF or image problem.

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.

Is this an html2canvas bug or a jsPDF bug?

The documented symptom crosses stages, so the evidence does not assign it universally to one library. The accepted remedy points to JPEG canvas encoding; geometry and independent drawing commands remain separate possibilities.

Best Value
PDF Director 3 PLUS - Edit, Convert, Redact, Protect PDFs, Fill Forms for Win 11, 10, 8.1, 7
  • Full-featured PDF Editor: Edit text in the document
  • Fully convert PDF to Word and Excel and continue editing
  • NEW: Further development of existing functions
  • NEW: Even faster and more user-friendly
  • NEW: Over 75 small improvements in all areas

Frequently Asked Questions

Does PNG always produce smaller PDFs than JPEG?

No. PNG is often larger for photographic imagery, while it is well suited to transparent canvases and sharp text. Compare output sizes for your documents after correctness is established.

Can this fix be applied after a PDF has already been generated?

No. Re-export the source canvas with the corrected format and regenerate the PDF; the original encoded image cannot be repaired reliably in place.

What should I include in a bug report?

Provide a minimal canvas, browser and library versions, export format, canvas dimensions, addImage coordinates, page format, and the PDF viewer in which the line appears.

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

Quick Recap

Bestseller No. 1
Adobe Acrobat Pro | PDF Software | Convert, Edit, E-Sign, Protect | PC/Mac Online Code | Activation Required
Adobe Acrobat Pro | PDF Software | Convert, Edit, E-Sign, Protect | PC/Mac Online Code | Activation Required
Edit text and images without jumping to another app.; Convert PDFs to editable Microsoft Word, Excel, or PowerPoint documents.
$239.88
Bestseller No. 2
Acrobat Pro | 1-Month Subscription | PDF Software |Convert, Edit, E-Sign, Protect |Activation Required [PC/Mac Online Code]
Acrobat Pro | 1-Month Subscription | PDF Software |Convert, Edit, E-Sign, Protect |Activation Required [PC/Mac Online Code]
Edit text and images without jumping to another app.; Convert PDFs to editable Microsoft Word, Excel, or PowerPoint documents.
$29.99
Bestseller No. 3
PDF Extra Lifetime - Professional PDF Editor - Best Adobe Acrobat Pro Alternative - Lifetime License for Windows PC
PDF Extra Lifetime - Professional PDF Editor - Best Adobe Acrobat Pro Alternative - Lifetime License for Windows PC
Perfect Adobe Acrobat Pro alternative – lifetime license for Windows 10 and 11.; EDIT text, images, pages, hyperlinks, designs in PDF documents. ORGANIZE PDFs.
$99.99
Bestseller No. 4
PDF Extra 2024| Complete PDF Reader and Editor | Create, Edit, Convert, Combine, Comment, Fill & Sign PDFs | Lifetime License | 1 Windows PC | 1 User [PC Online code]
PDF Extra 2024| Complete PDF Reader and Editor | Create, Edit, Convert, Combine, Comment, Fill & Sign PDFs | Lifetime License | 1 Windows PC | 1 User [PC Online code]
READ and Comment PDFs – Intuitive reading modes & document commenting and mark up.; CREATE, COMBINE, SCAN and COMPRESS PDFs
$99.99
Bestseller No. 5
PDF Director 3 PLUS - Edit, Convert, Redact, Protect PDFs, Fill Forms for Win 11, 10, 8.1, 7
PDF Director 3 PLUS - Edit, Convert, Redact, Protect PDFs, Fill Forms for Win 11, 10, 8.1, 7
Full-featured PDF Editor: Edit text in the document; Fully convert PDF to Word and Excel and continue editing
$29.99

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

Read next

Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.