Mike Buchanan wrote:
PdfContentByte cb = canvases[PdfPTable.TEXTCANVAS];
cb.moveTo(position.left(), position.top());
//cb.stroke();
cb.fill();
But where's the path?
What makes you believe this will actually draw something?
It just doesn't make sense...
As you can see in the attachment it put the text below the table instead
of overlaying it.
Of course! That's how you programmed it!
Maybe a working example would be easier to understand.
Sigh...
The fact that you don't understand why you need to paint
a path before you STROKE or FILL it (as is clearly explained
in the book), and the fact that you throw away everything
that is already in the cell by using setPhrase, a method
that is NOT EVEN MENTIONED in the book, really gives me
the impression you are pulling my leg here, but against
better judgment, see the attachment for a working example
(of course I have no idea if that's actually what you want
to do; your original code was very unclear).
br,
Bruno
package test;
//Test overlaying multiple PDF table cells with text
import java.io.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
class TextOverlay {
private static Document doc;
private static float[] colWidths;
private static boolean colorSw = false;
public static void main (String [] args) throws Exception {
doc = new Document (PageSize.LETTER.rotate());
PdfWriter.getInstance (doc, new FileOutputStream ("test_overlay.pdf"));
doc.open ();
float[] colSizes = { 72f, 18f, 140f, 95f, 30f };
colWidths = colSizes;
createTable();
doc.close ();
}
private static void createTable() throws Exception {
// Define an inner and outer table.
PdfPTable outerTable = new PdfPTable(1);
outerTable.setTotalWidth(355f);
outerTable.setLockedWidth(true);
PdfPTable innerTable = new PdfPTable(5);
innerTable.setTotalWidth(colWidths);
innerTable.setLockedWidth(true);
// Load the inner table with every other cell colored
Paragraph innerPara = new Paragraph();
PdfPCell innerCell = new PdfPCell(innerPara);
innerPara.setLeading(11f);
innerPara.add (new Phrase (" "));
innerCell.setFixedHeight(15f);
for(int i = 0;i < 5;i++) {
if(colorSw)
{
colorSw = false;
innerCell.setBackgroundColor(new CMYKColor(.05f, .01f, .00f,
.03f));
}
else
{
colorSw = true;
innerCell.setBackgroundColor(new CMYKColor(0f, 0f, 0f, 0f));
}
innerTable.addCell(innerCell);
}
String commentStr = "This comment in the outer table will extend over
multiple cells in the inner table";
PdfPCell cell = new PdfPCell(new Phrase(commentStr));
cell.setColspan(5);
innerTable.addCell(cell);
PdfPCell outerCell = new PdfPCell(innerTable);
outerCell.setCellEvent(new DoCellEvent());
//The following line is completely absurd!
//outerCell.setPhrase(new Phrase(commentStr));
outerCell.setBorder(Rectangle.NO_BORDER);
outerTable.addCell(outerCell);
doc.add(outerTable);
}
}
class DoCellEvent implements PdfPCellEvent {
public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[]
canvases)
{
PdfContentByte cb = canvases[PdfPTable.TEXTCANVAS];
cb.moveTo(position.left(), position.top());
cb.lineTo(position.right(), position.bottom());
cb.stroke();
}
}-------------------------------------------------------------------------
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
Buy the iText book: http://itext.ugent.be/itext-in-action/