import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; 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 Test { public static void main(String[] argv) throws TranscoderException, FileNotFoundException { Transcoder transcoder = new PDFTranscoder(); TranscoderInput transcoderInput = new TranscoderInput(new FileInputStream(new File("/tmp/test.svg"))); TranscoderOutput transcoderOutput = new TranscoderOutput(new FileOutputStream(new File("/tmp/test.pdf"))); transcoder.transcode(transcoderInput, transcoderOutput); } }
public void handleOption() { index++; transcoder.addTranscodingHint(SVGTranscoder.KEY_FORMAT, Boolean.FALSE); }
/** * Transcode a document into a file using the given transcoder. * * @param file Output file * @param transcoder Transcoder to use * @throws IOException On write errors * @throws TranscoderException On input/parsing errors */ protected void transcode(File file, Transcoder transcoder) throws IOException, TranscoderException { // Disable validation, performance is more important here (thumbnails!) transcoder.addTranscodingHint(XMLAbstractTranscoder.KEY_XML_PARSER_VALIDATING, Boolean.FALSE); SVGDocument doc = cloneDocument(); TranscoderInput input = new TranscoderInput(doc); OutputStream out = new BufferedOutputStream(new FileOutputStream(file)); TranscoderOutput output = new TranscoderOutput(out); transcoder.transcode(input, output); out.flush(); out.close(); }
transcoder.setTranscodingHints(hints);
/** * Transcode a document into a file using the given transcoder. * * @param file Output file * @param transcoder Transcoder to use * @throws IOException On write errors * @throws TranscoderException On input/parsing errors */ protected void transcode(File file, Transcoder transcoder) throws IOException, TranscoderException { // Disable validation, performance is more important here (thumbnails!) transcoder.addTranscodingHint(XMLAbstractTranscoder.KEY_XML_PARSER_VALIDATING, Boolean.FALSE); SVGDocument doc = cloneDocument(); TranscoderInput input = new TranscoderInput(doc); OutputStream out = new BufferedOutputStream(new FileOutputStream(file)); TranscoderOutput output = new TranscoderOutput(out); transcoder.transcode(input, output); out.flush(); out.close(); }
transcoder.setTranscodingHints(hints);
public void handleOption() { index++; transcoder.addTranscodingHint(SVGTranscoder.KEY_FORMAT, Boolean.FALSE); }
/** * 将SVG输入流转换并写入到JPEG输出流 * * @param reader SVG字符流 * @param output JPEG输出流 * @throws TranscoderException 转换异常 */ public static void svg2jpeg(Reader reader, OutputStream output) throws TranscoderException { if (reader == null) { throw new IllegalArgumentException("Reader must not be null"); } if (output == null) { throw new IllegalArgumentException("OutputStream must not be null"); } Transcoder transcoder = new JPEGTranscoder(); transcoder.transcode(new TranscoderInput(reader), new TranscoderOutput(output)); }
/** * Transcodes the image using the transcoder specified * * @param t * @param svgGenerator * @param useCSS * @param rect * @param fos * @throws IOException * @throws TranscoderException */ public static void transcode(Transcoder t, SVGGraphics2D svgGenerator, boolean useCSS, Rectangle rect, FileOutputStream fos) throws IOException, TranscoderException { PipedWriter pout = new PipedWriter(); BufferedReader rin = new BufferedReader(new PipedReader(pout)); new Piper(svgGenerator, useCSS, pout).start(); t.addTranscodingHint(JPEGTranscoder.KEY_HEIGHT, Float.valueOf(rect.height)); t.addTranscodingHint(JPEGTranscoder.KEY_WIDTH, Float.valueOf(rect.width)); t.transcode(new TranscoderInput(rin), new TranscoderOutput(fos)); }
transcoder.setTranscodingHints(hints);
public void handleOption() { index++; if (index >= arguments.length) { throw new IllegalArgumentException(); } String s = arguments[index++]; transcoder.addTranscodingHint(SVGTranscoder.KEY_XML_DECLARATION, s); }
/** * 将SVG输入流转换并写入到JPEG输出流 * * @param input SVG输入流 * @param output JPEG输出流 * @throws TranscoderException 转换异常 */ public static void svg2jpeg(InputStream input, OutputStream output) throws TranscoderException { if (input == null) { throw new IllegalArgumentException("InputStream must not be null"); } if (output == null) { throw new IllegalArgumentException("OutputStream must not be null"); } Transcoder transcoder = new JPEGTranscoder(); transcoder.transcode(new TranscoderInput(input), new TranscoderOutput(output)); }
transcoder.addTranscodingHint(PNGTranscoder.KEY_BACKGROUND_COLOR, Color.WHITE); } else { transcoder = new JPEGTranscoder(); transcoder.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, jpegQuality); transcoder.transcode(transcoderInput, transcoderOutput);
public void handleOption() { index++; if (index >= arguments.length) { throw new IllegalArgumentException(); } String s = arguments[index++]; transcoder.addTranscodingHint(SVGTranscoder.KEY_XML_DECLARATION, s); }
/** * 将SVG输入流转换并写入到PNG输出流 * * @param reader SVG字符流 * @param output PNG输出流 * @throws TranscoderException 转换异常 */ public static void svg2png(Reader reader, OutputStream output) throws TranscoderException { if (reader == null) { throw new IllegalArgumentException("Reader must not be null"); } if (output == null) { throw new IllegalArgumentException("OutputStream must not be null"); } Transcoder transcoder = new PNGTranscoder(); transcoder.transcode(new TranscoderInput(reader), new TranscoderOutput(output)); }
public void handleOption() { index++; if (index >= arguments.length) { throw new IllegalArgumentException(); } String s = arguments[index++]; transcoder.addTranscodingHint(SVGTranscoder.KEY_PUBLIC_ID, s); }
/** * 将SVG输入流转换并写入到PNG输出流 * * @param input SVG输入流 * @param output PNG输出流 * @throws TranscoderException 转换异常 */ public static void svg2png(InputStream input, OutputStream output) throws TranscoderException { if (input == null) { throw new IllegalArgumentException("InputStream must not be null"); } if (output == null) { throw new IllegalArgumentException("OutputStream must not be null"); } Transcoder transcoder = new PNGTranscoder(); transcoder.transcode(new TranscoderInput(input), new TranscoderOutput(output)); }
public static void setTranscoderStringHint(Transcoder transcoder, String property, TranscodingHints.Key key){ String str = System.getProperty(property); if(str != null){ transcoder.addTranscodingHint(key, str); } }
/** * 将SVG输入流转换并写入到PDF输出流 * * @param reader SVG字符流 * @param output PDF输出流 * @throws TranscoderException 转换异常 */ public static void svg2pdf(Reader reader, OutputStream output) throws TranscoderException { if (reader == null) { throw new IllegalArgumentException("Reader must not be null"); } if (output == null) { throw new IllegalArgumentException("OutputStream must not be null"); } Transcoder transcoder = new PDFTranscoder(); transcoder.transcode(new TranscoderInput(reader), new TranscoderOutput(output)); }
public void handleOption() { index++; if (index >= arguments.length) { throw new IllegalArgumentException(); } String s = arguments[index++]; transcoder.addTranscodingHint(SVGTranscoder.KEY_SYSTEM_ID, s); }