Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi Everybody,
Can you have good idea about how can we export database to PDF using with itextsharp component. I need to add logo in header also in specified location also. PDF file should be same as data in datatable/gridview.

Thanks!
Posted
Comments
Boipelo 3-Sep-13 13:02pm    
http://www.mikesdotnetting.com/Article/86/iTextSharp-Introducing-Tables
Everything is there, read it all...

Try Like This In there There Is No Need Of ItextShart
C#
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Shared.Interop;
using System.IO;



C#
bool status = false;
        DataTable dt = new DataTable();
        Student stu=new Student();
        dt = stu.getActiveBlockStudentReport(0,Convert.ToString(ddlDepartment.SelectedValue),Convert.ToString(ddlCourses.SelectedValue),Convert.ToString(ddlStatus.SelectedValue));
        try
        {
            if (dt != null && dt.Rows.Count>0)
            {
                if (File.Exists(Server.MapPath("~/ActiveBlockStudent.Pdf")))
                {
                    System.IO.File.Delete(Server.MapPath("ActiveBlockStudent.Pdf"));
                }

                string rptName = Server.MapPath("~\\Reports\\rptBlockActiveStudent.rpt");
                ReportDocument RptDoc = new ReportDocument();
                RptDoc.Load(rptName);
                RptDoc.SetDataSource(dt);
                ExportOptions exportOpts1 = RptDoc.ExportOptions;
                RptDoc.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
                RptDoc.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                RptDoc.ExportOptions.DestinationOptions = new DiskFileDestinationOptions();
                ((DiskFileDestinationOptions)RptDoc.ExportOptions.DestinationOptions).DiskFileName = Server.MapPath("ActiveBlockStudent.Pdf");
                RptDoc.Export();
                RptDoc.Close();
                RptDoc.Dispose();
                {
                    Response.ClearContent();
                    Response.ClearHeaders();
                    Response.ContentType = "application/pdf";
                    Response.AppendHeader("Content-Disposition", "attachment; filename=ActiveBlockStudent.Pdf");
                    Response.WriteFile("ActiveBlockStudent.Pdf");
                    Response.Flush();
                    Response.Close();
                }
                if (File.Exists(Server.MapPath("~/ActiveBlockStudent.Pdf")))
                {
                    System.IO.File.Delete(Server.MapPath("ActiveBlockStudent.Pdf"));
                }
                status = true;
            }
            else
            {
                status = false;
            }
        }
        catch (Exception ex)
        {
            status = false;
        }
        if (status == false)
        {
            Messagebox1.Show("No Record Found.");
        }
 
Share this answer
 
v2
 
Share this answer
 
Comments
[no name] 14-Sep-13 5:58am    
Can anybody suggest more component for ASP.net to generate PDF component. Help most welcomed.
Try this link iTextSharp Articles[^].
*Note: Newer versions of iTextSharp are not free, better find out which one to use before doing all the work and asked for money later.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900