Tan Hui Siang - Julie (DHL MY) wrote:
Hi,I am trying to generate pdf file from my Servlet and am getting the following error. Please help as I have tried changing the code multiple times but with no success :(
I have put your code in a standalone example. See attachments. You made some odd choices: the outer table has two columns, but all the columns have colspan 2. Why not make a table with one column? Also you have 2 only 2 rows AND you set the headerrows count to 2. This doesn't make sense. If you remove this line, the PDF gets generated without any problem. Use Occam's razor to remove everything that is not necessary in the java example in attachment. If you have further questions, use the attached file as reference. br, Bruno
nested_table.pdf
Description: Adobe PDF document
package test;
import java.awt.Color;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;
public class NestedTable {
public static void main(String[] args) {
// step 1: creation of a document-object
Document document = new Document();
try {
// step 2:
// we create a writer
PdfWriter.getInstance(
// that listens to the document
document,
// and directs a PDF-stream to a file
new
FileOutputStream("nested_table.pdf"));
// step 3: we open the document
document.open();
// step 4: we add a table to the document
PdfPTable table = new PdfPTable(2); // tab1 - with 2
col
table.setWidthPercentage(90f);
table.setSplitRows(true);
float[] widths = {0.2f, 0.3f, 0.25f, 0.25f};
PdfPTable nested1 = new PdfPTable(widths); // tab2 -
with 4 cols
nested1.getDefaultCell().setBorderColor(new Color(255,
0, 0));
nested1.addCell("DHL Ref: SR / SO:");
nested1.addCell("srnumber + / + sonumber");
nested1.addCell("Cust Ref 1 / Ref 2:");
nested1.addCell("21408917 / 10705706");
nested1.addCell("Account Name:");
nested1.addCell("Sun Microsystems Bangalore");
nested1.addCell("WMS Order No:");
nested1.addCell("2756853");
nested1.addCell("Requestor Name:");
nested1.addCell("Reqfst name, Reqlst name");
nested1.addCell("Date And Time of Call:");
nested1.addCell("10/06/2005 14:17:43 +8");
nested1.addCell("Requestor Contact:");
nested1.addCell("+653956956");
nested1.addCell("Collection Date & Time:"); // configurable
nested1.addCell("10/06/2005 14:157:47 +8");
nested1.addCell("Service Level:");
nested1.addCell("Part Return");
nested1.addCell("Revised Time of Collection"); //
configurable
nested1.addCell("-");
nested1.addCell("Agent Name:");
nested1.addCell("SIMON");
nested1.addCell("blank");
nested1.addCell("blank");
table.getDefaultCell().setColspan(2);
//table.setHeaderRows(2);
table.addCell("Sun Microsystem Part Return SPC:SYD
ASL89012345"); //configurable
table.addCell(nested1);
document.add(table);
} catch (DocumentException de) {
System.err.println(de.getMessage());
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
}
// step 5: we close the document
document.close();
}
}
------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions
