0

下面是我的代码,

.aspx:

<table border="0" width="100%" id="maintable" runat="server">
<tr>
<td style="width:90%;vertical-align:top;">
 <div id="content_left" runat="server"  style="margin-right:10px;
float:left;vertical-align:top;width:690px" ></div>
</td>
<td style="vertical-align:top;background-color:#eee;width:100px;">
<div id="content_right" runat="server" style="background-color:#eee;float:right;
width:300px;"></div>
</td>

</tr>
</table>

.aspx.cs:

  HtmlGenericControl aboutme_content = new HtmlGenericControl("div");
  aboutme.ID = "aboutme1";
  aboutme.Text= "ABOUT ME";
  content_left.Controls.Add(aboutme_content);
  PdfPTable table_left = new PdfPTable(1);
  PdfPCell cell_1 = new PdfPCell();

现在,我的疑问是我将如何将 content_left 添加到 PdfPCell。同样,我有我的用户控件并想将其添加到另一个 PDFPCell。我尝试使用 PDFP.ADDElement(),但它没有成功。

4

1 回答 1

0

您还可以PDF即时从标记创建。

请检查以下示例:

using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;

protected void HTMLToPDF()
    {
        string strHTML = @"<div>Some html markup & text </div>";
        String htmlText = strHTML.ToString();
        Document document = new Document();
        PdfWriter.GetInstance(document, new FileStream(Request.PhysicalApplicationPath + "MyTestPDF.pdf", FileMode.Create));
        document.Open();
        iTextSharp.text.html.simpleparser.HTMLWorker hw =
                     new iTextSharp.text.html.simpleparser.HTMLWorker(document);
        hw.Parse(new StringReader(htmlText));
        document.Close();
    }

希望这对你有帮助..!

更新:

填写:PDF Forms_iTextSharp

private void fillPdf() {
    Response.ContentType = "application/pdf";
    Response.AppendHeader(
      "Content-Disposition",
      "attachment;filename=itext_fill.pdf"
    );
    PdfReader r = new PdfReader(
      new RandomAccessFileOrArray(Request.MapPath("test_fill.pdf")), null
    );
    using (PdfStamper ps = new PdfStamper(r, Response.OutputStream)) {
      AcroFields af = ps.AcroFields;
      af.SetField("lname", lname.Text);
      af.SetField("fname", fname.Text);
      af.SetField("address", address.Text);
      af.SetField("zip", zip.Text);
      ps.FormFlattening = true;
    }
    Response.End();
  }
于 2014-02-03T06:01:33.160 回答