Skip to content

Instantly share code, notes, and snippets.

@onozaty
Created February 8, 2015 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onozaty/2f5ae77e13b608ec701c to your computer and use it in GitHub Desktop.
Save onozaty/2f5ae77e13b608ec701c to your computer and use it in GitHub Desktop.
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