我正在一个项目中,我需要在客户端生成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);
}
});
});
});
Run Code Online (Sandbox Code Playgroud)
和我的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>
Run Code Online (Sandbox Code Playgroud)
为什么无法显示SVG文件?这些文件如何转换为Canvas?有人可以向我展示代码示例吗?任何帮助将不胜感激