在网上找了一大圈方法。试过imagemagick等其他方式进行转换 都无法满足需要。转换后的矢量文件有时候是无法进行编辑的,就一张图片。无法满足我的要求,这个期间查看了好多帖子,有的要就是不全,要不就是jar不给提供,只给下载,还需要积分,这个可以理解 ,但是偏偏花了大量积分下载下来的jar包尽然无法使用,前钱后后花了100多积分,这可是我的好不容易积攒的。可真是害死人了,太坑了。无意间看到了一个帖子 上面提供了这种方式,但是也没有提供jar包和pom,但是官网是提供出来了,时间有点久忘记了那个贴子的路径了,实在不好意思,无法贴出来。最终 在官方上找到了jar包,同时在maven中央仓库找到了pom文件,为了使大家不在被坑,因而贴出来,希望能少走点弯路。
如果您不要通过代码转换,可以试试网上的提供的免费连接:
https://cn.office-converter.com/SVG-to-EPS
https://convertio.co/zh/svg-eps/
如果您不差钱,我差钱(🤭),可以使用上面两个连接提供的第三方接口,每个月大概是$14.99美元,大概是人民币:106.1847人民币元
所支持的相关格式:
具体请查看相关源码:org.apache.batik.transcoder.Transcoder
<!-- https://mvnrepository.com/artifact/org.apache.xmlgraphics/batik-all -->
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-all</artifactId>
<version>1.12</version>
<type>pom</type>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.xmlgraphics/fop -->
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>fop</artifactId>
<version>2.4</version>
</dependency>
import org.apache.batik.transcoder.*;
import org.apache.batik.transcoder.image.JPEGTranscoder;
import org.apache.batik.transcoder.image.PNGTranscoder;
import org.apache.batik.transcoder.image.TIFFTranscoder;
import org.apache.fop.render.ps.EPSTranscoder;
import org.apache.fop.render.ps.PSTranscoder;
import org.apache.fop.svg.AbstractFOPTranscoder;
import org.apache.fop.svg.PDFTranscoder;
import java.io.*;
* * 利用Apache Batik实现 SVG转PDF/PNG/JPG
public class SVGConverterUtils {
public static void main(String[] args) throws Exception {
String svgpath = "E:\\svgfile\\c.svg";
File svgFile = new File(svgpath);
String name = svgFile.getName();
name = name.substring(0, name.lastIndexOf("."));
SVGConverter converter = new SVGConverter();
// converter.svg2PDF(new File(svgpath), new File("E:/" + name + "_SVG文件转PDF.pdf"));
// converter.svg2PNG(new File(svgpath), new File("E:/" + name + "_SVG文件转PNG.png"));
// converter.svg2JPEG(new File(svgpath), new File("E:/" + name + "_SVG文件转JPG.jpg"));
String svgCode = converter.svg2String(new File(svgpath));
// converter.svg2PDF(svgCode, "D:/" + name + "_SVG代码转PDF.pdf");
// converter.svg2PNG(svgCode, "D:/" + name + "_SVG代码转PNG.png");
// converter.svg2JPEG(svgCode, "D:/" + name + "_SVG代码转JPG.jpg");
// converter.svg2PDF(svgCode, new FileOutputStream(new File("E:/svgfile/" + name + "_SVG代码转输出流.pdf")));
// converter.svg2PNG(svgCode, new FileOutputStream(new File("E:/svgfile/" + name + "_SVG代码转输出流.png")));
// converter.svg2JPEG(svgCode, new FileOutputStream(new File("E:/svgfile/" + name + "_SVG代码转输出流.jpg")));
// converter.svg2EPS(svgCode, new FileOutputStream(new File("E:/svgfile/" + name + "_SVG代码转输出流.eps")));
// converter.svg2PS(svgCode, new FileOutputStream(new File("E:/svgfile/" + name + "_SVG代码转输出流.ps")));
converter.svgtoeps(svgCode, new FileOutputStream(new File("E:/svgfile/" + name + "_SVG代码转输出流.eps")));
public void svgtoeps(String svgCode, OutputStream os){
EPSTranscoder epsTranscoder = new EPSTranscoder();
try {
svgCode = svgCode.replaceAll(":rect", "rect");
TranscoderInput input = new TranscoderInput(new ByteArrayInputStream(svgCode.getBytes()));
TranscoderOutput output = new TranscoderOutput(os);
epsTranscoder.transcode(input, output);
os.flush();
os.close();
} catch (Exception e) {
* SVG转PNG
* @param svgCode SVG代码
* @param outpath 输出路径
* @throws TranscoderException
* @throws IOException
public void svg2PNG(String svgCode, String outpath) throws TranscoderException, IOException {
Transcoder transcoder = new PNGTranscoder();
svgConverte(svgCode, outpath, transcoder);
* SVG转PNG
* @param svgCode SVG代码
* @param out 输出流
* @throws TranscoderException
* @throws IOException
public void svg2PNG(String svgCode, OutputStream out) throws TranscoderException, IOException {
Transcoder transcoder = new PNGTranscoder();
svgConverte(svgCode, out, transcoder);
* SVG转PNG
* @param svgFile SVG文件
* @param outFile 输出文件
* @throws TranscoderException
* @throws IOException
public void svg2PNG(File svgFile, File outFile) throws TranscoderException, IOException {
Transcoder transcoder = new PNGTranscoder();
svgConverte(svgFile, outFile, transcoder);
* SVG转JPG
* @param svgCode SVG代码
* @param outpath 输出路径
* @throws TranscoderException
* @throws IOException
public void svg2JPEG(String svgCode, String outpath) throws TranscoderException, IOException {
Transcoder transcoder = new JPEGTranscoder();
//为防止ERROR: The JPEG quality has not been specified. Use the default one: no compression 错误,需如下配置
transcoder.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, 0.99f);
svgConverte(svgCode, outpath, transcoder);
* SVG转JPG
* @param svgCode SVG代码
* @param out 输出流
* @throws TranscoderException
* @throws IOException
public void svg2JPEG(String svgCode, OutputStream out) throws TranscoderException, IOException {
Transcoder transcoder = new JPEGTranscoder();
//为防止ERROR: The JPEG quality has not been specified. Use the default one: no compression 错误,需如下配置
transcoder.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, 0.99f);
svgConverte(svgCode, out, transcoder);
* SVG转JPG
* @param svgFile SVG文件
* @param outFile 输出文件
* @throws TranscoderException
* @throws IOException
public void svg2JPEG(File svgFile, File outFile) throws TranscoderException, IOException {
Transcoder transcoder = new JPEGTranscoder();
//为防止ERROR: The JPEG quality has not been specified. Use the default one: no compression 错误,需如下配置
transcoder.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, 0.99f);
svgConverte(svgFile, outFile, transcoder);
* SVG转PDF
* @param svgCode SVG代码
* @param outpath 输出路径
* @throws TranscoderException
* @throws IOException
public void svg2PDF(String svgCode, String outpath) throws TranscoderException, IOException {
Transcoder transcoder = new PDFTranscoder();
svgConverte(svgCode, outpath, transcoder);
* SVG转PS
* @param svgCode
* @param outpath
* @throws TranscoderException
* @throws IOException
public void svg2PS(String svgCode, String outpath) throws TranscoderException, IOException {
Transcoder transcoder = new PSTranscoder();
svgConverte(svgCode, outpath, transcoder);
* SVG转PS
* @param svgCode SVG代码
* @param out 输出流
* @throws TranscoderException
* @throws IOException
public void svg2PS(String svgCode, OutputStream out) throws TranscoderException, IOException {
Transcoder transcoder = new PSTranscoder();
svgConverte(svgCode, out, transcoder);
* SVG转EPS
* @param svgCode SVG代码
* @param out 输出流
* @throws TranscoderException
* @throws IOException
public void svg2EPS(String svgCode, OutputStream out) throws TranscoderException, IOException {
Transcoder transcoder = new EPSTranscoder();
svgConverte(svgCode, out, transcoder);
* SVG转EPS
* @param svgCode
* @param outpath
* @throws TranscoderException
* @throws IOException
public void svg2EPS(String svgCode, String outpath) throws TranscoderException, IOException {
Transcoder transcoder = new EPSTranscoder();
svgConverte(svgCode, outpath, transcoder);
* SVG转PDF
* @param svgCode SVG代码
* @param out 输出流
* @throws TranscoderException
* @throws IOException
public void svg2PDF(String svgCode, OutputStream out) throws TranscoderException, IOException {
Transcoder transcoder = new PDFTranscoder();
svgConverte(svgCode, out, transcoder);
* SVG转PDF
* @param svgFile SVG文件
* @param outFile 输出文件
* @throws TranscoderException
* @throws IOException
public void svg2PDF(File svgFile, File outFile) throws TranscoderException, IOException {
Transcoder transcoder = new PDFTranscoder();
svgConverte(svgFile, outFile, transcoder);
private void svgConverte(String svgCode, String outpath, Transcoder transcoder) throws IOException, TranscoderException {
svgConverte(svgCode, getOutputStream(outpath), transcoder);
private void svgConverte(File svg, File outFile, Transcoder transcoder) throws IOException, TranscoderException {
svgConverte(svg2String(getInputStream(svg)), getOutputStream(outFile), transcoder);
private void svgConverte(String svgCode, OutputStream out, Transcoder transcoder) throws IOException, TranscoderException {
svgCode = svgCode.replaceAll(":rect", "rect");
TranscoderInput input = new TranscoderInput(new ByteArrayInputStream(svgCode.getBytes()));
TranscoderOutput output = new TranscoderOutput(out);
svgConverte(input, output, transcoder);
private void svgConverte(TranscoderInput input, TranscoderOutput output, Transcoder transcoder) throws IOException, TranscoderException {
transcoder.transcode(input, output);
public InputStream getInputStream(File file) throws IOException {
return new FileInputStream(file);
public InputStream getInputStream(String filepath) throws IOException {
File file = new File(filepath);
if (file.exists())
return getInputStream(file);
return null;
public OutputStream getOutputStream(File outFile) throws IOException {
return new FileOutputStream(outFile);
public OutputStream getOutputStream(String outpath) throws IOException {
File file = new File(outpath);
if (!file.exists())
file.createNewFile();
return getOutputStream(file);
* 默认使用编码UTF-8 SVG文件输入流转String
* @param svgFile
* @return SVG代码
* @throws IOException
public String svg2String(File svgFile) throws IOException {
InputStream in = getInputStream(svgFile);
return svg2String(in, "UTF-8");
* SVG文件输入流转String
* @param svgFile
* @return SVG代码
* @throws IOException
public String svg2String(File svgFile, String charset) throws IOException {
InputStream in = getInputStream(svgFile);
return svg2String(in, charset);
* 默认使用编码UTF-8SVG输入流转String
* @param in
* @return SVG代码
public String svg2String(InputStream in) {
return svg2String(in, "UTF-8");
* 指定字符集SVG输入流转String
* @param in 输入流
* @param charset 字符编码
* @return SVG代码
public String svg2String(InputStream in, String charset) {
StringBuffer svgBuffer = new StringBuffer();
BufferedReader bfr = null;
try {
InputStreamReader inputStreamReader = new InputStreamReader(in, charset);
bfr = new BufferedReader(inputStreamReader);
String line = "";
while ((line = bfr.readLine()) != null) {
svgBuffer.append(line);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (bfr != null)
bfr.close();
} catch (IOException e) {
e.printStackTrace();
return svgBuffer.toString();
注意:目前遇到的问题是svg转成eps文件可以成功,但是转出来的eps颜色会丢,查询官网目前还没有解决,如果解决了 后续会修改掉。
https://xmlgraphics.apache.org/fop/
https://xmlgraphics.apache.org/batik/
issues:
https://issues.apache.org/jira/projects/FOP/issues/FOP-1487?filter=allopenissues
在网上找了一大圈方法。试过imagemagick等其他方式进行转换 都无法满足需要。转换后的矢量文件是无法进行编辑的,就一张图片。无法满足我的要求,所支持的相关格式:具体请查看相关源码:org.apache.batik.transcoder.Transcoderpom: <!-- https://mvnrepository.com/artifact/...
#SVG到JSON一种将SVG字符串转换为JSON数据并可选地呈现统计信息的方法。
#Usage创建新实例,提供svg字符串,还可以选择传入options 。
var svg_json = new SVGToJSON ( svg [ , options ] ) ;
#API ## Object.json SVGToJSON()返回一个对象。 OBJ.json是主要的JSON数据。 它是所有SVG标签的数组。
var svg_json = new SVGToJSON ( svg ) ;
svg_json = {
json : [ ... ]
## Object.json [I]中的每个标签Object.json有四个值。
var first_tag = svg_json . json [ 0 ] ;
first_tag = {
attrs : {
Time-based One-time Password algorithm, 是一种共享密钥和当前时间计算一次性密码的算法。
利用时间戳和邮箱生成一段时间内唯一的验证码。验证时使用用户输入的验证码和一段时间内生成的验证码集合对比,如果在此集合,则证明验证码有效。摆脱使用redis等方式存储和对比验证码。
class Totp {
private $salt = 'salt'; // 盐
private $refreshInterval = 30; //每隔
这篇文章主要讲讲 通过java去解析不同地方的json文件
通常我们需要解析本地的json文件或者服务器上的json文件。我们用来解析json格式的jar包有很多,jackson,fastjson,gson都行。但本人喜欢用fastjson。所以本篇都是以fastjson来解析json文件。
1.解析本地json文件
随便把一个json文件存储在本地的一个文件夹下,然后通过文件流将json文件内容读取出来。
然后转换成String,最后转json对象,然后再解析,获取自己想要的数据。
首先我们这个json文
这将在HTML文档中创建一个图像元素,其源文件为1.svg,同时还提供了一个备用文本说明,以便于屏幕阅读器可以理解该图像的内容。
请注意,SVG文件的路径应该相对于HTML文件的位置来引用。例如,如果HTML和SVG文件位于同一目录中,则可以直接使用文件名。如果SVG文件位于HTML文件的子目录中,则需要相对于HTML文件的路径来引用。例如,如果SVG文件位于HTML文件的“images”子目录中,则应使用以下代码:
```html
<img src="images/1.svg" alt="SVG Image">