Search code examples
jquerysharepointjspdf

Aspx to pdf jsPDF


I want to convert my form (Sharepoint) to pdf with jsPDF but i have a problem ...

Form Page

Result:

PDF

Can you help me ?

My code:

function demoFromHTML() {
var pdf = new jsPDF('p', 'pt', 'letter');
// source can be HTML-formatted string, or a reference
// to an actual DOM element from which the text will be scraped.
source = $('.JsPDF tbody')[0];

// we support special element handlers. Register them with jQuery-style 
// ID selector for either ID or node name. ("#iAmID", "div", "span" etc.)
// There is no support for any other type of selectors 
// (class, of compound) at this time.
specialElementHandlers = {
    // element with id of "bypass" - jQuery style selector
    '#bypassme': function (element, renderer) {
        // true = "handled elsewhere, bypass text extraction"
        return true
    }
};
margins = {
    top: 80,
    bottom: 60,
    left: 10,
    width: 700
};
// all coords and widths are in jsPDF instance's declared units
// 'inches' in this case
pdf.fromHTML(
source, // HTML string or DOM elem ref.
margins.left, // x coord
margins.top, { // y coord
    'width': margins.width, // max width of content on PDF
    'elementHandlers': specialElementHandlers
},

function (dispose) {
    // dispose: object with X, Y of the last line add to the PDF 
    //          this allow the insertion of new lines after html
    pdf.save('Test.pdf');
}, margins);

}

Before i used spform to convert my form but spform create image pdf but i need convert to native format.

Thanks


Solution

  • My previous answer was deleted, so in case someone finds this useful:

    jspdf don't support css, so it can be hard to get the right format. If adding html as an image doesn't work for you (https://stackoverflow.com/a/43064789/7751910), then adding text parts separately seems the only way if you choose to work with this particular library.

    doc.text('my text', 287.64, 415, 'center');