4

My requirement is to convert a HTML content into a PDF (or pdf data url). This should be done in client-side with JavaScript and when converting the HTML into the PDF all the Styles(CSS) should be properly rendered. Styles may have been linked from other css files. Is this possible? Are there any JavaScript libraries to accomplish this task?

Edit: I tried out jsPDF library, it generate pdf file from html content but does not work with css styles

Sajith Dulanjaya
  • 121
  • 1
  • 1
  • 6
  • https://parall.ax/products/jspdf or http://itextpdf.com/ – sinanspd Mar 06 '15 at 06:19
  • jsPDF works, but not with CSS styles – Sajith Dulanjaya Mar 06 '15 at 06:34
  • If you still can't find a client-side only solution, and you want to consider using server-side conversion, you could check out the document converter module of LEADTOOLS, which has [online demos you can try](https://www.leadtools.com/demos/html5). Please note that I work for the owner of this website. – Amin Dodin Jan 24 '17 at 12:04

1 Answers1

-1

Below is a part of my AngularJS's directive used for creation of pdf file:

    link : function(scope, element, attrs) {
        element.bind('click', function(evt) {
            evt.preventDefault();
            printPreview();

            setTimeout(function() {
                var data = generatePrintData();

                var doc = new jsPDF();

                doc.fromHTML(
                    data,
                    10,
                    10,
                    {
                        'width': 180
                    }
                );

                if(scope.user!=null)
                    var name = scope.user.toString() + ".pdf";
                else
                    var name = "unknown_user.pdf"
                doc.save(name);
            }, 0);
        });
Tomasz Waszczyk
  • 2,680
  • 5
  • 35
  • 73