none
How to save created PDF file into dynamically file RRS feed

  • Question

  • 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.

    • Moved by CoolDadTx Thursday, October 24, 2019 1:49 PM Third party product
    Thursday, October 24, 2019 9:15 AM

All replies

  • Not sure i totally understood what you want. What do you mean with 'dynamic file'? Will the you give directory an filename? In this case just replace "Stock.pdf" with Path.Combine(Pathname, Filename) an your done.

    Thursday, October 24, 2019 10:41 AM
  • I want to let the user pick the save director file .

    Thursday, October 24, 2019 1:34 PM
  • We do not provide support for third party products in these forums. Please post your question related to iTextSharp in their forums.

    Michael Taylor http://www.michaeltaylorp3.net

    Thursday, October 24, 2019 1:49 PM