我正在尝试使用JsPdf
以PDF格式打印HTML内容,但是无法正常工作;所有内容都不会到来。我在下面提供我的代码。
$(document).ready(function(){
$("#print").click(function(){
var pdf = new jsPDF('p', 'pt', 'letter');
pdf.canvas.height = 72 * 11;
pdf.canvas.width = 72 * 8.5;
// source can be HTML-formatted string, or a reference
// to an actual DOM element from which the text will be scraped.
source = $('#pcntr')[0];
//console.log('source',source);
// 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: 20,
bottom: 20,
left: 10,
width: 300
};
// 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) {
console.log('hello');
// 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);
});
});
在这里,我只是想将我所有的HTML内容(包括CSS和图像部分)转换为PDF,但是一些文本即将到来,而有些则没有。许多空白页也将到来。 Here is my complete plunkr code。我需要创建全部内容的PDF文件。