Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Application VB.NET , +
Hello, i am working with the Vb.Net Desktop Application. i want to do Data Transfer from Datagrid View To PDF and data is coming from DataSet.
Posted 16-Apr-12 23:38pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
v2
Comments
Dipak V Nakum at 17-Apr-12 4:47am
   
i want to do in the DESKTOP Application Not in the Web.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
Based on your description, do you mean you want to export data form dataset or datagridview to PDF file?
 
If so, there are many ways can chieve that:
 
1.Using Reporting Services report generation: http://www.codeproject.com/KB/reporting-services/ReportExporters_WinForms.aspx
2.Using ReportViewer.Drop a Table report item on an RDLC report, populate it with data and it can be exported to PDF or Excel.
3.Using a free tool.See CompletIT DataGridView Extension on http://www.completit.com/Products/DGVE/Overview.aspx
 
I am not sure whether it can achieve by Crystal Reports. If you want to use Crustal Report, you can go to the Crystal Reports for Visual Studio Forum for help.
  Permalink  
v2
Comments
Dipak V Nakum at 17-Apr-12 4:49am
   
i am using Datagridview not Crystal Report.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

u just download iTextSharp.dll , it is completly free and working in my application is very well.
 
just add referance of this dll in your application put this code u will get perfect pdf what u need
 
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;
 
public void CreatePdfFiles()
{
try
{

 
DataSet objDS = db.GetDSBySP("spname");//here call method and fill dataset
 
string fPath = Server.MapPath("Report/BalanceDetails.pdf");
 
if (File.Exists(fPath))
File.Delete(fPath);
 
Document objDoc = new Document(PageSize.A4, 50, 50, 30, 30);
PdfWriter objWriter = PdfWriter.GetInstance(objDoc, new FileStream(fPath, FileMode.Create));
 
objDoc.Open();
// set header image table
PdfPTable HeaderImgdatatable = new PdfPTable(2);
HeaderImgdatatable.DefaultCell.Padding = 0;
HeaderImgdatatable.WidthPercentage = 70; // percentage
HeaderImgdatatable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
HeaderImgdatatable.DefaultCell.BorderWidth = 0;
//HeaderImgdatatable.DefaultCell.MinimumHeight = 20;
 

float[] HeaderImgcolumnWidths = { 20, 60 }; // This is without barcode
HeaderImgdatatable.SetWidths(HeaderImgcolumnWidths);
 

//Header set
PdfPTable Headerdatatable = new PdfPTable(1);
Headerdatatable.DefaultCell.Padding = 0;
Headerdatatable.WidthPercentage = 100; // percentage
Headerdatatable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
Headerdatatable.DefaultCell.BorderWidth = 0;
Headerdatatable.DefaultCell.MinimumHeight = 14;
 

float[] HeadercolumnWidths = { 100 }; // This is without barcode
Headerdatatable.SetWidths(HeadercolumnWidths);
 
string[] strArr = new string[4];
strArr[0] = " -:STATEMENT:- ";
strArr[1] = " Comaney Name LTD. ";
strArr[2] = " Address, New Delhi-67";
strArr[3] = "other info";
//strArr[4] = objDSBookShop.Tables[0].Rows[0]["BookShopName"].ToString() + ", " + objDSBookShop.Tables[0].Rows[0]["City"].ToString();
for (int i = 0; i < 4; i++)
{
if (i == 1)
{
Headerdatatable.DefaultCell.BackgroundColor = iTextSharp.text.Color.WHITE;
Phrase phrase = new Phrase(strArr[i].ToString(), FontFactory.GetFont("Times New Roman", 12, iTextSharp.text.Font.BOLD));
Headerdatatable.AddCell(phrase);
}
else
{
Headerdatatable.DefaultCell.BackgroundColor = iTextSharp.text.Color.WHITE;
Phrase phrase = new Phrase(strArr[i].ToString(), FontFactory.GetFont("Verdana", 9));
Headerdatatable.AddCell(phrase);
}
}
 

 
HeaderImgdatatable.AddCell(" ");
HeaderImgdatatable.AddCell(Headerdatatable);
objDoc.Add(HeaderImgdatatable);
//objDoc.Add(new Paragraph(strArr[4].ToString()));
 
iTextSharp.text.Image jpeg = iTextSharp.text.Image.GetInstance(Server.MapPath("images/Logo2.jpg"));
jpeg.SetAbsolutePosition(60, objDoc.PageSize.Height - 90);
objDoc.Add(jpeg);
 

objDoc.Add(new Paragraph(" "));
 
int numColumns = objDS.Tables[0].Columns.Count;
PdfPTable datatable = new PdfPTable(numColumns);
datatable.DefaultCell.Padding = 0;
datatable.WidthPercentage = 100; // percentage
datatable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
if (numColumns == 3)
{
float[] columnWidths = { 30, 30,40 };
datatable.SetWidths(columnWidths);
}
else
{
float[] columnWidths = { 40,20,20,20};
datatable.SetWidths(columnWidths);
}

 
//header row
datatable.DefaultCell.BorderWidth = 0;
datatable.DefaultCell.GrayFill = 0.8f;
datatable.DefaultCell.MinimumHeight = 20;
//datatable.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE;
 
//get column names
 
foreach (DataColumn col in objDS.Tables[0].Columns)
{
Phrase phrase = new Phrase(col.ColumnName.ToString(), FontFactory.GetFont("Verdana", 9, iTextSharp.text.Font.BOLD));
datatable.AddCell(phrase);
}
datatable.HeaderRows = 1; // this is the end of the table header
 
for (int i = 0; i < objDS.Tables[0].Rows.Count; i++)
{
for (int j = 0; j < objDS.Tables[0].Columns.Count; j++)
{
//if (numColumns == 4 && j == 1)
//{
datatable.DefaultCell.BackgroundColor = iTextSharp.text.Color.WHITE;
datatable.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_LEFT;
Phrase phrase = new Phrase(objDS.Tables[0].Rows[i][j].ToString(), FontFactory.GetFont("Verdana", 9));
datatable.AddCell(phrase);
//}
//else
//{
// datatable.DefaultCell.BackgroundColor = iTextSharp.text.Color.WHITE;
// datatable.DefaultCell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT;
// Phrase phrase = new Phrase(objDS.Tables[0].Rows[i][j].ToString(), FontFactory.GetFont("Verdana", 9));
// datatable.AddCell(phrase);
//}
}
}
 
objDoc.Add(datatable);
objDoc.Add(new Paragraph(" "));
objDoc.Add(new Paragraph("Thank You. "));
objDoc.Close();
//ShowPdf(fPath);
DownLoadFile(fPath, true);
}
catch (System.Exception objEx)
{
string strEx = objEx.Message;
}
}
private void DownLoadFile(string fPath, bool isDownLoad) //Function for downloading report document
{
string fullPath = Path.GetFullPath(fPath);
string fileName = Path.GetFileName(fullPath);
string ext = Path.GetExtension(fullPath);
string type = "";
if (!(ext == null))
{
ext = ext.ToLower();
}
switch (ext)
{
case ".pdf":
type = "Application/pdf";
break;
case ".csv":
type = "Application/x-msexcel";
break;
case ".rtf":
type = "Application/msword";
break;
case ".xls":
type = "Application/x-msexcel";
break;
 
}
 
if ((isDownLoad))
{
Response.AppendHeader("content-disposition", "attachment; filename=" + fileName);
}
if (type != "")
{
Response.ContentType = type;
}
Response.WriteFile(fullPath);
Response.End();
}
  Permalink  
Comments
Dipak V Nakum at 17-Apr-12 5:00am
   
i am working with the DESKTOP application not Web Application dear.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

  Permalink  
Comments
Dipak V Nakum at 17-Apr-12 5:15am
   
i had written clearly i am not using crystal report i am using DATAGRIDVIEW.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Use th below code.
Dim rpt As New ReportDocument
     rpt.Load(Server.MapPath("~/Reports/rptAll.rpt"))
     rpt.SetDataSource(Session("D"))
     rpt.SummaryInfo.ReportTitle = "IMM Inquiry Capture And Tracking  From Date" & Session("FromDt") & " To " & Session("ToDt")
     rpt.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, False, "IMM Inquiry Capture And Tracking")
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 5,130
1 DamithSL 4,237
2 Maciej Los 3,700
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,846


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 12 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100