protected void btn_commonprint_OnClick(object sender, EventArgs e)
    {
        try
        {
            string coename  = "";
            string strquery = "select *,district+' - '+pincode  as districtpin from collinfo where college_code='" + Session["collegecode"].ToString() + "'";
            ds.Dispose();
            ds.Reset();
            ds = d2.select_method_wo_parameter(strquery, "Text");
            string Collegename = "";
            string aff         = "";
            string collacr     = "";
            string dispin      = "";
            string category    = "";
            if (ds.Tables[0].Rows.Count > 0)
            {
                Collegename = ds.Tables[0].Rows[0]["Collname"].ToString();
                aff         = ds.Tables[0].Rows[0]["affliatedby"].ToString();
                string[] strpa = aff.Split(',');
                aff      = strpa[0];
                coename  = ds.Tables[0].Rows[0]["coe"].ToString();
                collacr  = ds.Tables[0].Rows[0]["acr"].ToString();
                dispin   = ds.Tables[0].Rows[0]["districtpin"].ToString();
                category = ds.Tables[0].Rows[0]["category"].ToString();
            }
            string degreecode = ddlbranch.SelectedValue.ToString();
            //string
            //string eve = d2.GetFunction(" select c.type from Degree d,Course c where d.Course_Id=c.Course_Id and d.Degree_Code='" + degreecode + "'");
            string eve     = "";
            string course  = "";
            string deptacr = "";

            string headingquery = "select c.type,c.Course_Name,de.dept_name from Degree d,Course c,Department de where d.Course_Id=c.Course_Id and de.Dept_Code=d.Dept_Code and d.Degree_Code='" + degreecode + "'";
            hds = d2.select_method_wo_parameter(headingquery, "Text");
            if (hds.Tables[0].Rows.Count > 0)
            {
                eve     = hds.Tables[0].Rows[0]["type"].ToString();
                course  = hds.Tables[0].Rows[0]["Course_Name"].ToString();
                deptacr = hds.Tables[0].Rows[0]["dept_name"].ToString();
            }
            string batch = ddlbatch.SelectedItem.Text;
            string title = "PAPERS SELECTED BY THE STUDENTS OF " + course + " - " + deptacr + " - BATCH " + batch + " (" + eve + ")";

            Font Fontbold1  = new Font("Times New Roman", 15, FontStyle.Bold);
            Font font2bold  = new Font("Times New Roman", 12, FontStyle.Bold);
            Font font2small = new Font("Times New Roman", 12, FontStyle.Regular);
            Font font3bold  = new Font("Times New Roman", 9, FontStyle.Bold);
            Font font3small = new Font("Times New Roman", 10, FontStyle.Regular);
            Font font4bold  = new Font("Times New Roman", 7, FontStyle.Bold);
            Font font4small = new Font("Times New Roman", 7, FontStyle.Regular);

            Gios.Pdf.PdfDocument  mydoc;
            Gios.Pdf.PdfPage      mypdfpage;
            Gios.Pdf.PdfTable     table1forpage2;
            Gios.Pdf.PdfTablePage newpdftabpage2;

            if (FpSpread2.Sheets[0].RowCount > 0)
            {
                int       nofocolun = 0;
                Hashtable hatrowset = new Hashtable();
                int       haskpage  = 0;
                int       checkrow  = 0;
                for (int r = 0; r < FpSpread2.Sheets[0].RowCount; r++)
                {
                    string nameval = FpSpread2.Sheets[0].Cells[r, 1].Text.ToString();
                    if (nameval.Trim() != "")
                    {
                        checkrow++;
                        if (checkrow == 11 || checkrow == 1)
                        {
                            haskpage++;
                            checkrow = 1;
                        }
                    }
                    if (hatrowset.Contains(haskpage))
                    {
                        hatrowset[haskpage] = Convert.ToInt32(hatrowset[haskpage]) + 1;
                    }
                    else
                    {
                        hatrowset.Add(haskpage, 1);
                    }
                }
                int pagcount = hatrowset.Count;
                haskpage = 0;
                int totcol     = FpSpread2.Sheets[0].ColumnCount - 3;
                int noofcolumn = totcol / 10;
                if (((FpSpread2.Sheets[0].ColumnCount - 3) % 10) > 0)
                {
                    noofcolumn++;
                }
                mydoc = new Gios.Pdf.PdfDocument(PdfDocumentFormat.InCentimeters(60, 40));
                int startcolun = 0;
                int endcolumn;
                int stratrow = 0;
                int endrow   = 0;
                for (int pc = 1; pc <= pagcount; pc++)
                {
                    int noofrows = Convert.ToInt32(hatrowset[pc]);
                    startcolun = 3;
                    stratrow   = endrow;
                    endrow     = stratrow + noofrows;
                    startcolun = 3;
                    int colcou = 3;
                    for (int col = 0; col < noofcolumn; col++)
                    {
                        if (col > 0)
                        {
                            startcolun = startcolun + 10;
                        }
                        endcolumn = startcolun + 10;
                        if (endcolumn > FpSpread2.Sheets[0].ColumnCount)
                        {
                            endcolumn = FpSpread2.Sheets[0].ColumnCount;
                        }
                        colcou    = colcou + 10;
                        nofocolun = 13;
                        if (colcou > FpSpread2.Sheets[0].ColumnCount)
                        {
                            colcou    = (FpSpread2.Sheets[0].ColumnCount + 10) - colcou;
                            nofocolun = colcou + 3;
                        }

                        mypdfpage = mydoc.NewPage();
                        int coltop = 20;

                        #region Left Logo

                        if (File.Exists(HttpContext.Current.Server.MapPath("~/college/Left_Logo.jpeg")))
                        {
                            PdfImage LogoImage = mydoc.NewImage(HttpContext.Current.Server.MapPath("~/college/Left_Logo.jpeg"));
                            mypdfpage.Add(LogoImage, 35, 20, 320);
                        }

                        #endregion

                        #region TOP DETAILS

                        coltop = coltop + 10;

                        PdfTextArea ptc = new PdfTextArea(Fontbold1, System.Drawing.Color.Black,
                                                          new PdfArea(mydoc, 0, coltop, 1700, 30), System.Drawing.ContentAlignment.TopCenter, Collegename + "(" + category + ")");
                        mypdfpage.Add(ptc);

                        coltop = coltop + 20;

                        ptc = new PdfTextArea(Fontbold1, System.Drawing.Color.Black,
                                              new PdfArea(mydoc, 0, coltop, 1700, 30), System.Drawing.ContentAlignment.TopCenter, title);
                        mypdfpage.Add(ptc);

                        coltop = coltop + 20;

                        //ptc = new PdfTextArea(font2bold, System.Drawing.Color.Black,
                        //                                            new PdfArea(mydoc, 560, coltop, 595, 30), System.Drawing.ContentAlignment.TopCenter, aff);
                        //mypdfpage.Add(ptc);
                        //coltop = coltop + 15;

                        //ptc = new PdfTextArea(font2bold, System.Drawing.Color.Black,
                        //                                            new PdfArea(mydoc, 560, coltop, 595, 30), System.Drawing.ContentAlignment.TopCenter, dispin);
                        //mypdfpage.Add(ptc);

                        #endregion

                        # region Table Binding

                        table1forpage2 = mydoc.NewTable(font3small, noofrows + 1, nofocolun, 4);
                        table1forpage2.VisibleHeaders = false;
                        table1forpage2.SetBorders(Color.Black, 1, BorderType.CompleteGrid);
                        table1forpage2.Cell(0, 0).SetContentAlignment(ContentAlignment.MiddleCenter);
                        table1forpage2.Cell(0, 0).SetContent("S.No");
                        table1forpage2.Columns[0].SetWidth(30);
                        table1forpage2.Cell(0, 1).SetContentAlignment(ContentAlignment.MiddleCenter);
                        table1forpage2.Cell(0, 1).SetContent("Reg.No");
                        table1forpage2.Columns[1].SetWidth(60);
                        table1forpage2.Cell(0, 2).SetContentAlignment(ContentAlignment.MiddleCenter);
                        table1forpage2.Cell(0, 2).SetContent("Student Name");
                        table1forpage2.Columns[2].SetWidth(150);
                        //table1forpage2.Cell(0, 3).SetContentAlignment(ContentAlignment.MiddleCenter);
                        //table1forpage2.Cell(0, 3).SetContent("(Total Papers Selected)");
                        //table1forpage2.Columns[3].SetWidth(80);
                        //table1forpage2.Cell(0, 4).SetContentAlignment(ContentAlignment.MiddleCenter);
                        //table1forpage2.Cell(0, 4).SetContent("Total Papers Appeared");
                        //table1forpage2.Columns[4].SetWidth(80);

                        table1forpage2.Cell(0, 0).SetFont(font2bold);
                        table1forpage2.Cell(0, 1).SetFont(font2bold);
                        table1forpage2.Cell(0, 2).SetFont(font2bold);
                        //table1forpage2.Cell(0, 3).SetFont(font2bold);
                        //table1forpage2.Cell(0, 4).SetFont(font2bold);

                        int totalrow = endrow - stratrow;
                        int tr       = 0;
                        int tc       = 3;
                        for (int r = stratrow; r < endrow; r++)
                        {
                            tr++;
                            tc = 2;
                            table1forpage2.Cell(tr, 0).SetContentAlignment(ContentAlignment.MiddleCenter);
                            table1forpage2.Cell(tr, 1).SetContentAlignment(ContentAlignment.MiddleLeft);
                            table1forpage2.Cell(tr, 2).SetContentAlignment(ContentAlignment.MiddleLeft);
                            //table1forpage2.Cell(tr, 3).SetContentAlignment(ContentAlignment.MiddleCenter);
                            //table1forpage2.Cell(tr, 4).SetContentAlignment(ContentAlignment.MiddleCenter);
                            table1forpage2.Cell(tr, 0).SetContent(FpSpread2.Sheets[0].Cells[r, 0].Text.ToString());
                            table1forpage2.Cell(tr, 1).SetContent(FpSpread2.Sheets[0].Cells[r, 1].Text.ToString());
                            table1forpage2.Cell(tr, 1).SetFont(font2bold);
                            table1forpage2.Cell(tr, 2).SetContent(FpSpread2.Sheets[0].Cells[r, 2].Text.ToString());
                            table1forpage2.Cell(tr, 2).SetFont(font2bold);
                            //table1forpage2.Cell(tr, 3).SetContent(FpSpread2.Sheets[0].Cells[r, 3].Text.ToString());
                            //table1forpage2.Cell(tr, 3).SetFont(font3small);
                            //table1forpage2.Cell(tr, 4).SetContent(FpSpread2.Sheets[0].Cells[r, 4].Text.ToString());
                            //table1forpage2.Cell(tr, 4).SetFont(font3small);
                            for (int c = startcolun; c < endcolumn; c++)
                            {
                                tc++;
                                if (tc < FpSpread2.Sheets[0].ColumnCount)
                                {
                                    if (r == stratrow)
                                    {
                                        table1forpage2.Cell(0, tc).SetContentAlignment(ContentAlignment.MiddleCenter);
                                        table1forpage2.Cell(0, tc).SetContent(FpSpread2.Sheets[0].ColumnHeader.Cells[0, c].Text.ToString());
                                        table1forpage2.Cell(0, tc).SetFont(font2bold);
                                        table1forpage2.Columns[tc].SetWidth(100);
                                        table1forpage2.Cell(tr, tc).SetCellPadding(20);
                                    }
                                    table1forpage2.Cell(tr, tc).SetContent(FpSpread2.Sheets[0].Cells[r, c].Text.ToString());
                                    table1forpage2.Cell(tr, tc).SetFont(font2bold);
                                    string value = FpSpread2.Sheets[0].Cells[r, c].Text.ToString().ToString();
                                    if (value.Trim() == "")
                                    {
                                        table1forpage2.Cell(tr, tc).SetContent(".");
                                        table1forpage2.Cell(tr, tc).SetForegroundColor(Color.White);
                                    }
                                    if (totalrow > 40)
                                    {
                                        table1forpage2.Cell(tr, tc).SetCellPadding(1);
                                    }
                                    else if (totalrow > 30)
                                    {
                                        table1forpage2.Cell(tr, tc).SetCellPadding(5);
                                    }
                                    else if (totalrow > 18)
                                    {
                                        table1forpage2.Cell(tr, tc).SetCellPadding(10);
                                    }
                                    else
                                    {
                                        table1forpage2.Cell(tr, tc).SetCellPadding(20);
                                    }
                                }
                            }
                        }
                        newpdftabpage2 = table1forpage2.CreateTablePage(new Gios.Pdf.PdfArea(mydoc, 15, 130, 1670, 5000));
                        mypdfpage.Add(newpdftabpage2);
                        mypdfpage.SaveToDocument();

                        #endregion
                    }
                }

                string appPath = HttpContext.Current.Server.MapPath("~");
                if (appPath != "")
                {
                    string szPath = appPath + "/Report/";
                    string szFile = "SubjectAllotment" + DateTime.Now.ToString("ddMMyyyy") + DateTime.Now.ToString("HHMMss") + ".pdf";
                    mydoc.SaveToFile(szPath + szFile);
                    Response.ClearHeaders();
                    Response.AddHeader("Content-Disposition", "attachment; filename=" + szFile);
                    Response.ContentType = "application/pdf";
                    Response.WriteFile(szPath + szFile);
                }
            }
        }