5

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

3
  • parall.ax/products/jspdf or itextpdf.com Commented Mar 6, 2015 at 6:19
  • jsPDF works, but not with CSS styles Commented Mar 6, 2015 at 6: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. Please note that I work for the owner of this website. Commented Jan 24, 2017 at 12:04

1 Answer 1

-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);
        });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.