如何使用iTextsharp在pdf的所有页面中添加页眉和页脚?

如何使用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:// *.com/questions/18996323/add-header-and-footer-for-pdf-using-itextsharp [ ^ ]
Hope the below link will help you.

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