我正在做一个项目,我需要在客户端生成一个 pdf 文件(onclick saveFile as 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?有人可以向我展示代码示例吗?任何帮助将不胜感激。