How to save created PDF file into dynamically file

  • Thread starter Thread starter gaggs1
  • Start date Start date
G

gaggs1

Guest
In my case, I need to save a Pdf file into a dynamic file that will specified by User. I know that I have to make some changes to "PdfWriterGetInstance".

Then how can I change my code to make it as I want:

Document doc = new Document(iTextSharp.text.PageSize.A4, 10, 10, 42, 35);
PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("Stock.pdf", FileMode.Create));
doc.Open();
Paragraph paragraphe = new Paragraph("Raport of Stock\n\n");
paragraphe.Alignment = Element.ALIGN_CENTER;
doc.Add(paragraphe);
DateTime now = new DateTime();
Paragraph paragraphe3 = new Paragraph(" " + now.ToString()+"\n\n\n");
paragraphe.Alignment = Element.ALIGN_LEFT;
doc.Add(paragraphe3);
PdfPTable table = new PdfPTable(dataGridView1.Columns.Count);
//add the header
for (int j=0; j < dataGridView1.Columns.Count; j++)
{
table.AddCell(new Phrase(dataGridView1.Columns[j].HeaderText));
}
//Flag the first row as a header
table.HeaderRows = 1;
for(int i = 0; i< dataGridView1.Rows.Count; i++)
{
for(int k = 0; k < dataGridView1.Columns.Count; k++)
{
if (dataGridView1[k, i].Value != null)
{
table.AddCell(new Phrase(dataGridView1[k, i].Value.ToString()));
}
}
}
doc.Add(table);
Paragraph paragraphe1 = new Paragraph(" " + "Total items: " +quaq1.ToString());
paragraphe.Alignment = Element.ALIGN_LEFT;
doc.Add(paragraphe1);
Paragraph paragraphe2 = new Paragraph(" " + "Total Price: " + tot1.ToString());
paragraphe.Alignment = Element.ALIGN_LEFT;
doc.Add(paragraphe2);


doc.Close();


Rq: I'm using iTextSharp Assembly.

Continue reading...
 
Back
Top