简体   繁体   English

将SVG模式另存为PDF和PNG

[英]Saving SVG pattern as PDF and PNG

I've got a flowery pattern ( http://pages.bangor.ac.uk/~abp4d9/ ) where user moves sliders (for inner circles and petals) and flowers change. 我有一个绚丽的图案( http://pages.bangor.ac.uk/~abp4d9/ ),用户可以移动滑块(用于内圈和花瓣),而花朵也会变化。 I've got 3 'Save as' buttons. 我有3个“另存为”按钮。 1st one (SVG) works great. 第一个(SVG)效果很好。 The other 2 work only half-way. 其他2个仅中途工作。 The saved file comes up in the appropriate format but then it doesn't open, saying that there was an error. 保存的文件以适当的格式显示,但随后打不开,说明存在错误。 All 3 JS functions are almost identical – I basically copied them from the working 1st function. 所有3个JS函数几乎都是相同的-我基本上是从工作的第一个函数中复制它们。 I'm not sure what to correct – probably 'new Blob' format, but I'm not sure what to put instead. 我不确定要纠正什么-可能是“新的Blob”格式,但是我不确定要放什么。 So, to sum up: • How to get a working 'Save as SVG' button to do the same with PDF and PNG? 因此,总结一下:•如何获得一个有效的“另存为SVG”按钮以对PDF和PNG进行同样的处理? Here is my JS for half-working PDF button: 这是我的半工作PDF按钮的JS:

function downloadPdf(){
var svg = document.getElementsByTagName("svg")[0];
var svg_xml = (new XMLSerializer).serializeToString(svg);
var blob = new Blob([svg_xml]);
var url = window.URL || window.webkitURL;
var blobURL = url.createObjectURL(blob);
var a = document.createElement('a');
a.download = "Pattern.pdf";
a.href = blobURL;
document.body.appendChild(a);
a.click();
}

you have to create the PNG resp. 您必须创建PNG响应。 PDF first. PDF首先。 for PNG you can use canvas to draw the image and then retrieve the canvas content as PNG (or you can use a library). 对于PNG,您可以使用canvas绘制图像,然后以PNG形式获取画布内容(或者可以使用库)。 for PDF you have to use a library. 对于PDF,您必须使用一个库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM