New paragraph is appending data from previous one.
- From: Antonio Gurisatti <maguri (at) epm.net.co>
- Date: Thu, 18 May 2006 23:24:58 -0500
I'm brand new using iText and I'm trying to build some reports in an
Eclipse RCP application.
The report is very simple. It reads some records from a database and
prints them.
This is the source:
package com.maguri.derbypad.reports;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Font;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
import com.maguri.derbypad.db.sql.NavigatorSql;
import com.maguri.utilities.DateUtilities;
/**
* (at) author agurisatti
*
*/
public class ObjectInventoryReport {
Font tit1 = new Font(Font.HELVETICA, 12, Font.BOLD);
Font tit2 = new Font(Font.HELVETICA, 9, Font.BOLD);
Font tit3 = new Font(Font.HELVETICA, 7, Font.NORMAL);
Font paragraph1 = new Font(Font.HELVETICA, 8, Font.NORMAL);
protected Document document;
protected Paragraph title1;
protected Paragraph title2;
protected Paragraph title3;
protected Paragraph emptyline = new Paragraph(" ");
protected Paragraph pschema;
protected Chunk schemaLabel = new Chunk(" Schema: ", tit2);
protected Chunk schemaName;
/**
*
*/
public ObjectInventoryReport() {
initialize();
}
private void initialize() {
document = new Document();
try {
PdfWriter.getInstance(document, new FileOutputStream(
"D:/Temporal/HelloWorld.pdf"));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (DocumentException e) {
e.printStackTrace();
}
document.setPageSize(PageSize.LETTER);
document.addTitle("Object Inventory");
document.addSubject("The inventory of database objects");
document.addAuthor("maguriWorks");
document.addCreator("DerbyPad 1.0");
// Left, right, top, bottom in points (72 x inch)
document.setMargins(72, 40, 72, 36);
configureTitles();
}
private void configureTitles() {
title1 = new Paragraph("DerbyPad 1.0", tit3);
title2 = new Paragraph(
"Generated on " + DateUtilities.getCurrentDate(), tit3);
title3 = new Paragraph("Object Inventory", tit1);
}
public void generateDocument() {
document.open();
printTitles();
ResultSet rs = NavigatorSql.getSchemas("%");
try {
while (rs.next()) {
printSchemaTitle(rs.getString(1));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
document.close();
}
private void printTitles() {
try {
document.add(title1);
document.add(title2);
document.add(title3);
} catch (DocumentException e) {
e.printStackTrace();
}
}
private void printSchemaTitle(String schName) {
pschema = new Paragraph();
Chunk ch = new Chunk(schName, tit2);
* pschema.add(schemaLabel);
pschema.add(ch);*
try {
document.add(emptyline);
document.add(pschema);
} catch (DocumentException e) {
e.printStackTrace();
}
}
}
The result is quite odd:
DerbyPad 1.0
Generated on 2006-5-18 22:34:40
Object Inventory
Schema: APP
Schema: APPDERBYPAD
Schema: APPDERBYPADESQUEMA1
Schema: APPDERBYPADESQUEMA1ESQUEMA2
Schema: APPDERBYPADESQUEMA1ESQUEMA2ESQUEMA3
Schema: APPDERBYPADESQUEMA1ESQUEMA2ESQUEMA3LOADER_TESTS
Schema: APPDERBYPADESQUEMA1ESQUEMA2ESQUEMA3LOADER_TESTSMGCOMUN
As you can see eache new schema name is appended to the previous one.
The odd thing is that if a change the order of the two statements in bold,
instead of
* pschema.add(schemaLabel);
pschema.add(ch);*
use
* pschema.add(ch);*
* pschema.add(schemaLabel);
*then the result is:
DerbyPad 1.0
Generated on 2006-5-18 23:20:4
Object Inventory
APP Schema:
DERBYPAD Schema:
ESQUEMA1 Schema:
ESQUEMA2 Schema:
ESQUEMA3 Schema:
LOADER_TESTS Schema:
MGCOMUN Schema:
MGCONTABIL Schema:
I've spent quite a time trying to find the problem but unfortunatelly
couldn't.
So the question is WHAT AM I DOING WRONG?
Thanks a lot for any help
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
iText-questions mailing list
iText-questions (at) lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions