473,387 Members | 3,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Images present in datagridview not exporting to file only text contents are generatin

Hi Everyone,

I have created simple Desktop app in that I trying to generate PDF file from Datagridview...when I click on ExportPDf button Pdf file is generation successfully but the issue is in that pdf whatever the images has present in datagridview that images are not generation into PDF only the text contents are Present in PDF file.

Does any one can tell me how to generate the PDF file along with images.

Here is my code:

Expand|Select|Wrap|Line Numbers
  1.   private void btnexportPDF_Click(object sender, EventArgs e)
  2.         {
  3.             int ApplicationNameSize = 15;
  4.             int datesize = 12;
  5.             Document document = null;
  6.  
  7.             try
  8.             {
  9.                 SaveFileDialog savefiledg = new SaveFileDialog();
  10.                 savefiledg.Filter = "All Files | *.* ";
  11.  
  12.                 if (savefiledg.ShowDialog() == DialogResult.OK)
  13.                 {
  14.                     string path = savefiledg.FileName;
  15.  
  16.                     document = new Document(PageSize.A4, 3, 3, 10, 5);
  17.  
  18.                     PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(path + ".pdf", FileMode.Create));
  19.                     document.Open();
  20.  
  21.                     // Creates a phrase to hold the application name at the left hand side of the header.
  22.                     Phrase phApplicationName = new Phrase("Sri Lakshmi Finance,Hosur-560068", FontFactory.GetFont("Arial", ApplicationNameSize, iTextSharp.text.Font.NORMAL));
  23.  
  24.  
  25.                     // Creates a phrase to show the current date at the right hand side of the header.
  26.                     Phrase phDate = new Phrase(DateTime.Now.ToLongDateString(), FontFactory.GetFont("Arial", datesize, iTextSharp.text.Font.NORMAL));
  27.  
  28.  
  29.                     document.Add(phApplicationName);
  30.                     document.Add(phDate);
  31.  
  32.                     iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance("D:\\logo.JPG");
  33.                     document.Add(img);
  34.  
  35.                     iTextSharp.text.Font font5= iTextSharp.text.FontFactory.GetFont(FontFactory.TIMES_ROMAN, 5);
  36.                     iTextSharp.text.Font font6 = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 6);
  37.                     //float[] columnDefinitionSize = { 2.5f, 7.0f,6.6f, 8.6f, 6.6f, 5.0f, 4.5f, 7.0f, 6.3f, 7.0f, 3.5f, 6.0f, };
  38.  
  39.                     PdfPTable table = null;
  40.                     table = new PdfPTable(dataGridView1.Columns.Count);
  41.                     table.WidthPercentage = 100;
  42.  
  43.                     PdfPCell cell = null;
  44.                     foreach (DataGridViewColumn c in dataGridView1.Columns)
  45.                     {
  46.                         cell = new PdfPCell(new Phrase(new Chunk(c.HeaderText,font6)));
  47.                         cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
  48.                         cell.VerticalAlignment = PdfPCell.ALIGN_CENTER;
  49.                         cell.BackgroundColor = new iTextSharp.text.BaseColor(240, 240, 240);
  50.                         table.AddCell(cell);
  51.                     }
  52.  
  53.                     if (dataGridView1.Rows.Count > 0)
  54.                     {
  55.                         for (int i = 0; i < dataGridView1.Rows.Count; i++)
  56.                         {
  57.                             PdfPCell[] objcell = new PdfPCell[dataGridView1.Columns.Count];
  58.  
  59.                             for (int j = 0; j < dataGridView1.Columns.Count - 0; j++)
  60.                             {
  61.                                 cell = new PdfPCell(new Phrase(dataGridView1.Rows[i].Cells[j].Value.ToString(), font5));
  62.                                 cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
  63.                                 cell.VerticalAlignment = PdfPCell.ALIGN_LEFT;
  64.                                 cell.Padding = PdfPCell.ALIGN_LEFT;
  65.                                 objcell[j] = cell;
  66.                             }
  67.  
  68.                             PdfPRow newrow = new PdfPRow(objcell);
  69.                             table.Rows.Add(newrow);
  70.                         }
  71.                     }
  72.  
  73.                     document.Add(table);
  74.                     MessageBox.Show("PDF Generated Successfully");
  75.                     document.Close();
  76.                 }
  77.                 else
  78.                 {
  79.                     //Error 
  80.                 }
  81.             }
  82.             catch (FileLoadException fle)
  83.             {
  84.                 MessageBox.Show(fle.Message);
  85.                 MessageBox.Show("Error in PDF Generation", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  86.             }
  87.         }
Attached Images
File Type: jpg gv.jpg (33.3 KB, 91 views)
File Type: jpg gv1.jpg (52.5 KB, 119 views)
Apr 3 '15 #1
0 1950

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Julia | last post by:
Hi, When generating CHM from my assemblies and XML documentation is it possible to embed images? Thanks.
2
by: Larry Cheung | last post by:
Hi, Is ther anyway I can present a html file on a win form? I have tried richtextbox. However, it can only accept text or richtext file format. I would like to use this feature to, for...
1
by: mohan21_kumar | last post by:
Hi, How to Save images in ms word file when it is downloaded from asp.net application. I have used the following code to convert the html page into ms word file. but i'm not able to save the...
3
by: Leszek | last post by:
Hello! Is there any possibility to load a datagridview from a text file? I have *.tsv file with performance counters and I'm trying to create a webpage (or Windows application), that will show...
4
by: B.N.Prabhu | last post by:
Can we Read the text contents from PDF using .net. If possible means what to do.
2
by: s14m27 | last post by:
Hi... I have tried displaying images in datagridview control from sqlserver 2000 where i have the path to the images.I could do it column-wise using the DataGridViewImageColumn.Could someone help...
2
by: Bruno Rafael Moreira de Barros | last post by:
I am trying to send a file's contents to the browser, the file is 80MB, but I can only download 6.99, then the file ends. I used set_time_limit(0), but it still happens... Any help? Thanks in...
0
by: Robert | last post by:
Hi! I want to fill the clipboard programmatically in oder to manual copy the data to word. The data consists of cells of a grid which contains text or images. Using the standard copy/paste of...
1
by: ankit1984 | last post by:
Hello, I am using this code for display Image in DataGridView but my problem is not being resolved. Please help me private void CreateColumns() { for (int i = 0; i <...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.