本文介绍了如何导出为pdf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在谷歌搜索但无法获得解决方案:(
请帮助
这是我的代码。
i search it in Google but cannot get solution :(
please help
here is my code.
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=UserDetails.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
string htmlstr = "title=’Header’ align=’Center’> Writing To PDF Using ASP.NET> <br><table align="’Center’"><tr><td style="’width:100px;color:green’"> iTextSharp</td><td style="’width:100px;color:red’">mypdftest</td></tr></table>";
StringReader sr = new StringReader(htmlstr);
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0.0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr); //Parse cannot take input as string reader (sr) how to solve?
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}
推荐答案
string htmlstr = @"<html><body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>";
如果成功,你可以在你的HTML中解决问题。
希望这有帮助
if it is success you can fix the issue in your html.
hope this helps
protected void imgbtnPDF_Click(object sender, ImageClickEventArgs e)
{
string imagepath = Server.MapPath("Images");
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=CellzoneSalesReport.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView1.AllowPaging = false;
GridView1.DataBind();
GridView1.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
pdfDoc.Add(new Paragraph("HEADER"));
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}
Try this. I hope this will help. :)
这篇关于如何导出为pdf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!