doc.save() throwing error with jspdf

与世无争的帅哥 提交于 2019-12-04 22:18:19
Owen Davey

Found out what the issue was. The saveAs function is part of FileSaver.js so I just needed to include this and everything worked.

Kyle Baker

I don't have enough to comment yet, so I'm adding this as an answer... saveAs() is a w3c interface. If adding FileSaver fixed your issue, that means you were using an old browser; FileSaver.js is used as a shim for jsPDF to support older browsers that don't have that function natively.

You can also use jspdf.debug.js it contains all of the plugins in one file. This way you are covered if something else is needed.

-Cheers

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Hello world</title>
</head>
<body>
    <h1>Hello world</h1>
    <script type="text/javascript" src="jspdf.min.js"></script>
    <script type="text/javascript">
        var pdf = new jsPDF();
        pdf.text(30, 30, 'Hello world!');
        pdf.save('hello_world.pdf');
    </script>
</body>
</html>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!