you can use iTextsharp pdf creator. just download the library ie itextsharp dll and add it to your references from sourceforge and use this code
note u have to edit where not applicable like connection strings, tablenames, variables, namespace, classnames. also note this code was implemented using C# in asp.net
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using iTextSharp.text;
using iTextSharp.text.rtf;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;
using System.Data.SqlClient;
using System.Data;
using System.Text;
using System.Collections;
using System.IO;
namespace report
{
public partial class launch : System.Web.UI.Page
{
string shifty,checky;
conex conexion = new conex();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
}
protected void cmdcancel_Click(object sender, System.EventArgs e)
{
Response.End();
this.Dispose();
}
public partial class Footer : PdfPageEventHelper
{
public override void OnEndPage(PdfWriter writer, Document doc)
{
Paragraph footer = new Paragraph("MY FOOTER DESCRIPTION HERE", FontFactory.GetFont(FontFactory.TIMES, 10, iTextSharp.text.Font.NORMAL));
footer.Alignment = Element.ALIGN_JUSTIFIED;
PdfPTable footerTbl = new PdfPTable(1);
footerTbl.TotalWidth = 600;
footerTbl.HorizontalAlignment = Element.ALIGN_JUSTIFIED;
PdfPCell cell = new PdfPCell(footer);
cell.Border = 0;
cell.PaddingLeft = 10;
footerTbl.AddCell(cell);
footerTbl.WriteSelectedRows(0, -1, 10, 30, writer.DirectContent);
}
}
private void chkcreate()
{
var titleFont = FontFactory.GetFont("Arial", 12, Font.NORMAL);
var titleFontx = FontFactory.GetFont("Arial", 12, Font.NORMAL,Color.RED);
var titleFont2 = FontFactory.GetFont("Arial", 12, Font.BOLD);
var logo = iTextSharp.text.Image.GetInstance(Server.MapPath("~/Images/imagename.gif"));
logo.SetAbsolutePosition(400, 795);
Document pdfDoc = new Document(PageSize.A4, 50, 50, 35, 25);
PdfPTable table = new PdfPTable(5);
table.TotalWidth = 535f;
table.LockedWidth = true;
float[] widths = new float[] { 2f, 13f,1.5f,3f,3f};
table.SetWidths(widths);
table.HorizontalAlignment = 0;
table.SpacingBefore = 5f;
table.SpacingAfter = 5f;
PdfPCell cell = new PdfPCell(new Phrase());
cell.Colspan = 0;
cell.Border = 0;
cell.HorizontalAlignment = 1;
table.AddCell("TaskID");
table.AddCell("TASK DESCRIPTION");
table.AddCell("TIME");
table.AddCell("MAKER");
table.AddCell("Comments*");
string connect = "Data Source=MACHINEname\\instancename;Initial Catalog=DatabaseName;User ID=yourloginID;Password=yourPassword";
using (SqlConnection conn = new SqlConnection(connect))
{
string query = "select bbbbb,ffffffff,CONVERT(VARCHAR(5),time),eeeee,xxxxx FROM mytablename ORDER BY xxxxxx";
SqlCommand cmd = new SqlCommand(query, conn);
try
{
conn.Open();
using (SqlDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
table.AddCell(rdr[0].ToString());
table.AddCell(rdr[1].ToString());
table.AddCell(rdr[2].ToString());
table.AddCell(rdr[3].ToString());
table.AddCell(rdr[4].ToString());
}
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
PdfPTable tab2 = new PdfPTable(3);
tab2.TotalWidth = 530f;
tab2.LockedWidth = true;
float[] width2 = new float[] { 1.2f, 14f,3f};
tab2.SetWidths(width2);
tab2.HorizontalAlignment = 0;
tab2.SpacingBefore = 5f;
tab2.SpacingAfter = 5f;
PdfPCell cell2 = new PdfPCell(new Phrase());
cell2.Colspan = 0;
cell2.Border = 0;
cell2.HorizontalAlignment = 1;
tab2.AddCell("Task");
tab2.AddCell("TASK DESCRIPTION");
tab2.AddCell("Attachment");
using (SqlConnection connx = new SqlConnection(connect))
{
string queryx = "select xxxx,aaaaa,bbbbb,vvvvv FROM tablename ORDER BY vvvvvvvv";
SqlCommand cmdx = new SqlCommand(queryx, connx);
try
{
connx.Open();
using (SqlDataReader rdrx = cmdx.ExecuteReader())
{
while (rdrx.Read())
{
tab2.AddCell(rdrx[0].ToString());
tab2.AddCell(rdrx[1].ToString());
tab2.AddCell(rdrx[2].ToString());
}
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=myfilename.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
StringReader sr = new StringReader(sw.ToString());
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
writer = PdfWriter.GetInstance(pdfDoc, new FileStream( Server.MapPath ("~\\C:\\myfoldername\\myfilenane.pdf"), FileMode.Create));
pdfDoc.Open();
pdfDoc.Add(logo);
pdfDoc.Add(new Paragraph("Title :" + shifty +" myfilename", titleFont));
pdfDoc.Add(new Paragraph("Business Date :" + txtdate.Text, titleFont));
pdfDoc.Add(new Paragraph(" ", titleFont));
pdfDoc.Add(table);
pdfDoc.Add(new Paragraph("TITLE 1:", titleFont2));
pdfDoc.Add(tab2);
pdfDoc.Add(new Paragraph("[ CHECKED BY...... " + checky +"]", titleFontx));
writer.PageEvent = new Footer();
pdfDoc.Add(logo);
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}
protected void cal1_SelectionChanged(object sender, System.EventArgs e)
{
}
protected void cmdcreate_Click(object sender, EventArgs e)
{
chkcreate();
}
}
}