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: - private void btnexportPDF_Click(object sender, EventArgs e)
-
{
-
int ApplicationNameSize = 15;
-
int datesize = 12;
-
Document document = null;
-
-
try
-
{
-
SaveFileDialog savefiledg = new SaveFileDialog();
-
savefiledg.Filter = "All Files | *.* ";
-
-
if (savefiledg.ShowDialog() == DialogResult.OK)
-
{
-
string path = savefiledg.FileName;
-
-
document = new Document(PageSize.A4, 3, 3, 10, 5);
-
-
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(path + ".pdf", FileMode.Create));
-
document.Open();
-
-
// Creates a phrase to hold the application name at the left hand side of the header.
-
Phrase phApplicationName = new Phrase("Sri Lakshmi Finance,Hosur-560068", FontFactory.GetFont("Arial", ApplicationNameSize, iTextSharp.text.Font.NORMAL));
-
-
-
// Creates a phrase to show the current date at the right hand side of the header.
-
Phrase phDate = new Phrase(DateTime.Now.ToLongDateString(), FontFactory.GetFont("Arial", datesize, iTextSharp.text.Font.NORMAL));
-
-
-
document.Add(phApplicationName);
-
document.Add(phDate);
-
-
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance("D:\\logo.JPG");
-
document.Add(img);
-
-
iTextSharp.text.Font font5= iTextSharp.text.FontFactory.GetFont(FontFactory.TIMES_ROMAN, 5);
-
iTextSharp.text.Font font6 = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 6);
-
//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, };
-
-
PdfPTable table = null;
-
table = new PdfPTable(dataGridView1.Columns.Count);
-
table.WidthPercentage = 100;
-
-
PdfPCell cell = null;
-
foreach (DataGridViewColumn c in dataGridView1.Columns)
-
{
-
cell = new PdfPCell(new Phrase(new Chunk(c.HeaderText,font6)));
-
cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
-
cell.VerticalAlignment = PdfPCell.ALIGN_CENTER;
-
cell.BackgroundColor = new iTextSharp.text.BaseColor(240, 240, 240);
-
table.AddCell(cell);
-
}
-
-
if (dataGridView1.Rows.Count > 0)
-
{
-
for (int i = 0; i < dataGridView1.Rows.Count; i++)
-
{
-
PdfPCell[] objcell = new PdfPCell[dataGridView1.Columns.Count];
-
-
for (int j = 0; j < dataGridView1.Columns.Count - 0; j++)
-
{
-
cell = new PdfPCell(new Phrase(dataGridView1.Rows[i].Cells[j].Value.ToString(), font5));
-
cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
-
cell.VerticalAlignment = PdfPCell.ALIGN_LEFT;
-
cell.Padding = PdfPCell.ALIGN_LEFT;
-
objcell[j] = cell;
-
}
-
-
PdfPRow newrow = new PdfPRow(objcell);
-
table.Rows.Add(newrow);
-
}
-
}
-
-
document.Add(table);
-
MessageBox.Show("PDF Generated Successfully");
-
document.Close();
-
}
-
else
-
{
-
//Error
-
}
-
}
-
catch (FileLoadException fle)
-
{
-
MessageBox.Show(fle.Message);
-
MessageBox.Show("Error in PDF Generation", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
-
}
-
}
0 1950 Sign in to post your reply or Sign up for a free account.
Similar topics
by: Julia |
last post by:
Hi,
When generating CHM from my assemblies and XML documentation is it possible
to embed images?
Thanks.
|
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...
|
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...
|
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...
|
by: B.N.Prabhu |
last post by:
Can we Read the text contents from PDF using .net.
If possible means what to do.
|
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...
|
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...
|
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...
|
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 <...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
| |