The page 2 was requested but the document has only 1 pages.

View: New views
2 Messages — Rating Filter:   Alert me  

The page 2 was requested but the document has only 1 pages.

by swati jain :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi williams,

Thanks for replying

 I have one more issue , pls help me , its very urgent

if u can give me ur few mins  pls go through following, else
can you tell me what can cause
The page 2 was requested but the document has only 1 pages.



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
using System.Text;
using iTextSharp.text.html;
using iTextSharp.text.pdf.events;
using System.Data;
using System.Data.SqlClient;
using RSBFL;
using RSBRL;
namespace RSWeb
{

    public class MyHandler1 : iTextSharp.text.pdf.events.PdfPageEventForwarder
    {
        public override void OnEndPage(PdfWriter writer, Document document)
        {



            base.OnStartPage(writer, document);

            Phrase header = new Phrase("**** THIS IS HEADER PART OF THIS PDF ****");
            PdfPTable footer = new PdfPTable(2);

            footer.TotalWidth = 575;
            footer.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
            footer.DefaultCell.Border = Rectangle.NO_BORDER;
            footer.AddCell(new Phrase(new Chunk("  Visit Index")
            .SetAction(new PdfAction(PdfAction.FIRSTPAGE))));


            int intGoToPageNo = 3;
            if (HttpContext.Current.Session["PageNoVisit"] != null)
            {

                if (HttpContext.Current.Session["PageNoVisit"] != "0")
                {
                    intGoToPageNo = Convert.ToInt32(HttpContext.Current.Session["PageNoVisit"].ToString());

                }
            }

            footer.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
            PdfAction action = PdfAction.GotoLocalPage(intGoToPageNo, new PdfDestination(PdfDestination.XYZ, -1, 10000, 0), writer);
            footer.AddCell(new Phrase(new Chunk(" Visit Summary")
           .SetAction(action)));


            PdfContentByte cb = writer.DirectContent;

            //ColumnText.ShowTextAligned(cb, Element.ALIGN_CENTER, header, (document.Right - document.Left) / 2 + document.LeftMargin, document.Top + 10, 0);

            footer.WriteSelectedRows(0, -1, (document.Right - document.Left) / 2 + document.LeftMargin - 300, document.Top + 35, cb);


            base.OnEndPage(writer, document);
            PdfContentByte moCB = writer.DirectContent;
            BaseFont moBF = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);



            String sText;
            Single fLen;



            int intCount = 0;

            if (HttpContext.Current.Session["PreFooter"] != null)
            {
                if (HttpContext.Current.Session["PreFooter"].ToString() != HttpContext.Current.Session["Footer"].ToString())
                {

                    if (HttpContext.Current.Session["PreFooter"].ToString() == "Visit Index ")
                    {
                        int intPageNoVisit = writer.PageNumber;
                        intPageNoVisit = intPageNoVisit + 1;
                        HttpContext.Current.Session["PageNoVisit"] = intPageNoVisit.ToString();


                    }
                    document.ResetPageCount();

                }
            }



            HttpContext.Current.Session["PreFooter"] = HttpContext.Current.Session["Footer"].ToString();


            sText = HttpContext.Current.Session["Footer"].ToString();
            if (sText == "CPX1 ")
            {

                sText = "CPX ";

            }


            int iPageNumber = writer.PageNumber;
            iPageNumber = iPageNumber + 1;
            //intPageNo[i] = writer.PageNumber;
            sText = sText + "00000" + iPageNumber.ToString();
            //if(sText=="")
            //    if(iPageNumber==1)
            //    {
            //        HttpContext.Current.Session["intVisitSummaryPageNo"] =



            fLen = moBF.GetWidthPoint(sText, 8);

            moCB.BeginText();
            moCB.SetFontAndSize(moBF, 8);
            moCB.SetTextMatrix(document.PageSize.Width - 150, 10);
            moCB.ShowText(sText);
            moCB.EndText();

            //moCB.AddTemplate(moTemplate, oDocument.PageSize.Width - 90 + fLen, 30)
            //moCB.BeginText()
            //moCB.SetFontAndSize(moBF, 8)
            //moCB.SetTextMatrix(280, 820)
            //moCB.EndText()

            //'---Line just above footer
            //moCB.MoveTo(30, 40)
            //moCB.LineTo(oDocument.PageSize.Width - 40, 40)
            //moCB.Stroke()





        }

    }


    public partial class Finalizer : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnGeneratePdf_Click(object sender, EventArgs e)
        {


            RSDataEntrySystem obj = new RSDataEntrySystem();
            DataSet dsIndex = new DataSet();
            DataTable objDataTable = new DataTable();
            DataTable objDataTable1 = new DataTable();
            DataTable objDataTable2 = new DataTable();
            DataTable objDataTable3 = new DataTable();
            DataTable objDataTable4 = new DataTable();
            DataTable objDataTable5 = new DataTable();
            DataTable objDataTable6 = new DataTable();
            DataTable objDataTable7 = new DataTable();
            DataTable objDataTable8 = new DataTable();

            obj.GetMedicalRecordIndex(ref dsIndex);
            objDataTable = (DataTable)dsIndex.Tables[0].DefaultView.Table;
            objDataTable1 = (DataTable)dsIndex.Tables[1].DefaultView.Table;
            objDataTable2 = (DataTable)dsIndex.Tables[2].DefaultView.Table;
            objDataTable3 = (DataTable)dsIndex.Tables[3].DefaultView.Table;
            objDataTable4 = (DataTable)dsIndex.Tables[4].DefaultView.Table;
            objDataTable5 = (DataTable)dsIndex.Tables[5].DefaultView.Table;
            objDataTable6 = (DataTable)dsIndex.Tables[6].DefaultView.Table;
            objDataTable7 = (DataTable)dsIndex.Tables[7].DefaultView.Table;
            objDataTable8 = (DataTable)dsIndex.Tables[8].DefaultView.Table;




            // int columnCount = GridView1.Columns.Count;
            int rowCount = objDataTable.Rows.Count; int tableRows = rowCount + 3;
            iTextSharp.text.Table grdTable = new iTextSharp.text.Table(4, rowCount);
            iTextSharp.text.Table grdTable1 = new iTextSharp.text.Table(3, 2);
            float[] f1 = new float[] { 1F, 3.2F, 0.5F };
            float[] fvisit = new float[] { 1F, 1F, 4.2F, 2.5F };

            grdTable.WidthPercentage = 100;
            grdTable.Widths = fvisit;
            grdTable1.Widths = f1;
            grdTable1.DefaultCellBorderColor = Color.GRAY;
            grdTable1.WidthPercentage = 100;
            grdTable1.DefaultCellBorderWidth = 1F;
            grdTable1.BorderWidth = 2f;
            grdTable1.BorderColor = Color.GRAY;


            grdTable.BorderWidth = 2;
            grdTable.BorderColor = Color.BLACK;
            grdTable.Cellpadding = 1;
            grdTable.Cellspacing = 1;

            grdTable.DefaultCell.BorderColor = Color.WHITE;

            Paragraph plogo = new Paragraph("");
            /*
            string FilePath11 =  "\\Images\\JaiGanesh\\compex.bmp";
            iTextSharp.text.Image imgDoc11 = iTextSharp.text.Image.GetInstance(FilePath11);
            imgDoc11.ScaleToFit(100, 60);
            plogo.Add(imgDoc11);
       
            grdTable.AddCell(c);
            c.Add(plogo);*/
            iTextSharp.text.Table grdTableimage = new iTextSharp.text.Table(4, 1);
            Cell cell = new Cell();
            cell.BorderColor = new Color(255, 0, 0);
            string FilePath11 = "C:\\compex.bmp";
            iTextSharp.text.Image imgDoc11 = iTextSharp.text.Image.GetInstance(FilePath11);
            imgDoc11.ScaleToFit(146, 52);
            imgDoc11.Alignment = iTextSharp.text.Image.LEFT_ALIGN; ;
            cell.Colspan = 3;
            cell.Rowspan = 3;
            cell.Add(imgDoc11);

            Cell cell1 = new Cell();
            string FilePath12 = "C:\\compex1.bmp";
            iTextSharp.text.Image imgDoc12 = iTextSharp.text.Image.GetInstance(FilePath12);
            imgDoc12.ScaleToFit(146, 52);
            imgDoc12.Alignment = iTextSharp.text.Image.ALIGN_RIGHT; ;
            //cell.Colspan = 4;
            //cell.Rowspan = 4;
            cell1.Add(imgDoc12);






            grdTableimage.AddCell(cell);
            grdTableimage.AddCell(cell1);
            grdTableimage.BorderColor = Color.WHITE;
            grdTableimage.WidthPercentage = 100;
            AddTableCell("Date", grdTable);
            AddTableCell("Pg.Number", grdTable);
            AddTableCell("Name", grdTable);
            AddTableCell("ReportType", grdTable);



            Document Doc = new Document();
            PdfWriter pdfWriter = PdfWriter.GetInstance(Doc, Response.OutputStream); Doc.Open();
            Font Headerfont = FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.NORMAL, Color.WHITE);

            HeaderFooter header = new HeaderFooter(new Phrase("this is header", Headerfont), false);
            header.Border = Rectangle.NO_BORDER;
            Doc.Header = header;

            //HeaderFooter footer = new HeaderFooter(new Phrase("this is footer"), false);
            //Doc.Footer = footer;
            Doc.SetPageSize(PageSize.A4);
            // Doc.Add(grdTableimage);

            // Doc.Add(plogo);

            // PdfPTable table = new PdfPTable(objDataTable.Columns.Count);

            //iTextSharp.text.ListItem=new iTextSharp.text.ListItem(
            //Chunk c=new Chunk(



            Paragraph PTable1 = new Paragraph("", FontFactory.GetFont(FontFactory.HELVETICA, 8));
            PTable1.Add(grdTableimage);
            //PTable1.Add(imgDoc11);
            for (int i = 0; i < objDataTable.Rows.Count; i++)
            {

                if (i % 2 == 0)
                {

                    grdTable.DefaultCell.BackgroundColor = new Color(197, 217, 241);//Color.CYAN;

                }
                else
                {

                    grdTable.DefaultCell.BackgroundColor = Color.WHITE;
                }


                for (int j = 0; j < objDataTable.Columns.Count; j++)
                {



                    Paragraph p1 = new Paragraph("", FontFactory.GetFont(FontFactory.HELVETICA, 8));
                    //  p1.Add(new Chunk(objDataTable.Rows[i][j].ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 255))).SetLocalGoto(objDataTable.Rows[i]["PageNo"].ToString()));

                    string strReportingID = objDataTable.Rows[i]["ReportTypeID"].ToString();
                    if (objDataTable.Columns[j].ColumnName != "PageNo")
                    {
                        p1.Add(new Chunk(objDataTable.Rows[i][j].ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL, Color.BLACK)).SetLocalGoto(strReportingID));

                    }
                    else
                    {
                        p1.Add(new Chunk(objDataTable.Rows[i][j].ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL, Color.BLACK)).SetLocalGoto(" loc" + i.ToString()));

                    }

                    if (objDataTable.Columns[j].ColumnName != "ReportTypeID")
                        grdTable.AddCell(p1);


                    //grdTable.AddCell(p2);
                    //grdTable.AddCell(objDataTable.Rows[i][j].ToString());

                }
            }




            PTable1.Add(grdTable);

            //Chapter PatientName = new Chapter("Patient Name", 0);
            //Doc.Add(PatientName);

            Font chFont = FontFactory.GetFont(FontFactory.HELVETICA, 1, Font.NORMAL, new Color(255, 0, 0));

            Paragraph pPatient = new Paragraph("", chFont);
            //Chapter chpRoot = new Chapter(pPatient, 1);
            //chpRoot.BookmarkTitle = "Patient Name";
            //chpRoot.BookmarkOpen = false;

            //Section chapterIndex = chpRoot.AddSection(PTable1, 1);//new Chapter(PTable1, 1);
            //chapterIndex.BookmarkTitle = "Visit Index";
            //chapterIndex.BookmarkOpen = false;
            Doc.Add(PTable1);
            PdfContentByte cb = pdfWriter.DirectContent;

            PdfAction actionPatient = PdfAction.GotoLocalPage(1, new PdfDestination(PdfDestination.XYZ, -1, 10000, 0), pdfWriter);
            PdfOutline Patient = new PdfOutline(cb.RootOutline, actionPatient, "Patient", false);

            PdfAction actionVisitIndex = PdfAction.GotoLocalPage(1, new PdfDestination(PdfDestination.XYZ, -1, 10000, 0), pdfWriter);
            PdfOutline VisitIndex = new PdfOutline(Patient, actionVisitIndex, "Visit Index", false);


            //Chapter chapterIndex = new Chapter(PTable1, 1);
            //chapterIndex.BookmarkTitle = "Visit Index";
            //chapterIndex.BookmarkOpen = false;
            //Doc.Add(chapterIndex);


            int Count = pdfWriter.PageNumber;
            MyHandler1 myEvents = new MyHandler1();
            Session["Footer"] = "Visit Index ";
            pdfWriter.PageEvent = myEvents;
            Doc.ResetPageCount();
            myEvents.OnEndPage(pdfWriter, Doc);

            Doc.NewPage();
            // PdfPTable table1 = new PdfPTable(objDataTable1.Columns.Count);

            grdTable1.BorderWidth = 2f; grdTable1.BorderColor = Color.GRAY;
            grdTable1.Cellpadding = 1; grdTable1.Cellspacing = 1;





            grdTable1.AutoFillEmptyCells = true;
            grdTable.AutoFillEmptyCells = true;



            MyHandler1 myEvents1 = new MyHandler1();
            Session["Footer"] = "Chronological Visit Summary ";
            pdfWriter.PageEvent = myEvents1;
            myEvents.OnEndPage(pdfWriter, Doc);

            Paragraph pVisitSummary = new Paragraph("Visit Summary");
            Doc.Add(pVisitSummary);
            int k = pdfWriter.CurrentPageNumber;
            PdfAction objAction = iTextSharp.text.pdf.PdfAction.GotoLocalPage(k, new iTextSharp.text.pdf.PdfDestination(iTextSharp.text.pdf.PdfDestination.FITH), pdfWriter);
            PdfOutline objSubOutline = new iTextSharp.text.pdf.PdfOutline(Patient, objAction, "Visit Summary");


            for (int i = 0; i < objDataTable1.Rows.Count; i++)
            {
                for (int j = 0; j < objDataTable1.Columns.Count; j++)
                {




                    // grdTable.AddCell(p1);

                    Paragraph p2 = new Paragraph("", FontFactory.GetFont(FontFactory.HELVETICA, 12));

                    string str = objDataTable1.Rows[i][j].ToString();
                    // p2.Add(new Chunk(str, FontFactory.GetFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 255, 0))).SetLocalDestination(objDataTable.Rows[i]["PageNo"].ToString()));
                    p2.Add(new Chunk(objDataTable.Rows[i]["ReportTypeID"].ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 12, Font.NORMAL, Color.WHITE)).SetLocalDestination(objDataTable.Rows[i]["ReportTypeID"].ToString()));



                    Paragraph p1 = new Paragraph("", FontFactory.GetFont(FontFactory.HELVETICA, 12));
                    //  p1.Add(new Chunk(objDataTable.Rows[i][j].ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 12, Font.NORMAL, new Color(0, 0, 255))).SetLocalGoto(objDataTable.Rows[i]["PageNo"].ToString()));


                    if (objDataTable1.Columns[j].ColumnName != "PageNo")
                    {
                        //  p1.Add(new Chunk(objDataTable.Rows[i][j].ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 12, Font.NORMAL, Color.BLACK)).SetLocalGoto(strReportingID));

                    }
                    else
                    {
                        p1.Add(new Chunk(objDataTable1.Rows[i][j].ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 12, Font.NORMAL, Color.BLACK)).SetLocalGoto(" loc" + i.ToString()));

                    }




                    string strProvider = objDataTable1.Columns[j].ColumnName.ToString();

                    if (strProvider != "ReportTypeID")
                    {
                        string strPage = objDataTable1.Columns[j].ColumnName.ToString();
                        Paragraph PCell = new Paragraph("");
                        Paragraph PSeparated = new Paragraph("", FontFactory.GetFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK));
                        Paragraph PSeparatedCnt = new Paragraph("", FontFactory.GetFont(FontFactory.HELVETICA, 12, Font.NORMAL, Color.BLACK));


                        if (strPage != "PageNo")
                        {
                            if (objDataTable1.Columns[j].ColumnName.ToString() == "Summary")
                            {

                                string[] strArr = objDataTable1.Rows[i]["Summary"].ToString().Split(';');


                                foreach (string s in strArr)
                                {

                                    string[] strArray = s.Split(':');
                                    // strSeparated = strSeparated+ strArray[0]+Environment.NewLine + strArray[1];
                                    //PSeparated.Add(strArray[0] + ":");
                                    //PSeparatedCnt.Add(strArray[1]);

                                    PSeparated = new Paragraph(strArray[0] + ":", FontFactory.GetFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK));
                                    PSeparatedCnt = new Paragraph(strArray[1], FontFactory.GetFont(FontFactory.HELVETICA, 12, Font.NORMAL, Color.BLACK));

                                    PCell.Add(PSeparated);
                                    PCell.Add(PSeparatedCnt);

                                }



                            }

                            else
                            {

                                PCell = new Paragraph(objDataTable1.Rows[i][j].ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK));

                            }


                        }
                        else
                        {
                            PCell = new Paragraph(objDataTable1.Rows[i][j].ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 1, Font.NORMAL, Color.BLUE));

                        }

                        //iTextSharp.text.Table nested = new iTextSharp.text.Table(1,1);
                        //Cell nestedc = new Cell();
                        //nestedc.Colspan = 0;
                        //nestedc.Rowspan = 0;
                        //nestedc.Add(PCell);
                        //nested.AddCell(nestedc);
                        Cell c11 = new Cell(PCell);//
                        c11.Header = true;
                        c11.BorderWidth = 1f;
                        c11.BorderColor = Color.GRAY;
                        c11.HorizontalAlignment = Element.ALIGN_CENTER;
                        c11.VerticalAlignment = Element.ALIGN_TOP;
                        c11.UseBorderPadding = true;

                        if (objDataTable1.Columns[j].ColumnName.ToString() != "ReportType")
                            if (objDataTable1.Columns[j].ColumnName.ToString() != "Summary")
                            {
                                c11.BackgroundColor = new Color(197, 217, 241);
                                c11.VerticalAlignment = Element.ALIGN_MIDDLE;


                            }
                            else
                            {
                                c11.HorizontalAlignment = Element.ALIGN_LEFT;
                            }
                        c11.Add(p1);



                        //c11.BorderWidth = 1.1F;
                        // c11.Colspan = 2;
                        //c11.Rowspan = 2;
                        //iTextSharp.text.Table nested = new iTextSharp.text.Table(1, 1);
                        // nested.AddCell(c11);

                        grdTable1.AddCell(c11);
                        //nested.InsertTable(nested,new  Point);



                    }
                    else
                    {
                        p2.Add(p1);

                        grdTable1.AddCell(p2);

                    }



                    //grdTable1.AddCell(objDataTable1.Rows[i][j].ToString());

                }

                Paragraph PTable2 = new Paragraph("", FontFactory.GetFont(FontFactory.HELVETICA, 12));
                PTable2.Add(grdTable1);



                Doc.Add(PTable2);

                //int intPageNumber = pdfWriter.PageNumber;



                grdTable1 = new iTextSharp.text.Table(3, 2);
                float[] f2 = new float[] { 1F, 3.2F, 0.5F };
                grdTable1.Widths = f2;

                grdTable1.WidthPercentage = 100;
                grdTable1.BorderWidth = 1; grdTable1.BorderColor = new Color(0, 0, 255);
                grdTable1.Cellpadding = 3; grdTable1.Cellspacing = 1;

                grdTable1.DefaultCellBorderColor = Color.GRAY;
                grdTable1.WidthPercentage = 100;
                grdTable1.DefaultCellBorderWidth = 1F;
                grdTable1.BorderWidth = 2f;
                grdTable1.BorderColor = Color.GRAY;



            }

            Doc.NewPage();

            //Chapter chapterImg = new Chapter("", 1);
            #region By Date
            PdfAction ActionByDate = iTextSharp.text.pdf.PdfAction.GotoLocalPage(pdfWriter.CurrentPageNumber, new iTextSharp.text.pdf.PdfDestination(iTextSharp.text.pdf.PdfDestination.FITH), pdfWriter);
            PdfOutline ByDate = new iTextSharp.text.pdf.PdfOutline(VisitIndex, ActionByDate, "By Date", false);


            //Section chapterImg = chapterIndex.AddSection("");
            //chapterImg.BookmarkTitle = "By Date";
            //chapterImg.BookmarkOpen = false;

            MyHandler1 myEvents2 = new MyHandler1();
            Session["Footer"] = "CPX ";
            pdfWriter.PageEvent = myEvents2;
            myEvents.OnEndPage(pdfWriter, Doc);

            int[] intPageNo = new int[objDataTable2.Rows.Count + 1];

            // intPageNo[0] = pdfWriter.CurrentPageNumber;
            DataSet dsTemp = new DataSet();
            DataTable Tables = new DataTable();
            dsTemp.Tables.Add(Tables);

            dsTemp.Tables[0].Columns.Add("PageNo", System.Type.GetType("System.String"));
            dsTemp.Tables[0].Columns.Add("FilePath", System.Type.GetType("System.String"));
            dsTemp.Tables[0].TableName = "Table";




            for (int i = 0; i < objDataTable2.Rows.Count; i++)
            {

                if (i == 0)
                {

                    intPageNo[0] = pdfWriter.CurrentPageNumber;
                }




                string strFilePath = objDataTable2.Rows[i]["FilePath"].ToString();
                int FileCount = strFilePath.IndexOf(';');
                if (FileCount != -1)
                {

                    string[] Files = strFilePath.Split(';');

                    foreach (string strFile in Files)
                    {



                        DataRow myRow = dsTemp.Tables[0].NewRow();
                        myRow[0] = intPageNo[i].ToString();
                        myRow[1] = strFile;

                        dsTemp.Tables[0].Rows.Add(myRow);

                        intPageNo[i + 1] = intPageNo[i] + 1;



                        Paragraph pImage = new Paragraph(objDataTable2.Rows[i]["BookMark"].ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 16, Font.BOLD, Color.WHITE));
                        pImage.Add(new Chunk(" loc" + i.ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 12, Font.NORMAL, Color.WHITE)).SetLocalDestination(" loc" + i.ToString()));


                        string FilePath = strFile;//objDataTable2.Rows[i]["FilePath"].ToString();
                        iTextSharp.text.Image imgDoc = iTextSharp.text.Image.GetInstance(FilePath);
                        imgDoc.ScaleAbsolute(574F, 730F);
                        pImage.Add(imgDoc);

                        //Section section1 = chapterImg.AddSection(pImage);
                        //section1.BookmarkTitle = objDataTable2.Rows[i]["BookMark"].ToString();
                        //section1.BookmarkOpen = false;
                        Doc.Add(pImage);


                    }
                }
                else
                {

                    Paragraph pImage = new Paragraph(objDataTable2.Rows[i]["BookMark"].ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 16, Font.BOLD, Color.WHITE));
                    pImage.Add(new Chunk(" loc" + i.ToString(), FontFactory..GetFont(FontFactory.HELVETICA, 12, Font.NORMAL, Color.WHITE)).SetLocalDestination(" loc" + i.ToString()));


                    DataRow myRow = dsTemp.Tables[0].NewRow();
                    myRow[0] = intPageNo[i].ToString();
                    myRow[1] = objDataTable2.Rows[i]["FilePath"].ToString();

                    dsTemp.Tables[0].Rows.Add(myRow);

                    intPageNo[i + 1] = intPageNo[i] + 1;

                    string FilePath = objDataTable2.Rows[i]["FilePath"].ToString();
                    iTextSharp.text.Image imgDoc = iTextSharp.text.Image.GetInstance(FilePath);
                    imgDoc.ScaleAbsolute(574F, 700F);
                    pImage.Add(imgDoc);

                    //Section section1 = chapterImg.AddSection(pImage);
                    //section1.BookmarkTitle = objDataTable2.Rows[i]["BookMark"].ToString();
                    //section1.BookmarkOpen = false;
                    Doc.Add(pImage);
                }

            }

            #region outlines for "By Date"

            for (int i = 0; i < objDataTable2.Rows.Count; i++)
            {




                string strFilePath = objDataTable2.Rows[i]["FilePath"].ToString();
                int FileCount = strFilePath.IndexOf(';');
                if (FileCount != -1)
                {

                    string[] Files = strFilePath.Split(';');

                    foreach (string strFile in Files)
                    {



                        string FilePath = strFile;
                        DataRow[] RowPageNo = dsTemp.Tables[0].Select("FilePath='" + FilePath + "'");
                        int intGoTo = Convert.ToInt32(RowPageNo[0]["PageNo"]);
                        PdfAction action1 = PdfAction.GotoLocalPage(intGoTo, new PdfDestination(PdfDestination.XYZ, -1, 10000, 0), pdfWriter);
                        PdfOutline ByDateBookMarks = new PdfOutline(ByDate, action1, objDataTable2.Rows[i]["BookMark"].ToString(), false);

                    }
                }
                else
                {

                    DataRow[] RowPageNo = dsTemp.Tables[0].Select("FilePath='" + strFilePath + "'");
                    int intGoTo = Convert.ToInt32(RowPageNo[0]["PageNo"]);
                    PdfAction action1 = PdfAction.GotoLocalPage(intGoTo, new PdfDestination(PdfDestination.XYZ, -1, 10000, 0), pdfWriter);
                    PdfOutline ByDateBookMarks = new PdfOutline(ByDate, action1, objDataTable2.Rows[i]["BookMark"].ToString(), false);

                }

            }

            #endregion



            // Doc.Add(chapterImg);
            //pdfWriter.ResetPageCount();
            #endregion
            Doc.NewPage();


            MyHandler1 myEvents3 = new MyHandler1();
            // Session["Footer"] = "CPX1 ";
            Session["Footer"] = "CPX ";
            pdfWriter.PageEvent = myEvents3;
            myEvents.OnEndPage(pdfWriter, Doc);


            Font chapterFont = FontFactory.GetFont(FontFactory.HELVETICA, 1, Font.NORMAL, Color.WHITE);
            Font sectionFont = FontFactory.GetFont(FontFactory.HELVETICA, 1, Font.NORMAL, Color.WHITE);
            Font subsectionFont = FontFactory.GetFont(FontFactory.HELVETICA, 1, Font.BOLD, Color.WHITE);


            Paragraph cTitle = new Paragraph("By Provider", chapterFont);
            //Chapter chpByProvider = new Chapter(cTitle, 1);
            //Section chpByProvider = chapterIndex.AddSection(cTitle);
            //chpByProvider.BookmarkTitle = "By Provider";
            //chpByProvider.BookmarkOpen = false;
            int[] intAdPageNo = new int[objDataTable3.Rows.Count + 1];

            // intPageNo[0] = pdfWriter.CurrentPageNumber;
            DataSet dsAdTemp = new DataSet();
            DataTable TableAd = new DataTable();
            dsAdTemp.Tables.Add(TableAd);

            dsAdTemp.Tables[0].Columns.Add("PageNo", System.Type.GetType("System.String"));
            dsAdTemp.Tables[0].Columns.Add("FilePath", System.Type.GetType("System.String"));
            dsAdTemp.Tables[0].TableName = "Table";





            for (int i = 0; i < objDataTable3.Rows.Count; i++)
            {


                if (i == 0)
                {

                    intAdPageNo[0] = pdfWriter.CurrentPageNumber;

                }


                string strFilePath = objDataTable3.Rows[i]["FilePath"].ToString();
                int FileCount = strFilePath.IndexOf(';');
                if (FileCount != -1)
                {

                    string[] Files = strFilePath.Split(';');

                    foreach (string strFile in Files)
                    {
                        Paragraph pImage = new Paragraph("", FontFactory.GetFont(FontFactory.HELVETICA, 16, Font.BOLD, Color.WHITE));
                        string FilePath = strFile;//dtFilter.Rows[j]["FilePath"].ToString();

                        DataRow myRow = dsAdTemp.Tables[0].NewRow();
                        myRow[0] = intAdPageNo[i].ToString();
                        myRow[1] = strFile;
                        dsAdTemp.Tables[0].Rows.Add(myRow);
                        intAdPageNo[i + 1] = intAdPageNo[i] + 1;


                        iTextSharp.text.Image imgDoc = iTextSharp.text.Image.GetInstance(FilePath);
                        imgDoc.ScaleAbsolute(574F, 730F);
                        pImage.Add(imgDoc);
                        Doc.Add(pImage);

                        //Section sec1 = sec3.AddSection(pImage);
                        //sec1.BookmarkTitle = dtFilter.Rows[j]["BookMark"].ToString();
                    }
                }
                else
                {



                    Paragraph pImage = new Paragraph("", FontFactory.GetFont(FontFactory.HELVETICA, 16, Font.BOLD, Color.WHITE));
                    string FilePath = objDataTable3.Rows[i]["FilePath"].ToString();
                    DataRow myRow = dsAdTemp.Tables[0].NewRow();
                    myRow[0] = intAdPageNo[i].ToString();
                    myRow[1] = FilePath;
                    dsAdTemp.Tables[0].Rows.Add(myRow);
                    intAdPageNo[i + 1] = intAdPageNo[i] + 1;
                    iTextSharp.text.Image imgDoc = iTextSharp.text.Image.GetInstance(FilePath);
                    imgDoc.ScaleAbsolute(574F, 730F);
                    pImage.Add(imgDoc);


                    //Section sec1 = sec3.AddSection(pImage);
                    //sec1.BookmarkTitle = dtFilter.Rows[j]["BookMark"].ToString();


                }


            }



            //  Doc.Add(chpByProvider);

            #region Added by Outline

            //Paragraph cTitle = new Paragraph("By Provider", chapterFont);
            //Chapter chpByProvider = new Chapter(cTitle, 1);
            // Section chpByProvider = chapterIndex.AddSection(cTitle);
            // chpByProvider.BookmarkTitle = "By Provider";
            // chpByProvider.BookmarkOpen = false;




            Boolean ifAlreadyExist = false;
            string strProviderName = "";


            DataSet dsGoTo = new DataSet();
            DataTable TableGoTo = new DataTable();
            dsGoTo.Tables.Add(TableGoTo);

            dsGoTo.Tables[0].Columns.Add("PageNo", System.Type.GetType("System.String"));
            dsGoTo.Tables[0].Columns.Add("OutLineName", System.Type.GetType("System.String"));
            dsGoTo.Tables[0].TableName = "Table";


            for (int i = 0; i < objDataTable3.Rows.Count; i++)
            {

                if (strProviderName == objDataTable3.Rows[i]["ProviderName"].ToString())
                {

                    ifAlreadyExist = true;

                }

                strProviderName = objDataTable3.Rows[i]["ProviderName"].ToString();

                if (ifAlreadyExist != true)
                {
                    DataView dv = objDataTable3.DefaultView;
                    dv.RowFilter = "ProviderName='" + objDataTable3.Rows[i]["ProviderName"].ToString() + "'";
                    DataTable dtFilter = dv.ToTable();
                    for (int j = 0; j < dtFilter.Rows.Count; j++)
                    {



                        string strFilePath = dtFilter.Rows[j]["FilePath"]..ToString();
                        int FileCount = strFilePath.IndexOf(';');
                        if (FileCount != -1)
                        {

                            string[] Files = strFilePath.Split(';');

                            foreach (string strFile in Files)
                            {

                                DataRow[] RowPageNo = dsTemp.Tables[0].Select("FilePath='" + strFile + "'");
                                int intGoTo = Convert.ToInt32(RowPageNo[0]["PageNo"]);

                                if (i == 0)
                                {
                                    DataRow myRow = dsGoTo.Tables[0].NewRow();
                                    myRow[0] = intGoTo.ToString();
                                    myRow[1] = "ByProviderGoto";
                                    dsGoTo.Tables[0].Rows.Add(myRow);
                                }



                            }
                        }
                        else
                        {

                            DataRow[] RowPageNo = dsTemp.Tables[0].Select("FilePath='" + strFilePath + "'");
                            int intGoTo = Convert.ToInt32(RowPageNo[0]["PageNo"]);

                            if (i == 0)
                            {
                                DataRow myRow = dsGoTo.Tables[0].NewRow();
                                myRow[0] = intGoTo.ToString();
                                myRow[1] = "ByProviderGoto";
                                dsGoTo.Tables[0].Rows.Add(myRow);
                            }




                        }
                    }


                }


            }





            DataRow[] RowPageNoProv = dsGoTo.Tables[0].Select("OutLineName='ByProviderGoto'");
            int intGoToProv = Convert.ToInt32(RowPageNoProv[0]["PageNo"]);

            PdfAction action = PdfAction.GotoLocalPage(intGoToProv, new PdfDestination(PdfDestination.XYZ, -1, 10000, 0), pdfWriter);
            PdfOutline ProviderRoot = new PdfOutline(VisitIndex, action, "By Provider", false);



            for (int i = 0; i < objDataTable3.Rows.Count; i++)
            {



                if (strProviderName == objDataTable3.Rows[i]["ProviderName"].ToString())
                {

                    ifAlreadyExist = true;

                }

                strProviderName = objDataTable3.Rows[i]["ProviderName"].ToString();

                if (ifAlreadyExist != true)
                {

                    //Paragraph cPar = new Paragraph("Provider " + i, chapterFont);
                    //Section sec = chapter.AddSection(cPar);

                    Paragraph pProvider = new Paragraph(objDataTable3.Rows[i]["ProviderName"].ToString(), chapterFont);



                    PdfAction action1 = PdfAction.GotoLocalPage(1, new PdfDestination(PdfDestination.XYZ, -1, 10000, 0), pdfWriter);
                    PdfOutline Provider = new PdfOutline(ProviderRoot, action, objDataTable3.Rows[i]["ProviderName"].ToString(), false);


                    //Section section1 = chpByProvider.AddSection(pProvider);
                    //section1.BookmarkTitle = objDataTable3.Rows[i]["ProviderName"].ToString();
                    //section1.BookmarkOpen = false;
                    PdfAction action2 = PdfAction.GotoLocalPage(intPageNo[i], new PdfDestination(PdfDestination.XYZ, -1, 10000, 0), pdfWriter);
                    PdfOutline Providersum = new PdfOutline(Provider, action2, "Summarized Documents", false);


                    PdfAction actionA = PdfAction.GotoLocalPage(intPageNo[i], new PdfDestination(PdfDestination.XYZ, -1, 10000, 0), pdfWriter);
                    PdfOutline ProviderAdm = new PdfOutline(Provider, actionA, "Administrative Documents", false);

                    //Paragraph cPar1 = new Paragraph("Summarized ", chapterFont);
                    //Section sec2 = section1.AddSection(cPar1);
                    //sec2.BookmarkTitle = "Summarized Documents";
                    //sec2.BookmarkOpen = false;

                    DataView dv = objDataTable3.DefaultView;
                    dv.RowFilter = "ProviderName='" + objDataTable3.Rows[i]["ProviderName"].ToString() + "'";
                    DataTable dtFilter = dv.ToTable();


                    for (int j = 0; j < dtFilter.Rows.Count; j++)
                    {

                        //Paragraph blahblah = new Paragraph("");
                        //iTextSharp.text.Image png = iTextSharp.text.Image.GetInstance(@"D:\pdfWeb\Images\JaiGanesh\00001.tif");
                        //png.ScaleAbsolute(574F, 730F);
                        //blahblah.Add(png);

                        //Paragraph pImage = new Paragraph(dtFilter.Rows[j]["BookMark"].ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 1, Font.BOLD, new Color(255, 0, 0)));
                        //pImage.Add(new Chunk(" loc" + i.ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 12, Font.NORMAL, Color.WHITE)).SetLocalDestination(" loc" + i.ToString()));

                        string strFilePath = dtFilter.Rows[j]["FilePath"]..ToString();
                        int FileCount = strFilePath.IndexOf(';');
                        if (FileCount != -1)
                        {

                            string[] Files = strFilePath.Split(';');

                            foreach (string strFile in Files)
                            {




                                Paragraph pImage = new Paragraph(dtFilter..Rows[j]["BookMark"].ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 16, Font.BOLD, Color.WHITE));
                                string FilePath = strFile; //dtFilter.Rows[j]["FilePath"].ToString();
                                DataRow[] RowPageNo = dsTemp.Tables[0].Select("FilePath='" + FilePath + "'");
                                int intGoTo = Convert.ToInt32(RowPageNo[0]["PageNo"]);


                                //iTextSharp.text.Image imgDoc = iTextSharp.text.Image.GetInstance(FilePath);
                                //imgDoc.ScaleAbsolute(574F, 730F);
                                //pImage.Add(imgDoc);


                                //Section sec1 = sec2.AddSection(pImage);
                                //sec1.BookmarkTitle = dtFilter.Rows[j]["BookMark"].ToString();
                                PdfAction action3 = PdfAction.GotoLocalPage(intGoTo, new PdfDestination(PdfDestination.XYZ, -1, 10000, 0), pdfWriter);
                                PdfOutline ProviderChild = new PdfOutline(Providersum, action3, pImage);
                            }

                        }
                        else
                        {

                            DataRow[] RowPageNo = dsTemp.Tables[0].Select("FilePath='" + dtFilter.Rows[j]["FilePath"].ToString() + "'");

                            int intGoTo = Convert.ToInt32(RowPageNo[0]["PageNo"]);

                            Paragraph pImage = new Paragraph(dtFilter.Rows[j]["BookMark"].ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 16, Font.BOLD, Color.WHITE));
                            string FilePath = dtFilter.Rows[j]["FilePath"].ToString();
                            //iTextSharp.text.Image imgDoc = iTextSharp.text.Image.GetInstance(FilePath);
                            //imgDoc.ScaleAbsolute(574F, 730F);
                            //pImage.Add(imgDoc);


                            //Section sec1 = sec2.AddSection(pImage);
                            //sec1.BookmarkTitle = dtFilter.Rows[j]["BookMark"].ToString();

                            PdfAction action3 = PdfAction.GotoLocalPage(intGoTo, new PdfDestination(PdfDestination.XYZ, -1, 10000, 0), pdfWriter);
                            PdfOutline ProviderChild = new PdfOutline(Providersum, action3, pImage);



                        }




                    }


                    Paragraph cPar2 = new Paragraph("Administrat", chapterFont);
                    //Section sec3 = section1.AddSection(cPar2);
                    //sec3.BookmarkTitle = "Administrative Documents";
                    //sec3.BookmarkOpen = false;


                    for (int j = 0; j < dtFilter.Rows.Count; j++)
                    {



                        string strFilePath = dtFilter.Rows[j]["FilePath"]..ToString();
                        int FileCount = strFilePath.IndexOf(';');
                        if (FileCount != -1)
                        {

                            string[] Files = strFilePath.Split(';');

                            foreach (string strFile in Files)
                            {
                                Paragraph pImage = new Paragraph("", FontFactory.GetFont(FontFactory.HELVETICA, 16, Font.BOLD, Color.WHITE));
                                string FilePath = strFile;//dtFilter.Rows[j]["FilePath"].ToString();

                                DataRow[] RowPageNo = dsAdTemp.Tables[0].Select("FilePath='" + FilePath + "'");
                                int intGoTo = Convert.ToInt32(RowPageNo[0]["PageNo"]);


                                PdfAction action3 = PdfAction.GotoLocalPage(intGoTo, new PdfDestination(PdfDestination.XYZ, -1, 10000, 0), pdfWriter);
                                PdfOutline ProviderChild = new PdfOutline(ProviderAdm, action3, dtFilter.Rows[j]["BookMark"].ToString());

                                //Section sec1 = sec3.AddSection(pImage);
                                //sec1.BookmarkTitle = dtFilter.Rows[j]["BookMark"].ToString();
                            }
                        }
                        else
                        {



                            Paragraph pImage = new Paragraph("", FontFactory.GetFont(FontFactory.HELVETICA, 16, Font.BOLD, Color.WHITE));
                            string FilePath = dtFilter.Rows[j]["FilePath"].ToString();

                            DataRow[] RowPageNo = dsAdTemp.Tables[0].Select("FilePath='" + dtFilter.Rows[j]["FilePath"].ToString() + "'");
                            int intGoTo = Convert.ToInt32(RowPageNo[0]["PageNo"]);


                            PdfAction action3 = PdfAction.GotoLocalPage(intGoTo, new PdfDestination(PdfDestination.XYZ, -1, 10000, 0), pdfWriter);
                            PdfOutline ProviderChild = new PdfOutline(ProviderAdm, action3, dtFilter.Rows[j]["BookMark"].ToString());
                            //Section sec1 = sec3.AddSection(pImage);
                            //sec1.BookmarkTitle = dtFilter.Rows[j]["BookMark"].ToString();


                        }

                    }
                }

                ifAlreadyExist = false;
            }
            //Doc.Add(chpByProvider);

            #endregion


            #region Billing Summary and index





            Paragraph pBilling = new Paragraph("", chapterFont);
            // Chapter chpBilling = new Chapter(pBilling, 1);
            //Section chpBilling = chpRoot.AddSection("", 1);
            //chpBilling.BookmarkTitle = "Billing Index";
            //chpBilling.BookmarkOpen = false;
            int[] intBiPageNo = new int[objDataTable2.Rows.Count + 1];

            // intPageNo[0] = pdfWriter.CurrentPageNumber;
            DataSet dsBiTemp = new DataSet();
            DataTable TableBi = new DataTable();
            dsBiTemp.Tables.Add(TableBi);

            dsBiTemp.Tables[0].Columns.Add("PageNo", System.Type.GetType("System.String"));
            dsBiTemp.Tables[0].Columns.Add("FilePath", System.Type.GetType("System.String"));
            dsBiTemp.Tables[0].TableName = "Table";





            #region  Billing Outlines


            for (int i = 0; i < objDataTable6.Rows.Count; i++)
            {

                if (i == 0)
                {

                    intBiPageNo[0] = pdfWriter.CurrentPageNumber;

                }


                string strFilePath = objDataTable6.Rows[i]["BillingFilePath"].ToString();
                int FileCount = strFilePath.IndexOf(';');
                if (FileCount != -1)
                {

                    string[] Files = strFilePath.Split(';');

                    foreach (string strFile in Files)
                    {


                        Paragraph pImage = new Paragraph(objDataTable6.Rows[i]["BookMark"].ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 16, Font.BOLD, Color.WHITE));
                        pImage.Add(new Chunk(" loc" + i.ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 12, Font.NORMAL, Color.WHITE)).SetLocalDestination(" locB" + i.ToString()));
                        string FilePath = strFile;
                        DataRow myRow = dsBiTemp.Tables[0].NewRow();
                        myRow[0] = intBiPageNo[i].ToString();
                        myRow[1] = strFile;

                        dsBiTemp.Tables[0].Rows.Add(myRow);

                        intBiPageNo[i + 1] = intBiPageNo[i] + 1;

                        iTextSharp.text.Image imgDoc = iTextSharp.text.Image.GetInstance(FilePath);
                        imgDoc.ScaleAbsolute(574F, 700F);
                        pImage.Add(imgDoc);

                        //Section section1 = chpBilling.AddSection(pImage);
                        //section1.BookmarkTitle = objDataTable6.Rows[i]["BookMark"].ToString();
                        Doc.Add(pImage);

                    }
                }
                else
                {

                    Paragraph pImage = new Paragraph(objDataTable6.Rows[i]["BookMark"].ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 16, Font.BOLD, Color.WHITE));
                    pImage.Add(new Chunk(" loc" + i.ToString(), FontFactory..GetFont(FontFactory.HELVETICA, 12, Font.NORMAL, Color.WHITE)).SetLocalDestination(" locB" + i.ToString()));
                    string FilePath = objDataTable6.Rows[i]["BillingFilePath"].ToString();

                    DataRow myRow = dsBiTemp.Tables[0].NewRow();
                    myRow[0] = intBiPageNo[i].ToString();
                    myRow[1] = FilePath;
                    dsBiTemp.Tables[0].Rows.Add(myRow);
                    intBiPageNo[i + 1] = intBiPageNo[i] + 1;

                    iTextSharp.text.Image imgDoc = iTextSharp.text.Image.GetInstance(FilePath);
                    imgDoc.ScaleAbsolute(574F, 700F);
                    pImage.Add(imgDoc);

                    //Section section1 = chpBilling.AddSection(pImage);
                    //section1.BookmarkTitle = objDataTable6.Rows[i]["BookMark"].ToString();
                    Doc.Add(pImage);


                }
            }


            int intBilling = pdfWriter.CurrentPageNumber;
            PdfAction actionB = PdfAction.GotoLocalPage(intBilling, new PdfDestination(PdfDestination.XYZ, -1, 10000, 0), pdfWriter);
            PdfOutline BillingIndex = new PdfOutline(Patient, actionB, "Billing Index", false);


            for (int i = 0; i < objDataTable6.Rows.Count; i++)
            {




                string strFilePath = objDataTable6.Rows[i]["BillingFilePath"].ToString();
                int FileCount = strFilePath.IndexOf(';');
                if (FileCount != -1)
                {

                    string[] Files = strFilePath.Split(';');

                    foreach (string strFile in Files)
                    {


                        Paragraph pImage = new Paragraph("", FontFactory.GetFont(FontFactory.HELVETICA, 16, Font.BOLD, Color.WHITE));

                        string FilePath = strFile;
                        DataRow[] RowPageNo = dsBiTemp.Tables[0].Select("FilePath='" + FilePath + "'");
                        int intGoTo = Convert.ToInt32(RowPageNo[0]["PageNo"]);
                        PdfAction action3 = PdfAction.GotoLocalPage(intGoTo, new PdfDestination(PdfDestination.XYZ, -1, 10000, 0), pdfWriter);
                        PdfOutline ProviderChild = new PdfOutline(BillingIndex, action3, objDataTable6.Rows[i]["BookMark"].ToString(), false);


                    }
                }
                else
                {

                    Paragraph pImage = new Paragraph("", FontFactory.GetFont(FontFactory.HELVETICA, 16, Font.BOLD, Color.WHITE));
                    string FilePath = objDataTable6.Rows[i]["BillingFilePath"].ToString();
                    DataRow[] RowPageNo = dsBiTemp.Tables[0].Select("FilePath='" + FilePath + "'");
                    int intGoTo = Convert.ToInt32(RowPageNo[0]["PageNo"]);
                    PdfAction action3 = PdfAction.GotoLocalPage(intGoTo, new PdfDestination(PdfDestination.XYZ, -1, 10000, 0), pdfWriter);
                    PdfOutline ProviderChild = new PdfOutline(BillingIndex, action3, objDataTable6.Rows[i]["BookMark"].ToString(), false);


                }
            }


            #endregion
            //  Doc.Add(chpBilling);


            iTextSharp.text.Table grdTable3 = new iTextSharp.text.Table(8, objDataTable5.Rows.Count - 1);
            float[] fw = new float[] { 1F, 1F, 4F, 2.5F, 1F, 1F, 1F, 1F };
            grdTable3.Widths = fw;
            grdTable3.WidthPercentage = 100;
            grdTable3.DefaultCell.BorderColor = Color.BLACK;
            AddTableCell("DATE", grdTable3);
            AddTableCell("PAGE #", grdTable3);
            AddTableCell("PROVIDER", grdTable3);
            AddTableCell("DESCRIPTION", grdTable3);
            AddTableCell("CPT CODES", grdTable3);
            AddTableCell("ICD9 CODES", grdTable3);
            AddTableCell("TOTAL AMOUNT", grdTable3);
            AddTableCell("AMOUNT PAID", grdTable3);


            grdTable3.BorderWidth = 1; grdTable3.BorderColor = Color.BLACK;
            grdTable3.Cellpadding = 1; grdTable3.Cellspacing = 1;

            grdTable3.AutoFillEmptyCells = true;
            grdTable3.AutoFillEmptyCells = true;

            int intBillingIndex = pdfWriter.CurrentPageNumber;
            PdfAction actionBI = PdfAction.GotoLocalPage(intBillingIndex, new PdfDestination(PdfDestination.XYZ, -1, 10000, 0), pdfWriter);
            PdfOutline BillingSummary = new PdfOutline(Patient, actionBI, "Billing Summary", false);


            for (int i = 0; i < objDataTable5.Rows.Count; i++)
            {
                for (int j = 0; j < objDataTable5.Columns.Count; j++)
                {

                    Paragraph p1 = new Paragraph("", FontFactory.GetFont(FontFactory.HELVETICA, 8));
                    p1.Add(new Chunk(objDataTable5.Rows[i][j].ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.NORMAL, Color.BLACK)).SetLocalGoto(" locB" + i.ToString()));
                    grdTable3.AddCell(p1);

                    //grdTable3.AddCell(objDataTable5.Rows[i][j].ToString());
                    string strTotalAmt = objDataTable5.Columns[j].ColumnName;
                    //if (strTotalAmt == "TotalAmt")
                    //{
                    //    TotalAmt = Convert.ToSingle(objDataTable5.Rows[i][j].ToString() == "" ? "0" : objDataTable5.Rows[i][j].ToString()) + TotalAmt;
                    //}

                    //if(

                }

            }
            for (int j = 0; j < objDataTable5.Columns.Count; j++)
            {

                string strTotalAmt = objDataTable5.Columns[j].ColumnName;

                if (strTotalAmt != "TotalAmt")
                {
                    if (strTotalAmt != "AmountPaid")
                    {
                        if (strTotalAmt != "ICD9")
                        {

                            Paragraph pTotal = new Paragraph("", FontFactory.GetFont(FontFactory.HELVETICA, 8));
                            grdTable3.AddCell(pTotal);
                        }
                    }

                }




                if (strTotalAmt == "ICD9")
                {
                    Paragraph pTotal = new Paragraph("Total:", FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD));
                    grdTable3.AddCell(pTotal);
                }


                if (strTotalAmt == "TotalAmt")
                {
                    Paragraph pTotal = new Paragraph(objDataTable7.Rows[0][0].ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 8));
                    grdTable3.AddCell(pTotal);


                }
                strTotalAmt = objDataTable5.Columns[j].ColumnName;
                if (strTotalAmt == "AmountPaid")
                {
                    Paragraph pTotal = new Paragraph(objDataTable8.Rows[0][0].ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 8));
                    grdTable3.AddCell(pTotal);


                }



            }

            Paragraph PTable3 = new Paragraph("", FontFactory.GetFont(FontFactory.HELVETICA, 12));

            PTable3.Add(grdTable3);
            Doc.Add(PTable3);
            //Chapter chpBillingIndex = new Chapter(PTable3, 1);
            //Section chpBillingIndex = chpRoot.AddSection(PTable3, 1);
            //chpBillingIndex.BookmarkTitle = "Billing Summary";
            //Doc.Add(chpBillingIndex);

            MyHandler1 myEvents4 = new MyHandler1();
            Session["Footer"] = "Billing Summary ";
            pdfWriter.PageEvent = myEvents4;
            myEvents.OnEndPage(pdfWriter, Doc);

            #endregion




            Doc.Close(); Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment; filename=SwatiJain.pdf"); Response.End();
        }


        #region Page Methods
        public void AddTableCell(string CellName, iTextSharp.text.Table grdTable)
        {
            Cell c1 = new Cell(new Phrase(CellName, FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD)));


            c1.BackgroundColor = Color.WHITE;
            c1.Header = true; //c1.Colspan = 2;
            c1.HorizontalAlignment = Element.ALIGN_CENTER;
            c1.VerticalAlignment = Element.ALIGN_MIDDLE;
            c1.BorderColorBottom = Color.BLACK;
            c1.BorderColor = iTextSharp.text.Color.WHITE;
            grdTable.AddCell(c1);


        }
        #endregion
    }
}












Thanks & Regards,    Swati Jain


--- On Tue, 2/6/09, William Rickards <itext@...> wrote:

> From: William Rickards <itext@...>
> Subject: Re: [itextsharp-questions] Bookmarks
> To: "Post all your questions about iTextSharp here" <itextsharp-questions@...>
> Date: Tuesday, 2 June, 2009, 7:35 PM
> Not sure what you mean.
> You just change the page number, the first argument to
> GotoLocalPage.
>
> In my actual implementation, I'm keeping track of what I'm
> inserting
> into the document.
> So if I start a new page to start a new section, that is
> when I do
> m_docReport.NewPage(),
> I get the page number with m_wrtReport.CurrentPageNumber.
> Then I add the bookmark.
>
> Will Rickards
>
>
> On Tue, Jun 2, 2009 at 8:36 AM, swati jain <swatifordotnet@...>
> wrote:
> >
> > Hi William ,
> >
> > Hope you will reply
> >
> > PdfAction action =
> PdfAction.GotoLocalPage(intAdPageNo[0], new
> > PdfDestination(PdfDestination.XYZ, -1, 10000, 0),
> pdfWriter);
> > PdfOutline ProviderRoot = new PdfOutline(VisitIndex,
> action, "By Provider",
> > false);
> >
> > I need to change the action of the PdfOutline  to
> some other page, depending
> > on condition
> >
> > How i can do it?
> >
> > Pls reply
> >
> >
> >
> >
> > William Rickards wrote:
> >>
> >> This is VB.net code that I use to insert bookmarks
> that refer to specific
> >> pages.
> >> Just creating the outline objects creates the
> bookmarks.
> >> First you get a reference to the bookmark root,
> then you add
> >> hierarchical outline objects based on action
> objects.
> >>
> >> Let's say you have a pdfwriter object,
> m_wrtReport, and a contentbyte
> >> reference, m_objContentByte.
> >>
> >>       Dim objOutlineRoot As
> iTextSharp.text.pdf.PdfOutline
> >>       Dim objOutline As
> iTextSharp.text.pdf.PdfOutline
> >>       Dim objSubOutline As
> iTextSharp.text.pdf.PdfOutline
> >>       Dim objAction As
> iTextSharp.text.pdf.PdfAction
> >>
> >>             ' get bookmarks root
> >>             objOutlineRoot =
> m_objContentByte.RootOutline
> >>
> >>             ' add page 1 bookmark
> >>             objAction =
> iTextSharp.text.pdf.PdfAction.GotoLocalPage(1,
> >> New
> >>
> iTextSharp.text.pdf.PdfDestination(iTextSharp.text.pdf.PdfDestination.FITH),
> >> m_wrtReport)
> >>             objOutline = New
> >> iTextSharp.text.pdf.PdfOutline(objOutlineRoot,
> objAction, "Page 1")
> >>
> >>             ' now add suboutlines for page 2
> and 3
> >>             objAction =
> iTextSharp.text.pdf.PdfAction.GotoLocalPage(2,
> >> New
> >>
> iTextSharp.text.pdf.PdfDestination(iTextSharp.text.pdf.PdfDestination.FITH),
> >> m_wrtReport)
> >>             objSubOutline = New
> >> iTextSharp.text.pdf.PdfOutline(objOutline,
> objAction, "Page 2")
> >>
> >>             objAction =
> iTextSharp.text.pdf.PdfAction.GotoLocalPage(3,
> >> New
> >>
> iTextSharp.text.pdf.PdfDestination(iTextSharp.text.pdf.PdfDestination.FITH),
> >> m_wrtReport)
> >>             objSubOutline = New
> >> iTextSharp.text.pdf.PdfOutline(objOutline,
> objAction, "Page 3")
> >>
> >>             ' add page 4 bookmark
> >>             objAction =
> iTextSharp.text.pdf.PdfAction.GotoLocalPage(4,
> >> New
> >>
> iTextSharp.text.pdf.PdfDestination(iTextSharp.text.pdf.PdfDestination.FITH),
> >> m_wrtReport)
> >>             objOutline = New
> >> iTextSharp.text.pdf.PdfOutline(objOutlineRoot,
> objAction, "Page 4")
> >>
> >>             ' now add suboutlines for page
> 5
> >>             objAction =
> iTextSharp.text.pdf.PdfAction.GotoLocalPage(5,
> >> New
> >>
> iTextSharp.text.pdf.PdfDestination(iTextSharp.text.pdf.PdfDestination.FITH),
> >> m_wrtReport)
> >>             objSubOutline = New
> >> iTextSharp.text.pdf.PdfOutline(objOutline,
> objAction, "Page 5")
> >>
> >>
> >> Will Rickards
> >>
> >>
> >>
> >> On Wed, Apr 22, 2009 at 9:55 AM, johntheface
> <lace.john@...>
> >> wrote:
> >>>
> >>> I have an app that creates a PDF document
> using iTextSharp. After the
> >>> document has been created I need to add
> bookmarks to it. I don't want to
> >>> add
> >>> any extra pages I just want bookmarks that
> will take to user to a certain
> >>> page when they click on it. I have found lots
> of examples online but I
> >>> haven't been able to get it working. I'm aware
> I'm supposed to use the
> >>> PdfOutline object but I've been trying
> different examples for days and
> >>> can't
> >>> get it working. Just to get me started could
> someone tell me how to add a
> >>> bookmark structure to an existing PDF document
> without adding any extra
> >>> pages. eg the following structure for a 5 page
> document:
> >>>
> >>> |---Page 1
> >>> |      |
> >>> |      --- Page 2
> >>> |      |
> >>> |      --- Page 3
> >>> |
> >>> |---Page 4
> >>> |      |
> >>>       --- Page 5
> >>>
> >>> Thanks in advance
> >>> --
> >>> View this message in context:
> >>> http://www.nabble.com/Bookmarks-tp23175463p23175463.html
> >>> Sent from the itextsharp-questions mailing
> list archive at Nabble.com.
> >>>
> >>>
> >>>
> ------------------------------------------------------------------------------
> >>> Stay on top of everything new and different,
> both inside and
> >>> around Java (TM) technology - register by
> April 22, and save
> >>> $200 on the JavaOne (SM) conference, June 2-5,
> 2009, San Francisco.
> >>> 300 plus technical and hands-on sessions.
> Register today.
> >>> Use priority code J9JMT32. http://p.sf.net/sfu/p
> >>>
> _______________________________________________
> >>> itextsharp-questions mailing list
> >>> itextsharp-questions@...
> >>> https://lists.sourceforge.net/lists/listinfo/itextsharp-questions
> >>>
> >>
> >>
> ------------------------------------------------------------------------------
> >> Stay on top of everything new and different, both
> inside and
> >> around Java (TM) technology - register by April
> 22, and save
> >> $200 on the JavaOne (SM) conference, June 2-5,
> 2009, San Francisco.
> >> 300 plus technical and hands-on sessions. Register
> today.
> >> Use priority code J9JMT32. http://p.sf.net/sfu/p
> >> _______________________________________________
> >> itextsharp-questions mailing list
> >> itextsharp-questions@...
> >> https://lists.sourceforge.net/lists/listinfo/itextsharp-questions
> >>
> >>
> >
> > --
> > View this message in context: http://www.nabble.com/Bookmarks-tp23175463p23831704.html
> > Sent from the itextsharp-questions mailing list
> archive at Nabble.com.
> >
> >
> >
> ------------------------------------------------------------------------------
> > OpenSolaris 2009.06 is a cutting edge operating system
> for enterprises
> > looking to deploy the next generation of Solaris that
> includes the latest
> > innovations from Sun and the OpenSource community.
> Download a copy and
> > enjoy capabilities such as Networking, Storage and
> Virtualization.
> > Go to: http://p.sf.net/sfu/opensolaris-get
> > _______________________________________________
> > itextsharp-questions mailing list
> > itextsharp-questions@...
> > https://lists.sourceforge.net/lists/listinfo/itextsharp-questions
> >
>
> ------------------------------------------------------------------------------
> OpenSolaris 2009.06 is a cutting edge operating system for
> enterprises
> looking to deploy the next generation of Solaris that
> includes the latest
> innovations from Sun and the OpenSource community. Download
> a copy and
> enjoy capabilities such as Networking, Storage and
> Virtualization.
> Go to: http://p.sf.net/sfu/opensolaris-get
> _______________________________________________
> itextsharp-questions mailing list
> itextsharp-questions@...
> https://lists.sourceforge.net/lists/listinfo/itextsharp-questions
>


      Explore and discover exciting holidays and getaways with Yahoo! India Travel http://in.travel.yahoo.com/


------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises
looking to deploy the next generation of Solaris that includes the latest
innovations from Sun and the OpenSource community. Download a copy and
enjoy capabilities such as Networking, Storage and Virtualization.
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
itextsharp-questions mailing list
itextsharp-questions@...
https://lists.sourceforge.net/lists/listinfo/itextsharp-questions

Re: The page 2 was requested but the document has only 1 pages.

by William Rickards :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Are you getting that error on a specific line when you generate the
pdf?  Or in the generated pdf when you click on a bookmark?  You need
to narrow the code down you need looked at.

Will Rickards

------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises
looking to deploy the next generation of Solaris that includes the latest
innovations from Sun and the OpenSource community. Download a copy and
enjoy capabilities such as Networking, Storage and Virtualization.
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
itextsharp-questions mailing list
itextsharp-questions@...
https://lists.sourceforge.net/lists/listinfo/itextsharp-questions