[英]Table nested into PDFPCELL in itextsharp
I want to give rounded border to a table but after research i found it can't be done but we can give rounded border to a cell.. 我想给一个桌子提供圆形边框,但经过研究后我发现它无法完成,但我们可以给一个单元格提供圆形边框。
so i done something like this 所以我做了这样的事情
PdfPCell cell = new PdfPCell()
{
CellEvent = rr, // rr is RoundRectangle object
Border = PdfPCell.NO_BORDER,
Padding = 4,
Phrase = new Phrase("test")
};
table.AddCell(cell);
document.Add(table);
Now i can give border to a cell so what i want to do is i want to place my complete nested table into this pdfpcell so that i can acheive border indirectly on that table... 现在我可以给一个单元格边框,所以我想要做的是我想将完整的嵌套表放入这个pdfpcell中,以便我可以间接地在该表上实现边界...
Can you help on this? 你可以帮忙吗? If you didn't understand my approach..ask questions..i ll explain more clearly on comments section...
如果你不理解我的方法..问题......我将在评论部分更清楚地解释......
Using kuujinbo's code verbatim for the RoundRectangle
class: 使用kuujinbo的代码逐字表示
RoundRectangle
类:
public class RoundRectangle : IPdfPCellEvent {
public void CellLayout(
PdfPCell cell, iTextSharp.text.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();
}
}
You then just need an "outer" and an "inner" table and only put the CellEvent
on the outer table. 然后,您只需要一个“外部”和“内部”表,只将
CellEvent
放在外部表上。
//Create a one column table
var outerTable = new PdfPTable(1);
//Create a single cell for that outer table
var outerCell = new PdfPCell();
//Turn the border off for that cell because we're manually going to draw one
outerCell.Border = iTextSharp.text.Rectangle.NO_BORDER;
//Bind our custom class for drawing the borders
outerCell.CellEvent = new RoundRectangle();
//Do whatever we want with the inner table
var innerTable = new PdfPTable(3);
for (var i = 0; i < 9; i++) {
innerTable.AddCell("Hello");
}
//When done, add the inner table to the outer cell
outerCell.AddElement(innerTable);
//Add the outer cell to the outer table
outerTable.AddCell(outerCell);
//Add the outer table to the document
doc.Add(outerTable);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.