예제 #1
0
        public void GenerateReportnew()
        {
            Document doc = new Document(r, mleft, mright, mtop, mbottom);

            //fs = new FileStream(fname, FileMode.Create);
            fs = HttpContext.Current.Response.OutputStream;

            PdfWriter writer = PdfWriter.GetInstance(doc, fs);

            tbl = new PdfPTable(reptab.Columns.Count);
            tbl.SetWidths(colwid);

            tbl.TotalWidth = (595 - mleft - mright); tbl.LockedWidth = true;
            tbl.SetWidths(colwid);
            tbl.HorizontalAlignment = 0;
            tbl.SpacingBefore       = 10f;
            tbl.SpacingAfter        = 10f;

            /*for (int i = 0; i < repheaders.Length; i++)
             * {
             *  PdfPCell cell = new PdfPCell(new Phrase(repheaders[i]));
             *  cell.Colspan = reptab.Columns.Count;
             *  cell.Border = 0;
             *  cell.HorizontalAlignment = 1;
             *  tbl.AddCell(cell);
             * }*/

            for (int rh = 0; rh < reptab.Columns.Count; rh++)
            {
                tbl.AddCell(reptab.Columns[rh].ColumnName.ToUpper());
            }

            for (int row = 0; row < reptab.Rows.Count; row++)
            {
                for (int col = 0; col < reptab.Columns.Count; col++)
                {
                    tbl.AddCell(reptab.Rows[row][reptab.Columns[col]].ToString());
                }
            }
            doc.Open();
            MyPager ev = new MyPager();

            writer.PageEvent = ev;
            doc.Add(tbl);
            doc.Close();
            //openpdf(fname);
        }
예제 #2
0
        public void GenerateReport()
        {
            Document doc = new Document(r, mleft, mright, mtop, mbottom);

            fs = new FileStream(fname, FileMode.Create);
            Font      tblfnt     = new Font(Font.FontFamily.HELVETICA, 8, 0);
            Font      tblheadfnt = new Font(Font.FontFamily.HELVETICA, 12, 1);
            PdfWriter writer     = PdfWriter.GetInstance(doc, fs);

            tbl = new PdfPTable(reptab.Columns.Count);
            tbl.SetWidths(colwid);

            tbl.TotalWidth = (595 - mleft - mright); tbl.LockedWidth = true;
            tbl.SetWidths(colwid);

            tbl.HorizontalAlignment = 0;
            tbl.SpacingBefore       = 10f;
            tbl.SpacingAfter        = 10f;

            for (int i = 0; i < repheaders.Length; i++)
            {
                PdfPCell cell = new PdfPCell(new Phrase(repheaders[i], tblheadfnt));
                cell.Colspan             = reptab.Columns.Count;
                cell.Border              = 0;
                cell.HorizontalAlignment = 1;
                tbl.AddCell(cell);
            }

            for (int rh = 0; rh < reptab.Columns.Count; rh++)
            {
                tbl.AddCell(reptab.Columns[rh].ColumnName.ToUpper());
            }

            for (int row = 0; row < reptab.Rows.Count; row++)
            {
                for (int col = 0; col < reptab.Columns.Count; col++)
                {
                    PdfPCell cell;
                    String   dtype = reptab.Rows[row][reptab.Columns[col]].GetType().Name;
                    if (reptab.Rows[row][reptab.Columns[col]].GetType().Name.Equals("Double"))
                    {
                        cell = new PdfPCell(new Phrase(Convert.ToDouble(reptab.Rows[row][reptab.Columns[col]]).ToString("n2").ToString(), tblfnt));

                        cell.HorizontalAlignment = 2;
                    }
                    else if (reptab.Rows[row][reptab.Columns[col]].GetType().Name.Equals("Int32"))
                    {
                        cell = new PdfPCell(new Phrase(reptab.Rows[row][reptab.Columns[col]].ToString(), tblfnt));
                        cell.HorizontalAlignment = 2;
                    }
                    else
                    {
                        cell = new PdfPCell(new Phrase(reptab.Rows[row][reptab.Columns[col]].ToString(), tblfnt));
                        cell.HorizontalAlignment = 0;
                    }
                    tbl.AddCell(cell);
                }
            }
            doc.Open();
            MyPager ev = new MyPager();

            writer.PageEvent = ev;
            doc.Add(tbl);
            doc.Close();
            //openpdf(fname);
        }