如何使用itextsharp打开pdf文件 [英] How to open a pdf file using itextsharp

查看:195
本文介绍了如何使用itextsharp打开pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在使用Itextsharp创建PDF文件。该文件已成功创建,但创建后不会直接打开。请帮助我。



先谢谢

Hi All,
I am creating a PDF file using Itextsharp. the file has created sucessfully but it is not getting open directly once it created .Please help me on this.

Thanks in Advance

推荐答案

我使用以下代码创建了使用gridview数据的pdf:

I have used the following code to create pdf which uses gridview data:
protected void btnPDF_Click(object sender, EventArgs e) // Export to PDF Document
        {
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=DefaultReport.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            dgResults.AllowPaging = false;
            BindGridView();
            dgResults.DataBind();
            dgResults.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();
            htmlparser.Parse(sr);
            pdfDoc.Close();
            Response.Write(pdfDoc);
            Response.End();  // end of the file

        }


这篇关于如何使用itextsharp打开pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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