Make boylescript = 0.
----- Original Message -----
From: "David Marcillo" <[EMAIL PROTECTED]>
To: <[email protected]>
Cc: <[EMAIL PROTECTED]>
Sent: Tuesday, January 24, 2006 7:55 PM
Subject: [iText-questions] PdfPTable writing additional row - Repost with
full sample
Hello folks,
I am new to itext and need a little help with PdfPTable.
Brief problem description: I am getting an extra row printed at the end of
an inner
table.
Problem Process Overview:
1- I create an inner table with six columns and no borders.
2- I add data to each column of the inner table.
3- I create a second table with borders and one cell,
so I can insert the first table.
4- I add the first inner table to the second table with borders
5- I send the second table to the document object
6- * Problem !!! I get an extra row printed at the end of the inner table
I am including a small example to reproduce this problem;
1 - web.xml file
2 - test101.html file
3 - servlet file
web.xml file follows
----------------------------------------------
<?xml version = '1.0' encoding = 'windows-1252'?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee">
<description> web.xml file for testing iText </description>
<!-- Test Servlets -->
<servlet>
<servlet-name>pdfTestServlet</servlet-name>
<servlet-class>com.abrecorp.servlet.pdf.pdfTestServlet</servlet-class>
</servlet>
<!-- Test Servlet Mapping -->
<servlet-mapping>
<servlet-name>pdfTestServlet</servlet-name>
<url-pattern>/test101</url-pattern>
</servlet-mapping>
<mime-mapping>
<extension>html</extension>
<mime-type>text/html</mime-type>
</mime-mapping>
<mime-mapping>
<extension>txt</extension>
<mime-type>text/plain</mime-type>
</mime-mapping>
<!-- The Welcome File List -->
<welcome-file-list>
<welcome-file>test101.html</welcome-file>
</welcome-file-list>
</web-app>
----------------------------------------------
test101.html file follows
----------------------------------------------
<html><head><title>Test iText</title></head>
<body bgcolor=white>
<table border="0" border="100%">
<tr>
<td><h1>Test iText Page</h1></td>
<td>This is the HTML page to call iText</td>
</tr>
<tr> <td align="left" colsapn=2> </td></tr>
<tr> <td align="left" colsapn=2> </td></tr>
<tr> <td align="left" colsapn=2> </td></tr>
<tr> <td align="left" colsapn=2> </td></tr>
<tr>
<th align="right">test PDF Servlet</th>
<td align="left"><A HREF="test101?test=test">Click Here</A></td>
</tr>
</table>
</body>
</html>
----------------------------------------------
servlet file follows
----------------------------------------------
package com.abrecorp.servlet.pdf;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
// import itext pdf generator
import com.lowagie.text.*;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfPCell;
public class pdfTestServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException
{
int iRetCode=0;
RequestDispatcher aReqDispObj=null;
iRetCode = generatePDF ( response ) ;
}
// end-of method doGet()
/**
* generate PDF File
* return -1 for errors
* return 0 for sucsess
*/
public int generatePDF( HttpServletResponse response ) {
int iRetCode=0 ;
String aszTemp=null;
if(null == response) return -1;
// tell the browser we will be sending a pdf file
response.setContentType("application/pdf");
// temporary opbjects used
PdfPTable aInnerTable=null;
PdfPTable aBorderTable=null;
PdfPCell aTempCell=null;
Chunk aTempChunk=null;
Paragraph aTempParagraph=null;
Document aTempDocument=null;
Font aTempFont12 = new Font(Font.TIMES_ROMAN, 12);
Font aTempFont10 = new Font(Font.TIMES_ROMAN, 10);
Font aTempFont8 = new Font(Font.TIMES_ROMAN, 8);
Font aTempFont6 = new Font(Font.TIMES_ROMAN, 6);
float boylescript = 18.0f;
// creation document-object
aTempDocument = new Document();
try {
// we create a writer for the document
PdfWriter.getInstance(aTempDocument, response.getOutputStream());
// open the document
aTempDocument.open();
// aTempDocument.addTitle("Quote");
aTempDocument.add(new Paragraph(Chunk.NEWLINE));
//============ Start Services Information
===================================
// create a table
aInnerTable = new PdfPTable( new float []{3f, 1f, 1f, 1f, 1f, 1f } );
aInnerTable.setHorizontalAlignment( Element.ALIGN_LEFT );
aInnerTable.setWidthPercentage(100);
aTempCell = aInnerTable.getDefaultCell();
aTempCell.setHorizontalAlignment( Element.ALIGN_LEFT );
aTempCell.disableBorderSide( Rectangle.LEFT );
aTempCell.disableBorderSide( Rectangle.RIGHT );
aTempCell.disableBorderSide( Rectangle.TOP );
aTempCell.disableBorderSide( Rectangle.BOTTOM );
// cell Row1 Col1
aszTemp = "Service";
aTempChunk = new Chunk( aszTemp, aTempFont12 );
aTempChunk.setTextRise(boylescript);
aTempParagraph = new Paragraph();
aTempParagraph.add( aTempChunk );
aInnerTable.addCell(aTempParagraph);
// cell Row1 Col2
aszTemp = "Quantity";
aTempChunk = new Chunk( aszTemp, aTempFont10 );
aTempChunk.setTextRise(boylescript);
aTempParagraph = new Paragraph();
aTempParagraph.add( aTempChunk );
aInnerTable.addCell(aTempParagraph);
// cell Row1 Col3
aszTemp = "Units";
aTempChunk = new Chunk( aszTemp, aTempFont10 );
aTempChunk.setTextRise(boylescript);
aTempParagraph = new Paragraph();
aTempParagraph.add( aTempChunk );
aInnerTable.addCell(aTempParagraph);
// cell Row1 Col4
aszTemp = "Rate";
aTempChunk = new Chunk( aszTemp, aTempFont10 );
aTempChunk.setTextRise(boylescript);
aTempParagraph = new Paragraph();
aTempParagraph.add( aTempChunk );
aInnerTable.addCell(aTempParagraph);
// cell Row1 Col5
aszTemp = "Min. Chg.";
aTempChunk = new Chunk( aszTemp, aTempFont10 );
aTempChunk.setTextRise(boylescript);
aTempParagraph = new Paragraph();
aTempParagraph.add( aTempChunk );
aInnerTable.addCell(aTempParagraph);
// cell Row1 Col6
aszTemp = "Charges";
aTempChunk = new Chunk( aszTemp, aTempFont10 );
aTempChunk.setTextRise(boylescript);
aTempParagraph = new Paragraph();
aTempParagraph.add( aTempChunk );
aInnerTable.addCell(aTempParagraph);
int iTotal=10;
int iCellNumber=6;
for (int iIndex=0; iIndex < iTotal; iIndex++){
for (int iIndex2=0; iIndex2 < iCellNumber; iIndex2++){
aszTemp = "Row " + ( iIndex + 1 + " Cell " + ( iIndex2 + 1) ) ;
aTempChunk = new Chunk( aszTemp, aTempFont10 );
aTempChunk.setTextRise(boylescript);
aTempParagraph = new Paragraph();
aTempParagraph.add( aTempChunk );
aInnerTable.addCell(aTempParagraph);
}
}
aTempCell = aInnerTable.getDefaultCell();
aTempCell.setHorizontalAlignment( Element.ALIGN_LEFT );
aTempCell.disableBorderSide( Rectangle.LEFT );
aTempCell.disableBorderSide( Rectangle.RIGHT );
aTempCell.disableBorderSide( Rectangle.TOP );
aTempCell.enableBorderSide( Rectangle.BOTTOM );
aTempCell.setColspan(1);
// blank Header
aTempParagraph = new Paragraph();
aTempParagraph.add( Chunk.NEWLINE );
aInnerTable.addCell(aTempParagraph);
aInnerTable.addCell(aTempParagraph);
aInnerTable.addCell(aTempParagraph);
aInnerTable.addCell(aTempParagraph);
aInnerTable.addCell(aTempParagraph);
aInnerTable.addCell(aTempParagraph);
// cell Row1 Col1
aszTemp = "Total Estimated Cost: ";
aTempChunk = new Chunk( aszTemp, aTempFont12 );
aTempChunk.setTextRise(boylescript);
aTempParagraph = new Paragraph();
aTempParagraph.add( aTempChunk );
PdfPCell atotalcell = new PdfPCell( aTempParagraph );
atotalcell.setColspan(4);
atotalcell.setHorizontalAlignment( Element.ALIGN_RIGHT );
aInnerTable.addCell(atotalcell);
// blank cell
aTempParagraph = new Paragraph();
aTempParagraph.add( Chunk.NEWLINE );
atotalcell = new PdfPCell( aTempParagraph );
atotalcell.setColspan(1);
atotalcell.setHorizontalAlignment( Element.ALIGN_LEFT );
aInnerTable.addCell(atotalcell);
// cell B2
aszTemp = "$ 3,567.00";
aTempChunk = new Chunk( aszTemp, aTempFont12 );
aTempChunk.setTextRise(boylescript);
aTempParagraph = new Paragraph();
aTempParagraph.add( aTempChunk );
atotalcell = new PdfPCell( aTempParagraph );
atotalcell.setColspan(1);
atotalcell.setHorizontalAlignment( Element.ALIGN_LEFT );
aInnerTable.addCell(atotalcell);
aTempCell = aInnerTable.getDefaultCell();
aTempCell.setHorizontalAlignment( Element.ALIGN_LEFT );
aTempCell.disableBorderSide( Rectangle.LEFT );
aTempCell.disableBorderSide( Rectangle.RIGHT );
aTempCell.disableBorderSide( Rectangle.TOP );
aTempCell.disableBorderSide( Rectangle.BOTTOM );
aTempCell.setColspan(1);
aTempCell = aInnerTable.getDefaultCell();
aTempCell.setHorizontalAlignment( Element.ALIGN_LEFT );
aTempCell.disableBorderSide( Rectangle.LEFT );
aTempCell.disableBorderSide( Rectangle.RIGHT );
aTempCell.disableBorderSide( Rectangle.TOP );
aTempCell.disableBorderSide( Rectangle.BOTTOM );
// create Boderder table
aBorderTable = new PdfPTable( 1 );
aBorderTable.setHorizontalAlignment( Element.ALIGN_LEFT );
aBorderTable.setWidthPercentage(100);
aTempCell = aBorderTable.getDefaultCell();
aTempCell.setHorizontalAlignment( Element.ALIGN_LEFT );
aTempCell.enableBorderSide( Rectangle.LEFT );
aTempCell.enableBorderSide( Rectangle.RIGHT );
aTempCell.enableBorderSide( Rectangle.TOP );
aTempCell.enableBorderSide( Rectangle.BOTTOM );
aBorderTable.addCell(aInnerTable);
aTempDocument.add(aBorderTable);
aInnerTable=null;
aBorderTable=null;
//============ END Services Information
===================================
aTempDocument.add(new Paragraph(Chunk.NEWLINE));
} catch (DocumentException de) {
iRetCode=-1 ;
de.printStackTrace();
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
iRetCode=-1 ;
}
// step 5: we close the document
aTempDocument.close();
return iRetCode;
}
// end-of method generatePDF()
}
----------------------------------------------
Thanks,
David Marcillo
[EMAIL PROTECTED]
-------------------------------------------------------
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://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
-------------------------------------------------------
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://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions