本文介绍了我该如何圆一个iTextSharp的表格边框的角落?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我想在iTextSharp的一个圆角矩形。下面是输出我现在有没有四舍五入: 和这里是我的代码,用于处理输出: pdftbl =新PdfPTable(3); pdftbl.WidthPercentage = 100; 宽度=新的浮动[3]; 宽度[0] = 0.6F; 宽度[1] = 0.2F; 宽度[2] = 0.6F; pdftbl.SetWidths(宽度); pdfcel =新PdfPCell(新乐句(Insuredaddress,docFont9)); pdfcel.BorderColor = Color.BLACK; pdftbl.AddCell(pdfcel); pdfcel =新PdfPCell(新词(,docWhiteFont9)); pdfcel.Border = 0; pdftbl.AddCell(pdfcel); pdfcel =新PdfPCell(新乐句(BkrAddrss,docFont9)); pdfcel.BorderColor = Color.BLACK; pdftbl.AddCell(pdfcel); objDocument.Add(pdftbl); 我可以改变/添加以实现期望的结果 什么解决方案 iText的[夏普]不具有此功能的开箱。这是做事的一种迂回的方式,但首先你必须实现 IPdfPCellEvent 接口,第二个事件处理程序附加到每个细胞添加到表中。首先一个简单的实现: 公共类RoundRectangle:IPdfPCellEvent {公共无效CellLayout( PdfPCell细胞,长方形矩形,PdfContentByte []帆布) { PdfContentByte CB =帆布[PdfPTable.LINECANVAS] cb.RoundRectangle( rect.Left, rect.Bottom, rect.Width, rect.Height, 4 //换人调整如何圆圆一角显示); cb.SetLineWidth(1F); cb.SetCMYKColorStrokeF(0F,0F,0F,1F); cb.Stroke(); } } 见的PdfContentByte文档 - 基本上所有上面的代码所做的就是像你想绘制一个圆角的单元格边框 然后分配上面创建这样的事件处理程序: RoundRectangle RR =新RoundRectangle (); 使用(文档的文档=新的文件()){ PdfWriter作家= PdfWriter.GetInstance(文件,STREAM); document.Open(); PdfPTable表=新PdfPTable(1); PdfPCell电池=新PdfPCell(){ CellEvent = RR,BORDER = PdfPCell.NO_BORDER,填充= 4,短语=新词(测试)}; table.AddCell(单元); document.Add(表); } I want to make a round rectangle in itextsharp. Here is the output I have now without rounding:and here is my code that processes that output: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);What can I change/add to achieve the desired result? 解决方案 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);} 这篇关于我该如何圆一个iTextSharp的表格边框的角落?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-14 00:00