下面是我的密码,
.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.Similarly中,我有我的用户控件,并且希望将同样的控件添加到另一个PDFPCell中,我尝试使用PDFP.ADDElement(),但它没有成功。
发布于 2014-02-03 06:01:33
您还可以动态地从标记创建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();
}https://stackoverflow.com/questions/19269447
复制相似问题