html4pdf vs jsPDF and html2canvas

This is the first result for almost every search about downloading a PDF from a web app, which is why so many products ship a PDF that nobody can copy text out of.

The short answer

jsPDF with html2canvas is free and needs no backend, and it produces a picture of your page rather than a document. If the text has to be selectable, searchable or printable at quality, it is the wrong tool.

What jsPDF and html2canvas is

jsPDF builds PDFs in the browser with a drawing API. html2canvas rasterises part of the DOM into a canvas. Put together, the usual recipe screenshots an element and places the image into a one page PDF. It is entirely client side, so there is no server, no key and no cost.

Side by side

 jsPDF and html2canvashtml4pdf
Where it runsThe browserOur server, in memory
OutputAn image of the page, embedded in a PDFReal text and vectors
Selectable textNoYes
Searchable and accessibleNoYes
Print qualityFixed resolution, soft on paperVector, sharp at any size
Page breaksWherever the image is sliced, often mid-lineReal pagination
File sizeLarge, it is a bitmapSmall
CSS fidelityhtml2canvas reimplements rendering and misses thingsIt is Chrome
CostFreeFrom $0.033 per document
Backend neededNoYes, a server call

Choose jsPDF and html2canvas when

  • You want a rough visual capture and nobody will read it on paper.
  • There is no backend at all and there cannot be one.
  • The content must never leave the browser, and a picture is acceptable.
  • It is a chart or a diagram, where an image is the honest output anyway.

Choose html4pdf when

  • Someone will select, copy or search the text: an invoice, a contract, a report.
  • It will be printed, or read on a screen bigger than the one that made it.
  • The document is longer than one page and needs real page breaks.
  • Accessibility matters, and a flat image fails it completely.

See the code

The working example, in the language this decision is being made in.

jsPDF and html2canvas: common questions

Why is my html2canvas PDF blurry?

Because it is a bitmap sized to the screen. Raising the scale option helps and makes the file much larger, but it is still an image: at print resolution it will always be softer than real text.

Can I select text in a jsPDF and html2canvas PDF?

Not when the page was captured by html2canvas. The text is pixels. Text written directly through the jsPDF drawing API is selectable, but then you are not converting HTML, you are drawing the document by hand.

How do I handle multiple pages?

The usual recipe slices the tall canvas into page-height strips, which cuts through whatever happens to be at the boundary. Avoiding that means rendering the document properly rather than photographing it.

Is there a client side way to get real text?

Yes: @react-pdf/renderer draws real text and vectors in the browser. The trade-off is that you write its components rather than HTML.

Can I call a PDF API from the browser instead?

Not directly, because your API key would be in the bundle for anyone to take. Proxy it through your own backend route.

Try it before you decide

New accounts get 10 free credits, no card. Send the HTML you already have and compare the output against whatever you are using now.

Get API key

Other comparisons