我已经花了四天时间试图解决一个问题,一开始看起来似乎是一个孩子的游戏:使用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>
然后,当我点击按钮&#39;保存&#39;我可以在javacript控制台上阅读:
Uncaught TypeError: Object #<Object> has no method 'save' index.html:58
我附加到项目的JavaScript文件列表是:
和图书馆:
因此,在显示所有这些信息后,我的问题是:为什么我不能使保存按钮正常工作?
有什么想法吗?
答案 0 :(得分:3)
尝试仅添加这两个脚本文件并查看
<script type="text/javascript" src="script/jspdf.js"></script>
<script type="text/javascript" src="script/FileSaver.js"></script>
除此之外你为什么要两次添加jspdf.js文件......