使用iTextSharp将细胞分裂为两个

时间:2016-12-11 14:57:25

标签: 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.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字体......

我可以以某种方式将这个细胞分成两部分,并说左侧的元素对齐左侧,第二个细胞中的元素左侧对齐吗?

有人能帮助我吗?

0 个答案:

没有答案