我无法使用jsPDF保存图像。当我尝试查看pdf本身时,可以保存<div id="content"></div>
标记内的内容和文本。为什么无法查看图像标签?有什么办法可以将其保存到PDF中吗?这是我的下面的代码
HTML代码
<div id="content" class="qrlist">
<p>Sample1: Test1</p>
<p>Sample2: <span id="filename">Test2</span></p>
<p>Sample3: Test3</p>
<p>Sample4: Test4</p>
<p>Sample5: Test5</p>
<p>Sample6: Test6</p>
<p>Sample7: Test7</p>
<p>Sample8: Test8</p>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/d/d0/QR_code_for_mobile_English_Wikipedia.svg/220px-QR_code_for_mobile_English_Wikipedia.svg.png">
</div>
<div id="editor"></div>
<a href="#" id="generatepdf">Generate PDF</a>
JavaScript
<!-- Script Tag -->
<script>
$(document).ready(function(){
var doc = new jsPDF();
// We'll make our own renderer to skip this editor
var specialElementHandlers = {
'#editor': function(element, renderer){
return true;
}
};
$('#generatepdf').click(function () {
var filename = $("#filename").text();
var file_ext = ".pdf";
var finalfilename = filename + file_ext;
doc.fromHTML($('#content').get(0), 15, 15, {
'width': 100,
'elementHandlers': specialElementHandlers
});
doc.save(finalfilename);
});
});
</script>