Search code examples
htmlcssangularjspdfhtml2pdf

Html To Pdf conversion in angular js


I am trying to convert html to pdf. Is there any custom directive, which i can use.I also tried to use angular-save-html-to-pdf from npm site but there is some error while using. Is there any other way to convert html to css in angular js.


Solution

  • There is jsPDF library which supports this. It's using html2canvas. There is a demo on their site.

    var doc = new jsPDF();
    
    // We'll make our own renderer to skip this editor
    var specialElementHandlers = {
        '#editor': function(element, renderer){
            return true;
        }
    };
    
    // All units are in the set measurement for the document
    // This can be changed to "pt" (points), "mm" (Default), "cm", "in"
    doc.fromHTML($('body').get(0), 15, 15, {
        'width': 170, 
        'elementHandlers': specialElementHandlers
    });