I am trying to create a PDF from a DataGridView populated from a database.
I just started trying to learn how to use iTextSharp for this.
The result of my code is a PDF that does not open. I get an error "File does not open"
Here is my PDF creation code
void SendToPDF(string heading, string filename) { try { Document doc = new Document(PageSize.A4.Rotate(), 30, 30, 20, 20); string myDocs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); if (!Directory.Exists(myDocs + @"\Production Reports")) Directory.CreateDirectory(myDocs + @"\Production Reports"); PdfWriter.GetInstance(doc, new FileStream(myDocs + @"\Production Reports\" + filename + ".pdf", FileMode.Append, FileAccess.Write)); iTextSharp.text.Font titleFont = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 14.0F, iTextSharp.text.Font.BOLD, BaseColor.BLACK); iTextSharp.text.Font tableFont = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 12.0F, iTextSharp.text.Font.NORMAL, BaseColor.BLACK); iTextSharp.text.Font headerfont = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 12.0F, iTextSharp.text.Font.BOLD, BaseColor.BLACK); PdfPTable table = new PdfPTable(GridView.Columns.Count);
I assume that my problem is with setting the width of the columns, but I'm not sure. Once and only once. I got an error when I tried to open a PDF that said βillegal floating point division by 0β or something in that direction.
Any help is greatly appreciated.
source share