我正在尝试使用jsPDF
将html div转换为pdf。在我的div中,我有一个带有背景图像的svg
文件,用户可以在其中绘制矩形、线条、文本等。我正在使用d3.js
进行绘制。现在我想要保存我的div和所有绘制内容到pdf,但它只将我的文本转换为pdf。我的js代码如下:
function htmlToPdf() {
console.log("--------------- with in 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 = $('svg.plancontainer')[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: 40,
width: 522
};
// 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.autoPrint();
pdf.output('dataurlnewwindow');
}, margins
);
}
CDN是<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.debug.js"></script>
它打印PRINT AREA
而不是我的image
和没有svg
图像的文本。
这是我想转换为PDF的样本div预览
我没有得到任何具体信息,说明在哪里可以使用
jsPDF
或者其他js库。
现在我的问题是:
是否可以使用
jsPDF
或其他js库?如果可能的话,请给我建议?
感谢您提供任何帮助。