1
Answer

pdf file not being created

S B  Ray

S B Ray

15y
1.9k
1
Dear All,

I am trying to create a pdf file for a report but it is not being created.
I am using itextsharp.dll.
The code is as given below:

 Document doc = new Document(PageSize.A4);
                        PdfWriter.GetInstance(doc, new FileStream(filename, FileMode.Create));
                        doc.Open();

                        // create a caption for the page
                        Paragraph newp = new Paragraph("XYZ Report");
                        newp.SetAlignment("center");
                        doc.Add(newp);
                        Paragraph blp = new Paragraph("");// for adding new lines
                        doc.Add(blp);
                        Paragraph blp1 = new Paragraph("");
                        doc.Add(blp1);
                        StringBuilder stbld = new StringBuilder();
                        for (int i = 0; i < grdcap1.Length; i++)
                        {

                            stbld.Append(Convert.ToString(grdcap1[i]));
                        }
                        string cap = stbld.ToString();
                        Paragraph newcap = new Paragraph(cap);
                        newcap.SetAlignment("center");
                        doc.Add(newcap);
                        StringBuilder headbld = new StringBuilder();
                        for (int k = 0; k < grdhead1.Length; k++)
                        {

                            headbld.Append(Convert.ToString(grdhead1[k]));

                        }
                        string head = Convert.ToString(headbld);
                        Paragraph newhead = new Paragraph(head);
                        newhead.SetAlignment("left");
                        doc.Add(newhead);
doc.Close();

But the file is not being created. Not even a blank file.
What is the problem?
What wrong have I done?

Thanks for your reply.

Answers (1)