Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SVG2PDFConverter
package com.enjoyxstudy.svg2pdf;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.batik.transcoder.Transcoder;
import org.apache.batik.transcoder.TranscoderException;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;
import org.apache.fop.svg.PDFTranscoder;
public class SVG2PDFConverter {
public static void main(String[] args) throws TranscoderException, IOException {
if (args.length != 2) {
System.err.println(
"引数として入力ファイルパス(SVG)と出力ファイルパス(PDF)を指定してください。");
System.exit(1);
}
String svgFilePath = args[0];
String pdfFilePath = args[1];
new SVG2PDFConverter().convert(svgFilePath, pdfFilePath);
}
public void convert(String svgFilePath, String pdfFilePath) throws TranscoderException,
IOException {
InputStream svgFileStream = new FileInputStream(svgFilePath);
try {
OutputStream pdfFileStream = new BufferedOutputStream(new FileOutputStream(pdfFilePath));
try {
TranscoderInput input = new TranscoderInput(svgFileStream);
TranscoderOutput output = new TranscoderOutput(pdfFileStream);
Transcoder transcoder = new PDFTranscoder();
transcoder.transcode(input, output);
} finally {
pdfFileStream.close();
}
} finally {
svgFileStream.close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.