Hello,
I'am moving from table to pdftable. The reason is that I need tables as
headers and footers. I've read in the mailing archives that this is possible
using absolute positioning objects, i.e. pdfptable.
The reports are being created dynamically from data coming from a database.
Given a cell, it can have text with different fonts and backgrounds. That is
the reason why I use a phrase to construct the pdfpcell. But when a chunk
has a backgroundcolor it seems that it is written over the text, only the
background appears in the pdf file.
Is this the way a backgroundcolor for a chunk should work in pdfpcell?
Does anyone knows a workaround? Or can give a hint for looking the java
code?
The first page of the generated pdf file has a Table and the second has two
PdfPTables one added with document.add() and the other with absolute
positioning.
Thanks in advance.
------------------------------------------
The code is basically the following, and is a modification from itext's
tutorial.
import java.awt.Color;
import java.io.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
public class Chap1009 {
public static void main(String[] args) {
System.out.println("Chapter 10 example 9: a PdfPTable at an absolute
position");
// step 1: creation of a document-object
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
try {
// step 2: we create a writer that listens to the document
PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream("C:/Chap1009.pdf"));
// step 3: we open the document
document.open();
// step 4: we add some content
PdfPTable table = new PdfPTable(2);
table.getDefaultCell().setBorder(Rectangle.LEFT |
Rectangle.RIGHT);
float [] aWidth={20,80};
table.setWidths(aWidth);
table.setWidthPercentage(80f);
Font oFont1= FontFactory.getFont(FontFactory.COURIER,
FontFactory.defaultEncoding, FontFactory.defaultEmbedding,
12f, Font.NORMAL, java.awt.Color.black);
Font oFont2= FontFactory.getFont(FontFactory.HELVETICA,
FontFactory.defaultEncoding, FontFactory.defaultEmbedding,
16f, Font.NORMAL, java.awt.Color.black);
Table table2= new Table(2);
table2.setWidth(50f);
table2.setAlignment(Element.ALIGN_RIGHT);
for (int k = 0; k < 10; ++k) {
Chunk oChunk1=new Chunk("addCell ");
oChunk1.setFont(oFont1);
oChunk1.setBackground(java.awt.Color.cyan);
Chunk oChunk2=new Chunk(" "+k);
oChunk2.setFont(oFont2);
oChunk2.setBackground(java.awt.Color.gray);
Phrase oPhrase= new Phrase();
oPhrase.add(oChunk1);
oPhrase.add(oChunk2);
// cell
Cell oCell2 = new Cell();
// oCell2.setBackgroundColor(java.awt.Color.gray);
oCell2.add(oPhrase);
table2.addCell(oCell2);
// pdf cell
PdfPCell oCell= new PdfPCell(oPhrase);
oCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
// oCell.setBackgroundColor(java.awt.Color.cyan);
table.addCell(oCell);
}
document.add(table2);
document.newPage();
document.add(table);
table.writeSelectedRows(0, -1, 0, 500,
writer.getDirectContent());
// step 5: we close the document
document.close();
}
catch (Exception de) {
de.printStackTrace();
}
}
}
_________________________________________________________________
MSN Fotos: la forma m�s f�cil de compartir e imprimir fotos.
http://photos.msn.es/support/worldwide.aspx
-------------------------------------------------------
This sf.net email is sponsored by: Are you worried about
your web server security? Click here for a FREE Thawte
Apache SSL Guide and answer your Apache SSL security
needs: http://www.gothawte.com/rd523.html
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions
