iText[Sharp] doesn't have this functionality out of the box. It's a roundabout way of doing things, but first you have to implement the IPdfPCellEvent interface, and second attach the event handler to each cell you add to the table. First a simple implementation:
public class RoundRectangle : IPdfPCellEvent {
public void CellLayout(
PdfPCell cell, Rectangle rect, PdfContentByte[] canvas
)
{
PdfContentByte cb = canvas[PdfPTable.LINECANVAS];
cb.RoundRectangle(
rect.Left,
rect.Bottom,
rect.Width,
rect.Height,
4 // change to adjust how "round" corner is displayed
);
cb.SetLineWidth(1f);
cb.SetCMYKColorStrokeF(0f, 0f, 0f, 1f);
cb.Stroke();
}
}
See the PdfContentByte documentation - basically all the code above does is draw a cell border with round corners like you want.
Then assign the event handler created above like this:
RoundRectangle rr = new RoundRectangle();
using (Document document = new Document()) {
PdfWriter writer = PdfWriter.GetInstance(document, STREAM);
document.Open();
PdfPTable table = new PdfPTable(1);
PdfPCell cell = new PdfPCell() {
CellEvent = rr, Border = PdfPCell.NO_BORDER,
Padding = 4, Phrase = new Phrase("test")
};
table.AddCell(cell);
document.Add(table);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…