I used PdfPCellEvent's to draw a line in one cell.
The Result I wanted was something like this:
Cell1.1 Cell1.2 Value
Cell2.1 Cell2.2 Value
Cell3.1 Cell3.2 Value
--------
Total Value
So I created a method which would do the Job.
private void drawCellEventTable(){
// I defined the cells I am going to use in my table
PdfPCell cell1;
PdfPCell cell2;
PdfPCell value;
PdfPCell totalCell1;
PdfPCell totalCell2;
PdfPCell lineCell1;
PdfPCell lineCell2;
Strike strike = new Strike(); // This is the PdfPCellEvent inner
class
//Create the table and fill with values
PdfPTable tbl=new PdfPTable(size);
tbl.setTotalWidth(widths);
for(int i=1;i<=3;i++){
cell1=new PdfPCell(new Paragraph("Cell"+i+".1"));
cell2=new PdfPCell(new Paragraph("Cell"+i+".2"));
value=new PdfPCell(new Paragraph("value"+i));
tbl.addCell(cell1);
tbl.addCell(cell2);
tbl.addCell(value);
}
//Here I add the Cell Event
lineCell1=new PdfPCell(new Paragraph(""));
lineCell1.setColspan(2);
lineCell2=new PdfPCell(new Paragraph(""));
lineCell2.setCellEvent(strike);
tbl.addCell(lineCell1);
tbl.addCell(lineCell2);
//The Total Value Line
totalCell1=new PdfPCell(new Paragraph("Total"));
totalCell1.setColspan(2);
totalCell2=new PdfPCell(new Paragraph("Value"));
tbl.addCell(totalCell1);
tbl.addCell(totalCell2);
tbl.writeSelectedRows(0,-1,x,y,cb);
}
//Here I use the cell boundaries "rect" to draw a line
class Strike implements PdfPCellEvent {
public void cellLayout(PdfPCell cell, Rectangle rect,
PdfContentByte[] canvas) {
PdfContentByte cb = canvas[PdfPTable.TEXTCANVAS];
cb.setRGBColorStroke(0x00, 0x00, 0x00);
cb.moveTo(rect.left()+cm2Pnt(0.5f), (rect.top
()+rect.bottom())/2);
cb.lineTo(rect.right()-cm2Pnt(0.1f), (rect.top
()+rect.bottom())/2);
cb.stroke();
cb.resetRGBColorStroke();
}
}
I hope this will give you some ideas.
Regards Yannis
2007/4/18, Mitch Freed <[EMAIL PROTECTED]>:
The best solution I could find was to use a PdfPTable: (this is C#, but
you can get the idea)
PdfPTable t = new PdfPTable(1);
t.HorizontalAlignment = Element.ALIGN_CENTER;
t.WidthPercentage = 100f; // this would be the 100 from
setHorizontalLine
t.SpacingAfter = 5f;
t.SpacingBefore = 0f;
t.DefaultCell.UseVariableBorders = true;
t.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE;
t.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
t.DefaultCell.Border = Image.BOTTOM_BORDER; // This generates the line
t.DefaultCell.BorderWidth = 1f; // this would be the 1 from
setHorizontalLine
t.DefaultCell.Padding = 0;
t.AddCell("");
Hope that helps.
- Mitch
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Jason Pettiss
Sent: Tuesday, April 17, 2007 4:24 PM
To: [email protected]
Subject: [iText-questions] Graphic / Horizontal line
Our iText library was just upgraded, out of our control. We used to do
this to get a horizontal rule (quite a lot in fact):
Graphic hr = new Graphic();
hr.setHorizontalLine(1, 100);
document.add(hr);
Now none of our code builds-- what happened to Graphic, and what is the
equivalent replacement code for the above?
Thanks,
--jason
------------------------------------------------------------------------
-
This SF.net email is sponsored by DB2 Express Download DB2 Express C -
the FREE version of DB2 express and take control of your XML. No limits.
Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
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/
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
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/
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
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/