Ejemplo n.º 1
0
        /// <summary>
        /// Generates the report.
        /// </summary>
        /// <returns>The report.</returns>
        /// <param name="filename">Filename.</param>
        /// <param name="inspectionObject">Inspection object.</param>
        public string GenerateReport(string filename, Inspection inspectionObject)
        {
            string appRootDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            //Console.WriteLine (appRootDir);
            // Step 1: Creating System.IO.FileStream object
            DirectoryInfo path = Directory.CreateDirectory(appRootDir + "/LiRoReport");
            FileStream    fs   = new FileStream(path.FullName + "/" + filename, FileMode.Create, FileAccess.ReadWrite, FileShare.None);

            // Step 2: Creating iTextSharp.text.pdf.Document object
            iTextSharp.text.Document doc = new iTextSharp.text.Document(PageSize.A4, 20f, 20f, 60f, 60f);

            // Step 3: Creating iTextSharp.text.pdf.PdfWriter object
            // It helps to write the Document to the Specified FileStream
            PdfWriter writer = PdfWriter.GetInstance(doc, fs);

            writer.PageEvent = new ItextPageEvents(ReportType.Pass);

            // Step 4: Openning the Document
            doc.Open();

            PdfPTable table = PassInspectionReportTable(inspectionObject);

            try
            {
                if (table != null)
                {
                    doc.ResetHeader();
                    doc.Add(table);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception occured in Pass GenerateReport" + ex.Message);
            }
            finally
            {
                doc.Close();
                writer.Close();
            }
            return(fs.Name);
        }