如何使用iTextsharp在pdf的所有页面中添加页眉和页脚? [英] How to add header and footer in all page of pdf using iTextsharp?

查看:150
本文介绍了如何使用iTextsharp在pdf的所有页面中添加页眉和页脚?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从数据库中完成了导出pdf,但不包含页眉和页脚。

所以,请帮我这个代码页眉和页脚包含。



我的代码 - :



I have completed export pdf from database, but not header and footer contains.
So, please help me in this code header and footer contains.

My code-:

protected void btnPdf_Click(object sender, EventArgs e)
{
    try
    {
        var company = objCompany.GetAllCompanyInExcel();
        if (company != null)
        {
            GridView grdCompanyPdf = new GridView();
            grdCompanyPdf.AllowPaging = false;
            grdCompanyPdf.DataSource = company;
            grdCompanyPdf.DataBind();

            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition",
              "attachment;filename=DataTable.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            grdCompanyPdf.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();
        }
        else
        {

        }
    }
    catch (Exception ex)
    {
        throw ex;
    }
}

推荐答案

希望以下链接能为您提供帮助。



http:// stackoverflow.com/questions/18996323/add-header-and-footer-for-pdf-using-itextsharp [ ^ ]
Hope the below link will help you.

http://stackoverflow.com/questions/18996323/add-header-and-footer-for-pdf-using-itextsharp[^]


这篇关于如何使用iTextsharp在pdf的所有页面中添加页眉和页脚?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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