Thanks to Paulo for helping me get my table to display an SVG image several days ago.  However, I’m having problems now extending my simple example to a more complicated one and I was hoping someone could point out what I’m doing wrong.  Here’s my goal…

 

I have a framework that populates an iText Table object with iText Cell objects.  The framework later goes back and adds the Cells to the “correct” place in a table.  I am pretty confident that this part of my code works, since I can use it to successfully populate the cells with PNG-based images.  Where I’m going crazy is trying to extend this to add SVG-based images to the cell.  I took some code from these archives that uses the batik libraries and modified it to create an ImgTemplate from the resulting PdfTemplate object.  The resulting pdf document shows what looks like empty images (apparently of the correct size) in my cells.  Where am I screwing up here (efficiency aside I’d just like something to work first!)?  My code is pasted below.

 

 

Thanks,

Chris

 

 

 

 

// “writer” is a valid PdfWriter object and was created with

// the Document object I’m adding the Table and Cells to.  It

// was already opened with writer.open();

//

// width and height are ints, both set to 125.

//

// The c:\svg.svg file is a valid svg that is 125 x 125 pixels.

//

// m_columnData is a container that creates cells from Elements.

// It works correctly if img is a PNG image.

 

PdfContentByte cb = writer.getDirectContent();

 

PdfTemplate template = cb.createTemplate(width, height);

DefaultFontMapper mapper = new DefaultFontMapper();

Graphics2D g2 = template.createGraphics(width, height);

PrintTranscoder prm = new PrintTranscoder();

prm.addTranscodingHint(PrintTranscoder.KEY_WIDTH, new Float(width));

prm.addTranscodingHint(PrintTranscoder.KEY_HEIGHT, new Float(height));

TranscoderInput ti = new TranscoderInput("file:///C:/svg.svg");

 

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);

m_columnData.addRow(img);

 

 

Reply via email to