【发布时间】:2017-06-03 01:02:53
【问题描述】:
我想保存一个包含 IFrame 内容的 PDF 文件。我正在使用 jsPDF。当我点击调用该函数的按钮时,脚本会创建一个空的 PDF 页面。
框架内容如下:https://jsfiddle.net/ss6780qn/
我正在使用以下脚本:
<script src="../jspdf/plugins/standard_fonts_metrics.js"></script>
<script type="text/javascript">
function toPDF(){
var pdf = new jsPDF('p', 'in', 'letter');
// source can be HTML-formatted string, or a reference
// to an actual DOM element from which the text will be scraped.
source = $('#frame')[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
'div': function(element, renderer){
// true = "handled elsewhere, bypass text extraction"
return true
}
}
// all coords and widths are in jsPDF instance's declared units
// 'inches' in this case
pdf.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
}
)
pdf.save('Test.pdf');
}
有人知道出了什么问题以及我该如何解决这个问题吗?
【问题讨论】:
-
还没有修复
-
还没有修复
-
你能用你的整个代码创建一个 JSFiddle 或等效的,而不仅仅是框架吗?
-
'specialElementHandlers' 完成了什么。从表面上看,它说忽略所有“div”元素。可能不利于捕获您的内容?内容中的第一个元素是 div class="content"
标签: javascript pdf jspdf