我已经花了四天的时间试图解决一个问题,这个问题一开始似乎是个孩子的游戏:使用 jsPDF 库我正在尝试保存文件。不打印它,那是已经完成的事情。
所以这是我的HTML:
<!DOCTYPE html>
<html manifest="offline.appcache">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>New project</title>
<!-- Allow fullscreen mode on iOS devices. (These are Apple specific meta tags.) -->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, minimal-ui" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="apple-touch-icon" sizes="256x256" href="icon-256.png" />
<meta name="HandheldFriendly" content="true" />
<!-- Chrome for Android web app tags -->
<meta name="mobile-web-app-capable" content="yes" />
<link rel="shortcut icon" sizes="256x256" href="icon-256.png" />
<script src="script/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="script/jspdf.js"></script>
<script type="text/javascript" src="script/libs/base64.js"></script>
<script type="text/javascript" src="script/libs/sprintf.js"></script>
<script type="text/javascript" src="script/jspdf.js"></script>
<script type="text/javascript" src="script/jspdf.plugin.standard_fonts_metrics.js"></script>
<script type="text/javascript" src="script/jspdf.plugin.split_text_to_size.js"></script>
<script type="text/javascript" src="script/jspdf.plugin.from_html.js"></script>
<script type="text/javascript" src="script/FileSaver.js"></script>
<!-- The CSS -->
<style type="text/css">
p
{
font-size: 18px;
}
#container{
width: 800px;
height: 500px;
background-color: red;
}
</style>
<!-- The javascript -->
<script>
function print()
{
var doc = new jsPDF();
doc.text(20, 20, 'Hello world.');
doc.output('datauri');
}
function save()
{
var doc = new jsPDF();
doc.text(20, 20, 'Hello world.');
doc.save('nombre_example.pdf');
}
</script>
</head>
<body>
<input type="button" value="Print" height="50px" width="50px" Onclick="print()">
<input type="button" value="Save" height="50px" width="50px" Onclick="save()">
<div id="container">
<p>
HOLA <br>
HOLA <br>HOLA <br>HOLA <br>HOLA <br>HOLA <br>HOLA <br>HOLA <br>HOLA <br>HOLA <br>HOLA <br>HOLA <br>HOLA <br>HOLA <br>HOLA <br>HOLA <br>HOLA <br>HOLA <br>HOLA <br>
</p>
</div>
</body>
</html>
然后,当我单击“保存”按钮时,我可以在 javacript 控制台上阅读:
Uncaught TypeError: Object #<Object> has no method 'save' index.html:58
我附加到项目的 JavaScript 文件列表是:
- FileSaver.js
- jquery-2.1.0.min.js
- jspdf.js
- jspdf.plugin.addimage.js
- jspdf.plugin.autoprint.js
- jspdf.plugin.cell.js
- jspdf.plugin.from_html.js
- jspdf.plugin.javascript.js
- jspdf.plugin.png_support.js
- jspdf.plugin.sillysvgrenderer.js
- jspdf.plugin.split_text_to_size.js
- jspdf.plugin.standard_fonts_metrics.js
- jspdf.plugin.total_pages.js
和图书馆:
- base64.js
- sprintf.js
所以,在显示所有这些信息之后,我的问题是:为什么我不能让保存按钮正常工作?
有任何想法吗?