jsHTML2PDF - Example 1

Converting Div element to PDF file

by Luis Valle

JavaScript

$('#btnConvertDiv').on('click', function () {
    $(this).attr('disabled', 'disabled');
    var inStyleSheet = '<style>span, input, div, tr, th {font-family: Arial;}' +
        'th {padding: 6px;background-color: gray;border: 1px solid black;color: white;}' +
        'td {text-align: left;padding: 6px;border: 1px solid black;}' +
        'div, table, tr, td, th, tbody, thead, tfoot{page-break-inside: avoid !important;}' +
        '</style>';
    
    var pdfOptions = {
        html: $('#dvPDFarea'),
        fileName: 'FileConvertedFromDivElement_|uniqueNumber|',
        pageStyle: inStyleSheet,
        myCustomParams: $.stringify({
            fileformat: $('#cmbFileTypeA option:selected').val(),
            smartshrink: 'false',
            includepagenumbers: 'true'
        })
    };
    
    var PDFfile = new jsHtmlToPDF(pdfOptions);
    
    PDFfile.convert()
    .done(function () {
        $('#btnConvertDiv').removeAttr('disabled');
    });
    
    return false;
});