1

我正在尝试使用 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 字体...

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

有人可以帮我吗?

4

0 回答 0