Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

html to pdf javascript

var doc = new jsPDF();          
var elementHandler = {
  '#ignorePDF': function (element, renderer) {
    return true;
  }
};
var source = window.document.getElementsByTagName("body")[0];
doc.fromHTML(
    source,
    15,
    15,
    {
      'width': 180,'elementHandlers': elementHandler
    });

doc.output("dataurlnewwindow");
Comment

javascript download html to pdf

<div id="content">
     <h3>Hello, this is a H3 tag</h3>

    <p>A paragraph</p>
</div>
<div id="editor"></div>
<button id="cmd">generate PDF</button>

// javascript
var doc = new jsPDF();
var specialElementHandlers = {
    '#editor': function (element, renderer) {
        return true;
    }
};

$('#cmd').click(function () {
    doc.fromHTML($('#content').html(), 15, 15, {
        'width': 170,
            'elementHandlers': specialElementHandlers
    });
    doc.save('sample-file.pdf');
});
Comment

Convert HTML To PDF Using JavaScript

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.5/jspdf.min.js"></script>  
<script>
$(document).ready(function () {  
    var form = $('.form'),  
    cache_width = form.width(),  
    a4 = [595.28, 841.89]; // for a4 size paper width and height  

    $('#create_pdf').on('click', function () {  
        $('body').scrollTop(0);  
        createPDF();  
    });  
    
    function createPDF() {  
        getCanvas().then(function (canvas) {  
            var  
             img = canvas.toDataURL("image/png"),  
             doc = new jsPDF({  
                 unit: 'px',  
                 format: 'a4'  
             });  
            doc.addImage(img, 'JPEG', 20, 20);  
            doc.save('Bhavdip-html-to-pdf.pdf');  
            form.width(cache_width);  
        });  
    }  
      
    function getCanvas() {  
        form.width((a4[0] * 1.33333) - 80).css('max-width', 'none');  
        return html2canvas(form, {  
            imageTimeout: 2000,  
            removeContainer: true  
        });  
    }
});
</script>
Comment

PREVIOUS NEXT
Code Example
Javascript :: return nothing javascript 
Javascript :: javascript parsefloat 
Javascript :: javascript dataset 
Javascript :: js setinterval vs settimeout 
Javascript :: mongoose find get nested prop only 
Javascript :: toLocalString 
Javascript :: javascript regex match character from a set of characters 
Javascript :: plotly express bar graph 
Javascript :: react router changing url but not rendering 
Javascript :: office check in 
Javascript :: extract domain from url js 
Javascript :: get role id from role position 
Javascript :: random unique number generator javascript 
Javascript :: requirejs example 
Javascript :: javascript get cell by index 
Javascript :: how to make button in react js 
Javascript :: js sort integer array 
Javascript :: datatable bootstrap cllick on specific button 
Javascript :: react native webview disable touch 
Javascript :: how to return the max and min of an array in javascript 
Javascript :: toast 
Javascript :: define value in js 
Javascript :: react hooks send data from child to parent 
Javascript :: cypress test only one file 
Javascript :: browser tab switch event js 
Javascript :: vuex do not mutate vuex store state outside mutation handlers. nuxt 
Javascript :: no routes matched location / react router 
Javascript :: Detect the city on application launch via geolocation react native 
Javascript :: mongoose get value 
Javascript :: add quotes to array items 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =