How to Export All FormViews to a PDF?

Posted by Sathiya_Narayanan under ASP.NET on 3/20/2012 | Points: 10 | Views : 1458 | Status : [Member] | Replies : 5
Hi,

Scenerio:

I have 20 records retrieved from DB.

Each record is being displayed in a formview. I want to export all '20' records/formviews to a PDF file.

How can accomplish this?

Any suggestion?

On a button click event all forms to be convert into PDF.
Thanks,

SATHIYANARAYANAN

SATHIYANARAYANAN


Responses

Posted by: Sksamantaray on: 3/20/2012 [Member] Silver | Points: 25

Up
0
Down
Create a SSRS Report.

Thanks,
Sanjay

Sathiya_Narayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sathiya_Narayanan on: 3/20/2012 [Member] Starter | Points: 25

Up
0
Down
sir how to create SSRS Report, i m a learner i dono it...

can you give me some use full steps & links to create report.

SATHIYANARAYANAN

Sathiya_Narayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 3/20/2012 [Member] Silver | Points: 25

Up
0
Down

Hi Sathiya_Narayanan,
Refer to this:

http://www.dotnetfunda.com/articles/article1778-create-ssrs-client-side-report.aspx

Thanks,
Sanjay

Sathiya_Narayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vijetha on: 3/20/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
1. First create a method which will retrieve you the records from db.Then,
2. Write the event for button click and call the method to retrieve the data.
3. Assign the return value from the method to the object
4. Create a document and a PDFtable,add the return data to the datatable using for loop.
Then follow the type specification method.
Given below is the sample.
protected void btnExportPDF_Click(object sender, EventArgs e)
{

MasterData objMaster = new MasterData();

using (MemoryStream MStream = new MemoryStream())
{
ServiceAccess objservice = new ServiceAccess();
objMaster = objservice.GetMasterDataDescription();
if (objMaster != null)
{

// step 1: creation of a document-object
Document document = new Document(PageSize.A4.Rotate(), 10, 10, 10, 10);


// step 2:
// we create a writer that listens to the document
// and directs a PDF-stream to a file
PdfWriter.GetInstance(document,MStream);
// step 3: we open the document
document.SetMargins(5, 12, 12, 5);
document.Open();
//step 4:Add data to document table cell
int NumColumns = 12;

PdfPTable datatable = new PdfPTable(NumColumns);
Font fnt = FontFactory.GetFont("Times New Roman",1);
Phrase ph=new Phrase("GIFTREGISTRY-ASSIGNMENT1");

document.Add(ph);

int[] headerwidths = { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 };// percentage
datatable.SetWidths(headerwidths);



datatable.TotalWidth = 100;



datatable.WidthPercentage = 100;
datatable.AddCell("Registry#");
datatable.AddCell("EventDate");
datatable.AddCell("RegDate");
datatable.AddCell("RegFName");
datatable.AddCell("RegLName");
datatable.AddCell("CoFName");
datatable.AddCell("CoLName");
datatable.AddCell("Source");
datatable.AddCell("SKU");
datatable.AddCell("EventName");
datatable.AddCell("Itemname");
datatable.AddCell("UPC");


for (int j = 0; j < objMaster.ReturnDataList.Length; j++)
{
datatable.AddCell(objMaster.ReturnDataList[j].RCustcode);
datatable.AddCell(objMaster.ReturnDataList[j].REvent_Date.ToString("dd-MMM-yyyy"));
datatable.AddCell(objMaster.ReturnDataList[j].RRegister_Date.ToString("dd-MMM-yyyy"));
datatable.AddCell(objMaster.ReturnDataList[j].RRegFirst_Name);
datatable.AddCell(objMaster.ReturnDataList[j].RRegLast_Name);
datatable.AddCell(objMaster.ReturnDataList[j].RCoregFirst_Name);
datatable.AddCell(objMaster.ReturnDataList[j].RCoregLast_Name);
datatable.AddCell(objMaster.ReturnDataList[j].RSource);
datatable.AddCell(objMaster.ReturnDataList[j].RSKU);
datatable.AddCell(objMaster.ReturnDataList[j].REvent_Name);
datatable.AddCell(objMaster.ReturnDataList[j].RItemName);
datatable.AddCell(objMaster.ReturnDataList[j].RUPC);

}
// step 5: we add a table data to the document
document.Add(datatable);
// step 6: we close the document
document.Close();

Response.Clear();
Response.Charset = string.Empty;
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=" + "EventPdfReport" + ".pdf");

Response.BinaryWrite(MStream.GetBuffer());
Response.End();


}
}
}

Regards,
Vijetha.M.M

Sathiya_Narayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajni.Shekhar on: 3/22/2012 [Member] Bronze | Points: 25

Up
0
Down
you can also refer...

http://www.dotnetfunda.com/codes/code2077-export-gridview-into-pdf.aspx

Thanks,
Rajni Shekhar

Sathiya_Narayanan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response