Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript: How to create pdf file from HTML form or div

I am new to Javascript / jQuery and am looking for a way to add a button to a page that allows the user to create a pdf from a pre-defined form or div (e.g. by adding a class).

I did some research but could not find a way to do this in JS or jQuery.

Is there a way to realise this on client side via Javascript / jQuery or can someone tell me a freeware plugin that supports this ?

The only plugin I found is TCPDF but this seems to be pretty large and I did not see a way there where I can limit this to a certain form or div on a page (instead of printing the whole page).

Note: I do not need to cover images, just plain HTML like form fields or tables and text.

Many thanks in advance for any help with this, Mike

like image 228
keewee279 Avatar asked Mar 16 '23 20:03

keewee279


1 Answers

you could try with jsPDF

it's free and client side.

You can see from their 'HTML Render' example that you can create a PDF from a portion of your HTML

EDIT

Probably jsPDF doesn't support CSS

If you need it, you could try as an alternative phantomJS, but it's a command-line tool and it captures a web page as a screenshot. Not sure if that's what you're searching for

like image 61
Moppo Avatar answered Mar 23 '23 11:03

Moppo