我正在尝试使用html2pdf将数据导出到PDF。首先,我写了一个简单的例子,当点击导出按钮,打开一个新的空白窗口,没有任何内容导出到它,有什么建议吗?
演示:https://plnkr.co/edit/ruWKJBQiZ9QgUjxaBzbo?p=preview
html代码:
<div ng-controller="listController">
<button ng-click="export()">export</button>
<h3> Simple Test</h3>
</div>js代码:
app.controller("listController", ["$scope",
function($scope) {
$scope.export = function() {
var pdf = new jsPDF('p', 'pt', 'letter');
var canvas = pdf.canvas;
canvas.height = 72 * 11;
canvas.width= 72 * 8.5;;
// can also be document.body
var html = '<html><body>Hello from JS file <strong> World</strong></body></html>';
html2pdf(html, pdf, function(pdf) {
pdf.output('dataurlnewwindow');
});
}
}
]);当用户单击导出按钮时,分配给html变量的字符串应该导出并显示。
发布于 2017-11-01 19:54:30
如果不想打开新窗口,请使用:
pdf.output('datauri');dataurinewwindow特别要求在一个新窗口中打开PDF。
完整的例子:
var app = angular.module("app", []);
app.controller("listController", ["$scope",
function($scope) {
$scope.export = function() {
var pdf = new jsPDF('p', 'pt', 'letter');
var canvas = pdf.canvas;
canvas.height = 72 * 11;
canvas.width = 72 * 8.5;;
// can also be document.body
var html = '<html><body>Hello from JS file <strong> World</strong></body></html>';
html2pdf(html, pdf, function(pdf) {
pdf.output('dataurl');
});
}
}
]);https://stackoverflow.com/questions/47062596
复制相似问题