我需要你的帮助。 我尝试在博客中的每个帖子上制作可下载的pdf文件格式博客。我使用了以下代码和插件:
插件:
jQuery v1.11.3
jspdf.js
HTML结构
<div id='printpdf'>
..................
Blog Post Content here
.....................
</div>
<div id="editor">
</div>
<button id="btn-pdf" type="button" name="btn-pdf">generate PDF</button>
HTML Live网址: http://ecwebzone.blogspot.in/2015/09/this-is-test-post-of-pdf-creation.html
代码:
<script>
$(document).ready(function(){
var specialElementHandlers = {
'#editor': function (element, renderer) {
return true;
}
};
$('#btn-pdf').click(function () {
var doc = new jsPDF('p', 'mm', [297, 210]);
var source = $('#printpdf').html();
var specialElementHandlers = {
'#editor': function (element, renderer) {
return true;
}
};
doc.fromHTML(source, 5, 5, {
'width': 297,'elementHandlers': specialElementHandlers
});
doc.output("dataurlnewwindow");
});
});
</script>
单击按钮后,它会转换此帖子的几行,例如,您通过我的网址检查:
Answer the following questions by selecting the most appropriate option.
1. A creative learner refers to one who is
请帮助我任何人。我想将这个选项添加到我的每个帖子中,即“以pdf格式下载帖子”的4个纸张大小。
我也尝试过:
<script>
function downPDF() {
var doc = new jsPDF('p', 'in', 'letter');
var source = $('#printpdf').first();
var specialElementHandlers = {
'#editor': function(element, renderer) {
return true;
}
};
doc.fromHTML(
source, // HTML string or DOM elem ref.
0.5, // x coord
0.5, // y coord
{
'width': 7.5, // max width of content on PDF
'elementHandlers': specialElementHandlers
});
doc.save('ECNote-files.pdf');
}
</script>
此处仅输出空白。创建的pdf中没有文字。
答案 0 :(得分:0)
在HTML源代码中,我看到带有span的第一行没有&lt; br&gt;在结束标记之后但是&lt; / div&gt;。所以#printpdf-div在第一个跨度后关闭。重写&lt; / div&gt;在这个位置用&lt; br /&gt;它应该工作。
代码:
... 1. A creative learner refers to one who is</span> --></div><--
<span style="background-color: white; color: #141823; font-family: helvetica, arial, sans-serif; font-size: 14px; line-height: 19.32px;">(1) very talented in drawing and painting</span><br /> ....