As promised here is a very simple PDF that contains a SVG-based image.
The SVG contains the following data:
<? Xml version = "1.0" standalone = "no"?>
<! DOCTYPE svg PUBLIC "-// W3C // dtd svg 1.1 // EN"
Http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd>
<Svg width = "300" height = "300" version = "1.1"
Xmlns = "http://www.w3.org/2000/svg">
<Rect x = "40" y = "20" rx = "20" ry = "20" width = "250" height = "250"
Style = "fill: red; stroke: black; stroke-width: 1;"/>
</Svg>
Here is the Java code:
Public static void main (String [] args ){
Document document = new Document ();
Try {
Using writer = Using writer. getInstance (document,
New FileOutputStream ("svgworkflow "));
Document. open ();
Document. add (new Paragraph ("SVG Example "));
Int width = 250;
Int height = 250;
Required contentbyte cb = writer. getDirectContent ();
Repeated template = cb. createTemplate (width, height );
Graphics2D g2 = template. createGraphics (width, height );
PrintTranscoder prm = new PrintTranscoder ();
TranscoderInput ti = new TranscoderInput ("file: // c: \ java \ svg. xml ");
Prm. transcode (ti, null );
PageFormat pg = new PageFormat ();
Paper pp = new Paper ();
Pp. setSize (width, height );
Pp. setImageableArea (0, 0, width, height );
Pg. setPaper (pp );
Prm. print (g2, pg, 0 );
G2.dispose ();
ImgTemplate img = new ImgTemplate (template );
Document. add (img );
} Catch (incluentexception e ){
System. err. println (e );
} Catch (IOException e ){
System. err. println (e );
}
Document. close ();
}
Keep in mind that you will need the Batik and Xerces libraries in addition to the iTExt jar file.
Http://xml.apache.org/batik/
Http://www.lowagie.com/iText/
Http://xml.apache.org/xerces2-j/
From: http://jroller.com/page/ghillert? Entry = svg_and_pdf_example