First, my code:
<%@ page import="java.io.*, com.lowagie.text.*, com.lowagie.text.pdf.*, com.lowagie.text.html.*, java.awt.Color" %>
<% response.setContentType( "application/pdf" );
// creation of the document with a certain size and certain margins
Document document = new Document(PageSize.LETTER, 50, 50, 50, 50);
try {
// creation of the different writers
ByteArrayOutputStream buffer = new ByteArrayOutputStream(); PdfWriter.getInstance(document, buffer);
// we add some meta information to the document
document.addSubject("Current inventory as of ");
document.open();
Table datatable = new Table(7);
datatable.setPadding(4); datatable.setSpacing(0); datatable.setBorder(Rectangle.NO_BORDER); datatable.setWidths( new int[] { 10, 10, 10, 10, 10, 10, 60 } ); datatable.setWidth(120);
Image jpg = Image.getInstance("/home/workbench/web_sites/paragonis/images/PARAGONlogo.gif");
jpg.setBorder(Rectangle.NO_BORDER);
jpg.scalePercent(50);
Cell cell = new Cell(); cell.add(jpg); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setLeading(30); cell.setColspan(5); cell.setBorder(Rectangle.NO_BORDER); datatable.addCell(cell);
cell = new Cell("PO Box 1234 Hometown, St 27282-1234\n" + "Phone: 336-555-1212\nContact: David"); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setColspan(2); cell.setBorder(Rectangle.NO_BORDER); datatable.addCell(cell);
datatable.setDefaultCellBorder(Rectangle.BOTTOM); datatable.setDefaultCellBorderColor(new Color(0x33, 0x33, 0x33)); datatable.setDefaultCellBorderWidth(2); datatable.setDefaultHorizontalAlignment(Element.ALIGN_CENTER);
datatable.addCell(new Phrase("Receipt Date", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD)));
datatable.addCell(new Phrase("Type", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD)));
datatable.addCell(new Phrase("Make", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD)));
datatable.addCell(new Phrase("Model", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD)));
datatable.addCell(new Phrase("Meter", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD)));
datatable.setDefaultColspan(2);
datatable.setDefaultHorizontalAlignment(Element.ALIGN_LEFT);
datatable.addCell(new Phrase("Description", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD)));
// this is the end of the table header datatable.endHeaders();
Cell commonCell = new Cell(); commonCell.setVerticalAlignment(Element.ALIGN_TOP); commonCell.setHorizontalAlignment(Element.ALIGN_CENTER); commonCell.setColspan(1); // commonCell.setRowspan(2); commonCell.setNoWrap(true);
Cell singleLineCell = new Cell(); singleLineCell.setVerticalAlignment(Element.ALIGN_TOP); singleLineCell.setHorizontalAlignment(Element.ALIGN_LEFT); singleLineCell.setColspan(1); singleLineCell.setRowspan(1); singleLineCell.setNoWrap(false);
datatable.setDefaultColspan(1); datatable.setDefaultCellBorderWidth(1); datatable.setDefaultRowspan(1);
for (int i = 1; i < 30; i++) {
datatable.setDefaultLayout(commonCell); datatable.addCell("12312000"); // datatable.addCell("Duplicator"); datatable.addCell("Gestetner"); datatable.addCell("FS 9999B"); datatable.addCell("9999999");
datatable.setDefaultLayout(singleLineCell); datatable.addCell("Accessories"); datatable.addCell("This is a long description of the accessories"); }
document.add(datatable);
// we close the document
document.close();
// step 6: we output the writer as bytes to the response output DataOutput output = new DataOutputStream( response.getOutputStream() ); byte[] bytes = buffer.toByteArray(); response.setContentLength(bytes.length); for( int i = 0; i < bytes.length; i++ ) { output.writeByte( bytes[i] ); }
} catch(Exception e) { out.print("Exception: " + e.getClass().getName() + ", " + e.getMessage()); } %>
Now this code as presented work just like it is supposed to. However, if you uncomment the datatable.addCell("Duplicator"); line, the error posted in the subject is thrown. Why? and what do I do to fix it? I don't see what is happening on that line that makes a difference.
Thank you for your help in advance.
------------------------------------------------------- This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click _______________________________________________ iText-questions mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/itext-questions