我正在使用 itextsharp dll 以 PDF 格式打印网页。我的 html 文件中有一个<img src="Images/flower.jpg" />
。当我没有图像时,下面的按钮单击事件将呈现 PDF。使用图像,我收到此错误:
找不到路径“C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\Images\flower.jpg”的一部分
这是我的代码:
protected void Button1_Click(object sender, EventArgs e)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
this.Page.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}