如何绕过iTextSharp桌边的角?

我想在itextsharp中制作一个圆角矩形。 这是我现在没有舍入的输出:

在此处输入图像描述

这是我处理输出的代码:

pdftbl = new PdfPTable(3); pdftbl.WidthPercentage = 100; width = new float[3]; width[0] = 0.6F; width[1] = 0.2F; width[2] = 0.6F; pdftbl.SetWidths(width); pdfcel = new PdfPCell(new Phrase(Insuredaddress, docFont9)); pdfcel.BorderColor = Color.BLACK; pdftbl.AddCell(pdfcel); pdfcel = new PdfPCell(new Phrase("", docWhiteFont9)); pdfcel.Border = 0; pdftbl.AddCell(pdfcel); pdfcel = new PdfPCell(new Phrase(BkrAddrss, docFont9)); pdfcel.BorderColor = Color.BLACK; pdftbl.AddCell(pdfcel); objDocument.Add(pdftbl); 

我可以更改/添加什么来实现所需的结果?

iText [夏普]没有开箱即用的此function。 这是一种迂回的处理方式,但首先必须实现IPdfPCellEvent接口,然后将事件处理程序附加到添加到表中的每个单元格。 首先是一个简单的实现

 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(); } } 

请参阅PdfContentByte文档 – 基本上上面的所有代码都是绘制带有圆角的单元格边框。

然后像这样分配上面创建的事件处理程序:

 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); }