1 17 18 19 20 package embedding; 21 22 import java.io.File ; 24 import java.io.IOException ; 25 import java.io.InputStream ; 26 import java.io.OutputStream ; 27 28 import org.apache.batik.transcoder.Transcoder; 30 import org.apache.batik.transcoder.TranscoderException; 31 import org.apache.batik.transcoder.TranscoderInput; 32 import org.apache.batik.transcoder.TranscoderOutput; 33 34 import org.apache.fop.svg.PDFTranscoder; 36 37 40 public class ExampleSVG2PDF { 41 42 49 public void convertSVG2PDF(File svg, File pdf) throws IOException , TranscoderException { 50 51 Transcoder transcoder = new PDFTranscoder(); 53 55 InputStream in = new java.io.FileInputStream (svg); 57 try { 58 TranscoderInput input = new TranscoderInput(in); 59 60 OutputStream out = new java.io.FileOutputStream (pdf); 62 out = new java.io.BufferedOutputStream (out); 63 try { 64 TranscoderOutput output = new TranscoderOutput(out); 65 66 transcoder.transcode(input, output); 68 } finally { 69 out.close(); 70 } 71 } finally { 72 in.close(); 73 } 74 } 75 76 77 81 public static void main(String [] args) { 82 try { 83 System.out.println("FOP ExampleSVG2PDF\n"); 84 System.out.println("Preparing..."); 85 86 File baseDir = new File ("."); 88 File outDir = new File (baseDir, "out"); 89 outDir.mkdirs(); 90 91 File svgfile = new File (baseDir, "xml/svg/helloworld.svg"); 93 File pdffile = new File (outDir, "ResultSVG2PDF.pdf"); 94 95 System.out.println("Input: SVG (" + svgfile + ")"); 96 System.out.println("Output: PDF (" + pdffile + ")"); 97 System.out.println(); 98 System.out.println("Transforming..."); 99 100 ExampleSVG2PDF app = new ExampleSVG2PDF(); 101 app.convertSVG2PDF(svgfile, pdffile); 102 103 System.out.println("Success!"); 104 } catch (Exception e) { 105 e.printStackTrace(System.err); 106 System.exit(-1); 107 } 108 } 109 } 110 | Popular Tags |