I would like to take data from a Table in Excel and automatically fill in multiple & fillable PDF forms using a macro.
Asked
Active
Viewed 1.9k times
0
-
Please see http://stackoverflow.com/about and http://stackoverflow.com/faq to learn about the types of questions you can ask here. To use this site, you should show an attempt at the problem, not ask others to do the work for you. Perhaps you can post some code attempts and the errors you are getting and we can help. – Scott Feb 23 '13 at 13:12
-
Sorry i i am a new user sorry – Saima Maheen Feb 23 '13 at 13:14
-
See here http://stackoverflow.com/questions/11103771/itextsharp-to-print-a-gridview – Scott Feb 23 '13 at 13:17
-
Thax and sorry dont mint i am a new sorry – Saima Maheen Feb 23 '13 at 13:27
-
do you want to download the pdf? or send it across internet? – Kob_24 Sep 27 '16 at 11:21
1 Answers
2
Here is an article which explains how to convert datagridview to PDF and excel files
http://www.codeproject.com/Articles/28269/Exporting-a-DataGridView-to-an-Excel-PDF-image-fil
Here is what I have done recently in one of my projects:
public void ExportToPdf(DataTable ExDataTable) //Datatable
{
//Here set page size as A4
Document pdfDoc = new Document(PageSize.A4, 10, 10, 10, 10);
try
{
PdfWriter.GetInstance(pdfDoc, System.Web.HttpContext.Current.Response.OutputStream);
pdfDoc.Open();
//Set Font Properties for PDF File
Font fnt = FontFactory.GetFont("Times New Roman", 12);
DataTable dt = ExDataTable;
if (dt != null)
{
PdfPTable PdfTable = new PdfPTable(dt.Columns.Count);
PdfPCell PdfPCell = null;
//Here we create PDF file tables
for (int rows = 0; rows < dt.Rows.Count; rows++)
{
if (rows == 0)
{
for (int column = 0; column < dt.Columns.Count; column++)
{
PdfPCell = new PdfPCell(new Phrase(new Chunk(dt.Columns[column].ColumnName.ToString(), fnt)));
PdfTable.AddCell(PdfPCell);
}
}
for (int column = 0; column < dt.Columns.Count; column++)
{
PdfPCell = new PdfPCell(new Phrase(new Chunk(dt.Rows[rows][column].ToString(), fnt)));
PdfTable.AddCell(PdfPCell);
}
}
// Finally Add pdf table to the document
pdfDoc.Add(PdfTable);
}
pdfDoc.Close();
Response.ContentType = "application/pdf";
//Set default file Name as current datetime
Response.AddHeader("content-disposition", "attachment; filename=" + DateTime.Now.ToString("yyyyMMdd") + ".pdf");
System.Web.HttpContext.Current.Response.Write(pdfDoc);
Response.Flush();
Response.End();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}

coder
- 13,002
- 31
- 112
- 214
-
-
-
I am new programmer i cannt understand heavy programming like this. – Saima Maheen Feb 23 '13 at 13:23
-
@SaimaMaheen- I have updated with my solution and let me know still if you have any issues with it. – coder Feb 23 '13 at 13:28
-
hy thanx bosss i try it later now i off my computer u where from? – Saima Maheen Feb 23 '13 at 13:29
-
-
did u add any spl libraries for using pdf? if so plz say what it is.. @coder – Kopika Dec 14 '15 at 04:13