在asp.net中创建pdf [英] Creating pdf in asp.net

查看:60
本文介绍了在asp.net中创建pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里创建pdf这是我的代码

Here i am creating pdf this is my code

Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=SanghiOrder.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView1.AllowPaging = false;
GetAddTocartData2();
GridView1.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, new FileStream(Server.MapPath("~/pdf/Order" + OrderNumber + ".pdf"), FileMode.Create));
pdfDoc.Open();
htmlparser.Parse(sr);  //Here Error is Getting
pdfDoc.Close();
Response.End();


创建pdf时
我这样得到错误



这里我收到服务器404错误...请帮助我


while creating pdf am getting errror like this

Here am getting server 404 error ...Please Help me

推荐答案

作为替代方案,您可以使用 iTextSharp 来创建PDF。



As an alternative you may use iTextSharp for create PDF.

using iTextSharp.text;
using iTextSharp.text.pdf;

var doc1 = new Document();

//use a variable to let my code fit across the page...
string path = Server.MapPath("PDFs");
PdfWriter.GetInstance(doc1, new FileStream(path + "/Doc1.pdf", FileMode.Create));

doc1.Open();
doc1.Add(new Paragraph("My first PDF"));
doc1.Close();





欲了解更多信息,请查看:在ASP.NET中创建PDF



我希望这会对你有所帮助。



For more info check this : Create PDFs in ASP.NET

I hope this will help to you.


这篇关于在asp.net中创建pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆