0
public void genreatePdf()
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("<table>");
        sb.Append("<tr><td><img src='images/my.jpg'/></td></tr>");
        sb.Append("<tr><td>some text</td></tr>");
        sb.Append("</table>");

        string path = Server.MapPath("~/invoice/invoice.pdf");
        Document document = new Document(PageSize.A4);
        PdfWriter.GetInstance(document, new FileStream(path, FileMode.Create));
        document.Open();
        document.Add(new Paragraph(strMailMsg.ToString()));
        document.Close();
    }

pdf文件的输出是

<table><tr><td><img src='images/my.jpg'/></td></tr><tr><td>some text</td></tr></table>

qus:预期的格式就像一个包含图像和文本的表格。为什么没有以该格式创建 pdf 文件。

4

1 回答 1

0

您需要创建一个表格并将其附加到 pdf 文件中。它不是通过附加 XHTML 来完成的,而是使用 C# 的内部表。

Table aTable = new Table(2, 2);    // 2 rows, 2 columns
theTable.AddCell("0.0");
theTable.AddCell("0.1");
theTable.AddCell("1.0");
theTable.AddCell("1.1");

//add the table to the document
document.Add(theTable);

是一个使用 itextsharp 的简单教程。

于 2012-06-22T08:49:57.393 回答