C# 使用iTextSharp将单元格一分为二
我正在尝试使用iTextSharp生成PDF文件,到目前为止,我已经编写了以下代码:C# 使用iTextSharp将单元格一分为二,c#,split,itext,pdfptable,C#,Split,Itext,Pdfptable,我正在尝试使用iTextSharp生成PDF文件,到目前为止,我已经编写了以下代码: string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); Document doc = new Document(iTextSharp.text.PageSize.A4,50,50,120,40); PdfWriter writer = PdfWriter.GetI
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
Document doc = new Document(iTextSharp.text.PageSize.A4,50,50,120,40);
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(path+"\\Invoices\\Test.pdf", FileMode.Create));
PdfPTable table = new PdfPTable(2);
table.WidthPercentage = 100;
table.DefaultCell.HasBorder(iTextSharp.text.Rectangle.NO_BORDER);
table.AddCell(new PdfPCell() { HorizontalAlignment = PdfPCell.ALIGN_LEFT, Phrase = new Phrase("The text on the left goes here", FontFactory.GetFont("Arial",10.00f,iTextSharp.text.Font.BOLD)), BorderColor = BaseColor.WHITE, BorderWidth = 0 });
table.AddCell(new PdfPCell() { HorizontalAlignment = PdfPCell.ALIGN_CENTER, Phrase = new Phrase("Contact us\n\n", FontFactory.GetFont("Arial", 10.00f, iTextSharp.text.Font.BOLD | iTextSharp.text.Font.UNDERLINE)), BorderColor = BaseColor.WHITE, BorderWidth = 0 });
// table.AddCell(new PdfPCell() { HorizontalAlignment = PdfPCell.ALIGN_LEFT, Phrase = new Phrase("Email\nPhone2\nPhone1\nFax\nCell", FontFactory.GetFont("Arial", 10.00f, BaseColor.BLACK)), BorderColor = BaseColor.WHITE, BorderWidth = 0 });
doc.Open();
Paragraph p2 = new Paragraph("Text above cells goes here\n ", FontFactory.GetFont("Arial", 8.0f, BaseColor.BLACK));
doc.Add(p2);
doc.Add(table);
doc.Close();
我正在尝试创建如下输出:
The text above the cells
The text on the left goes here **Contact us**
Email l@test.com
Phone2 01234567890
Phone1 01234567890
Fax 01234567890
Cell 01234567890
文本“联系我们”必须保持粗体和下划线,而文本电子邮件“phone2,1”必须仅为常规的Arial 10字体
我可以把这个单元格分成两部分,左边的元素向左对齐,第二个单元格向左对齐吗
有人能帮我吗?您正在寻找跨多列的单元格。看看这些复杂表的例子(有些是java的,但C#应该有相同的方法,只是签名稍有不同):,@Samuel ty为此,我昨天已经解决了这个问题。干杯:)您正在寻找跨多个列的单元格。看看这些复杂表的例子(有些是java的,但C#应该有相同的方法,只是签名稍有不同):,@Samuel ty为此,我昨天已经解决了这个问题。干杯:)