Thanks for the suggestion, Paulo. Unfortunately, I didn't see the svg
on the page. It seemed to create an empty page before my table (my
table used to be the first and only thing in the document, but now
there's an empty page before it). You suggested that my svg might be
off limits, but I don't think that's the case. Here's my simple svg:
<svg width="128" height="128" >
<line x1="5" y1="5" x2="122" y2="122" stroke="rgb(0, 0, 0)" />
<line x1="122" y1="5" x2="5" y2="122" stroke="rgb(0, 0, 0)" />
<text x="15" y="65" stroke="rgb(200, 0, 200)">I curse thee, SVG</text>
</svg>
This svg image shows up fine in the Adobe SVG plugin, and it also works
fine in my little test iText table. Because it worked fine in my test
iText table, I just cut-and-pasted that exact working code where my
current non-functional code was. This code works great in a stand-alone
application, but it also doesn't show any images in my table. What
could possibly interfere with this code which works in an application
all by itself?
Thanks,
Chris
Document d = new Document();
PdfWriter writer = PdfWriter.getInstance(d, new
FileOutputStream("d:\\crap.pdf"));
d.open();
writer.open();
PdfContentByte cb = writer.getDirectContent();
width = 300;
height = 300;
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);
Table t = new Table(2, 2);
t.addCell(new Cell("Hello world"), 0, 0);
t.addCell(new Cell("0,1"), 0, 1);
t.addCell(new Cell("1,0"), 1, 0);
Cell imgholder = new Cell();
imgholder.addElement(img);
t.addCell(imgholder, 1, 1);
d.add(t);
d.close();
writer.close();
-----Original Message-----
From: Paulo Soares [mailto:[EMAIL PROTECTED]
Sent: Tuesday, July 29, 2003 2:40 AM
To: Chris Farmer; [EMAIL PROTECTED]
Subject: Re: [iText-questions] Adding svg images to a table, revisited
----- Original Message -----
From: "Chris Farmer" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, July 29, 2003 1:12
Subject: [iText-questions] Adding svg images to a table, revisited
>
> 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);
Put here:
img.setAbsolutePosition(0, 0);
cb.addImage(img);
If it shows the image then I'll need a complete runnable example to test
it
here.
If it doesn't the svg is probably off limits.
Best Regards,
Paulo Soares
> m_columnData.addRow(img);
>
>
>
-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions