我正在处理一个项目,其中需要在客户端上生成PDF文件(点击保存为PDF),因为有些数据不应该发送到服务器。我已经了解了这些可用选项; fileSaver.js和html2canvas,但都没有帮助。我还想指出,我不太擅长JavaScript。 以下是我的JS代码:
<script type="text/javascript">
$(document).ready(function() {
$("#saveOutput").click(function() {
$("#Screenshot").html2canvas({
onrendered: function(canvas) {
var png = canvas.toDataURL()
window.open(png);
}
});
});
});
</script>
和我的Html
<div id="Screenshot">
<p>This is it</p>
<svg xmlns:xlink="http://www.w3.org/1999/xlink" width="250" height="250" style="height: 250px; width: 250px;">
<circle id="1" cx="100" cy="100" r="25" fill="#A52A2A"></circle>
</svg>
</div>
<div id="content">
<a class="button" id="saveOutput" href="#">Save as File</a>
</div>
为什么无法显示SVG文件?如何将这些文件转换为Canvas?有人能给我展示一下代码样例吗?任何帮助将不胜感激。