[英]Cannot make full html content to PDF from Html div by jsPDF
I need your help. 我需要你的帮助。 I try to make downloadable pdf file form blog each post in blogger.
我试图使Blogger中的每个帖子都成为可下载的pdf文件形式。 I have use following code and plugins :
我使用以下代码和插件:
Plugins: 外挂程式:
jQuery v1.11.3
jspdf.js
HTML Structure 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 URL: http://ecwebzone.blogspot.in/2015/09/this-is-test-post-of-pdf-creation.html HTML Live URL: http : //ecwebzone.blogspot.in/2015/09/this-is-test-post-of-pdf-creation.html
Code: 码:
<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>
After click on the button it will convert few lines of this post like, you check it through my url: 单击该按钮后,它将转换该帖子的几行,就像您通过我的url进行检查一样:
Answer the following questions by selecting the most appropriate option.
1. A creative learner refers to one who is
Please help me any one. 请任何人帮助我。 I want to add this option to my each post as namely 'Download post as pdf' in a4 paper size.
我想将此选项添加到我的每个帖子中,即“ a4纸张大小的'pdf下载帖子'”。
I have also try following: 我也尝试以下操作:
<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>
here output blank only. 这里仅输出空白。 no text in created pdf.
创建的pdf中没有文本。
In the HTML source i see that the first line with a span has not a <br> after the closing tag but a </div>. 在HTML源代码中,我看到带有跨度的第一行在结束标记之后不是<br>而是</ div>。 So the #printpdf-div is closed after the first span.
因此,#printpdf-div在第一个跨度之后关闭。 Replac e the </div> at this position with a <br /> and it should work.
在此位置用<br />替换</ div>,它应该可以工作。
Code: 码:
... 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 /> ....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.