Hello,

I have got a server application using iText which should generate pdf documents for different user data. Therefore I want to cache as much as possible on the server.

One way would be to generate pdf with acroforms and store them on the server and afterwards fill them with data.

However, I am wanted to try a different approach. I created a chapter with all elements and stored this chapter object on the server. If the user calls a site, simple make this:

Document document = new Document ();
PdfWriter writer1 = PdfWriter.getInstance(document,new FileOutputStream("output.pdf"));
document.open();
document.add (chapter); // this chapter contains the document
dcouemnt.close ();

However, no I have got the problem how to get the user data in the chapter. Therefore I added a table to the chapter and added a PdfPCellEvent to a chell. Now I want to print text in the cellLayout - Method of the Event - Object but it doesn't work.

I alwasy get this Excepiton:

Exception in thread "main" java.lang.RuntimeException: The page 1 was requested but the document has only 0 pages.

However, if I just try to fill the table, it works.

Question 1: Is it possible what I want to do? If yes, where is the error in my code?

Question 2: Is there another, easier, possibility to swap the text after an element was added to another element? I also tried generic tags on chunks, but I think its more difficult than cell events.

This is my code:

public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) {

       PdfContentByte cb = canvases [PdfPTable.TEXTCANVAS];

//works:
        position.setGrayFill(0.5f);
        cb.rectangle(position);

//doesn't work:
// cell.addElement(new Paragraph("Test"));

// doesn't work:
//cb.beginText();
//cb.showText("test");
//cb.endText();

//doesn't work
// PdfTemplate template=cb.createTemplate(20,20);
// template.beginText();
// template.showText("Test");
// template.endText();
// cb.addTemplate(template,10,10);
}




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to