Eff*_*rik 17 javascript pdf google-chrome html2canvas jspdf
我正在尝试使用jsPDF将应用程序导出为PDF.在浏览网页后,在这里抓取一行代码,在那里找到一个部分 - 我已经设法让它工作...... 有点.
它适用于Firefox和Safari,但不适用于Chrome.
使用的JS文件(来自jsPDF).也许是矫枉过正.和Jquery一起.
<script type="text/javascript" src="PDF/standard_fonts_metrics.js"></script>
<script type="text/javascript" src="PDF/split_text_to_size.js"></script>
<script type="text/javascript" src="PDF/from_html.js"></script>
<script type="text/javascript" src="PDF/addhtml.js"></script>
<script type="text/javascript" src="PDF/addimage.js"></script>
Run Code Online (Sandbox Code Playgroud)
我正在使用的代码是这样的:
<script type="text/javascript">
function demoFromHTML() {
$('#listAreaPDF').css("display", "block");
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 = $('#listAreaPDF')[0];
pdf.setFontSize(24);
pdf.text(35, 40, "PDF Title here");
pdf.setFontSize(10);
pdf.text(500, 40, "Company Name AB");
// 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) {
html2canvas($("#presentationArea"), {
onrendered: function (canvas) {
var imgData = canvas.toDataURL(
'image/png');
pdf.addImage(imgData, 'PNG', 20, 300);
pdf.save('Test.pdf');
}
});
// dispose: object with X, Y of the last line add to the PDF
// this allow the insertion of new lines after html
// pdf.save('Test.pdf');
},
margins
);
$('#listAreaPDF').css("display", "none");
}
</script>
Run Code Online (Sandbox Code Playgroud)
感谢这里找到的代码.只需要很少的小改动以适合我的应用程序,我就添加了一个与html2canvas的连接,将图像从我的应用程序中取出并将其放入PDF中.哪个实际上工作正常 - 在Safari和Firefox中.
在Chrome中单击并激活此功能时,我甚至没有收到空白PDF,我什么都没得到.甚至没有生成弹出窗口或页面.
可能是Firefox和Safari工作但不是Chrome的原因? 我还没有尝试过Internet Explorer,但我没有屏住呼吸.如果你知道一种工作方式,我就是全力以赴.
欢呼您提供任何帮助或建议.
小智 5
此问题可能与 chrome弃用顶框导航有关。
删除:内容启动顶部框架导航至数据 URL(已删除)
我们打算使用标签、window.open、window.location 和类似机制来阻止网页加载数据:顶部框架中的 URL。
data: 等伪 URL 通常会造成用户混淆。由于不熟悉,这些方案被广泛用于欺骗和网络钓鱼攻击。理想情况下,浏览网页的用户应该只使用两种众所周知的方案(http 和 https)。
在 M58 中已弃用
M60 中的移除
https://www.chromestatus.com/feature/5669602927312896
正如提到的 google groups thread 中所述,一个可能的解决方案是使用 iFrame。
| 归档时间: |
|
| 查看次数: |
1755 次 |
| 最近记录: |