2017-10-17 72 views
0

我試圖讓我的jspdf不保存空白頁面PDF。我一直在努力的例子很多,但沒有任何工程:(。​​我的表格內容的PDF的第二頁上保存正確,具有形象,但我的第一頁是空白。jspdf第一個PDF頁面是空白的

var pdf = new jsPDF('o', 'pt', 'a6'); 
//pdf.autoTable(this.columns, this.data); 
//var width = pdf.internal.pageSize.width;  
//var height = pdf.internal.pageSize.height; 
pdf.addPage('1800','900'); 
pdf.addImage(imgData, 'PNG', 120, 40, 120, 100); 
pdf.setTextColor(0,0,0); 
pdf.text(120, 20, 'BOOKINGS'); 
pdf.setFontSize(22);  
// 'o', 'pt', 'a4' 
// '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 = jQuery('.dataTables_wrapper')[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: 120, 
    bottom: 0, 
    left: 0, 
    width: 2000 
}; 
// 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('bookings.pdf'); 
}, margins); 

}

回答

0

的第一頁是空白的,因爲添加頁面是調用jsPDF構造函數後第一次調用。構造函數已經創建了(第一個)空白頁面。要刪除文檔開始處的附加空白頁面,可以刪除第一頁呼叫doc.deletePage(1),或者在調用構造函數後不添加頁面。