<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Blobs</title>
<script src="http://localhost:81/0_plus-in/jspdf/jspdf.debug.js"></script>
</head>
<body>
<button id="button">Link</button>
</body>
<script>
const download = (fileName, blob) => {
const element = document.createElement('a');
const url = window.URL.createObjectURL(blob);
element.href = url;
element.download = fileName;
element.target = '_blank';
element.click();
element.remove();
}
document.addEventListener('click', async event => {
if (event.target.id === 'button') {
const doc = new jsPDF();
const fileName = 'test.pdf';
doc.text('Hello world!', 10, 10);
const blob = new Blob([doc.output()]);
download(fileName, blob);
}
});
</script>
</html>
js创建pdf文件
最新推荐文章于 2024-08-08 07:59:25 发布