Kavi suja

Kavi suja

  • NA
  • 298
  • 167.6k

PDFwriter -PushButton-perform action "Back to previous page"

Sep 10 2013 9:39 AM
Hi,
  I have registration page. I generate PDF using button click. It generates PDF. Now, the problem is, after generate in to PDF, if I want to go to Previous page then I use browser back button. I want to use seperate button in PDF which performs "back to previous page option". I'm not identify how to do this? I search about PushButton inPDF files. But using this how i perform the action . Can anyone help me to do this? I include my  code here.

 protected void btnUpload_Click(object sender, EventArgs e)
        {
            Document pdfDoc = new Document(PageSize.A4, 10, 10, 10, 10);

            try
            {
                PdfWriter.GetInstance(pdfDoc, System.Web.HttpContext.Current.Response.OutputStream);
                pdfDoc.Open();

                //Set Font Properties for PDF File
                Font fnt = FontFactory.GetFont("Times New Roman", 14);

                PdfPTable PdfTable = new PdfPTable(1);
                //PdfPCell PdfPCell = null;

                //Retrieve content from design side
                string pntype = "Patient Type  : ";
                string ptype = ddlpatienttype.SelectedItem.Text;
                PdfPCell ptypeval = new PdfPCell(new Phrase(new Chunk(pntype + ptype)));
                PdfTable.AddCell(ptypeval);

                string pnamel = "Name : ";
                string pnamet = "";
                if (rdbtnmr.Checked == true)
                {
                    pnamet = lblsalutmr.Text + " " + txtPFirstName.Text + " " + txtPMiddleName.Text + " " + txtPLastName.Text;
                }
                else if (rdbtnms.Checked == true)
                {
                    pnamet = lblsalutms.Text + " " + txtPFirstName.Text + " " + txtPMiddleName.Text + " " + txtPLastName.Text;
                }
                else
                //if (rdbtnmrs.Checked == true)
                {
                    pnamet = lblsalutmrs.Text + " " + txtPFirstName.Text + " " + txtPMiddleName.Text + " " + txtPLastName.Text;
                }
               
                PdfPCell pnameval = new PdfPCell(new Phrase(new Chunk(pnamel + pnamet)));
                PdfTable.AddCell(pnameval);

                string pdobl = "DOB : ";
                string pdobt = ddlMonth.SelectedItem.Text + "/" + txtDateOfBirth.Text + "/" + txtBDayYear.Text;
                PdfPCell pdobval = new PdfPCell(new Phrase(new Chunk(pdobl + pdobt)));
                PdfTable.AddCell(pdobval);

                string pgenderl = "Gender : ";
                string pgenderrad = "";
                if (rdbtnmale.Checked == true)
                {
                    pgenderrad = lblmale.Text;
                }
                else if (rdbtnfemale.Checked == true)
                {
                    pgenderrad = lblfemale.Text;
                }
                //string pgenderrad = ddlGender.SelectedItem.Text;
                PdfPCell pgenderval = new PdfPCell(new Phrase(new Chunk(pgenderl + pgenderrad)));
                PdfTable.AddCell(pgenderval);

                string pdoct = "Doctor : ";
                string pdoctdrop = ddlConsultingDoc.SelectedItem.Text;
                PdfPCell pdoctval = new PdfPCell(new Phrase(new Chunk(pdoct + pdoctdrop)));
                PdfTable.AddCell(pdoctval);

                string pAddresstype = "Address Type : ";
                string pAddressDrop = ddladdresstype.SelectedItem.Text;
                PdfPCell pAddressval = new PdfPCell(new Phrase(new Chunk(pAddresstype + pAddressDrop)));
                PdfTable.AddCell(pAddressval);

                string pAddressline1 = "Address Line1 : ";
                string pAddresstext = txtaddressline1.Text;
                PdfPCell pAddressline1val = new PdfPCell(new Phrase(new Chunk(pAddressline1 + pAddresstext)));
                PdfTable.AddCell(pAddressline1val);

                string pAddressline2 = "Address Line2 : ";
                string pAddresstext2 = txtaddressline2.Text;
                PdfPCell pAddressline2val = new PdfPCell(new Phrase(new Chunk(pAddressline2 + pAddresstext2)));
                PdfTable.AddCell(pAddressline2val);

                string pAddressline3 = "Address Line3 : ";
                string pAddresstext3 = txtaddressline3.Text;
                PdfPCell pAddressline3val = new PdfPCell(new Phrase(new Chunk(pAddressline3 + pAddresstext3)));
                PdfTable.AddCell(pAddressline3val);

                string pcity = "City : ";
                string pcitytext = txtcity.Text;
                PdfPCell pcitytextval = new PdfPCell(new Phrase(new Chunk(pcity + pcitytext)));
                PdfTable.AddCell(pcitytextval);

                string ppostalcode = "Postal Code : ";
                string pposttext = txtpostalcode.Text;
                PdfPCell pposttextval = new PdfPCell(new Phrase(new Chunk(ppostalcode + pposttext)));
                PdfTable.AddCell(pposttextval);

                string pcountry = "Country : ";
                string pcountrytext = txtcountry.Text;
                PdfPCell pcountrytextval = new PdfPCell(new Phrase(new Chunk(pcountry + pcountrytext)));
                PdfTable.AddCell(pcountrytextval);

               
                

               

                

                string pgname = "Guardian Name : ";
                string pgnametext = "";
                if (rbsalmr.Checked == true)
                {
                    pgnametext = lblsalmr.Text + " " + txtGFirstName.Text + " " + txtgmiddlename.Text + " " + txtGLastName.Text;
                }
                else if (rbsalms.Checked == true)
                {
                    pgnametext = lblsalms.Text + " " + txtGFirstName.Text + " " + txtgmiddlename.Text + " " + txtGLastName.Text;
                }
                else
                {
                    pgnametext = lblsalmrs.Text + " " + txtGFirstName.Text + " " + txtgmiddlename.Text + " " + txtGLastName.Text;
                }
              
                PdfPCell pgnametextval = new PdfPCell(new Phrase(new Chunk(pgname + pgnametext)));
                PdfTable.AddCell(pgnametextval);

                string pRelationshipname = "RelationShip : ";
                string pRelationshiptext = ddlRelationShip.SelectedItem.Text;
                PdfPCell pRelationshiptextval = new PdfPCell(new Phrase(new Chunk(pRelationshipname + pRelationshiptext)));
                PdfTable.AddCell(pRelationshiptextval);

                string pgdobl = "DOB : ";
                string pgdobt = ddlGMonth.SelectedItem.Text + "/" + txtGDate.Text + "/" + txtGYear.Text;
                PdfPCell pgdobval = new PdfPCell(new Phrase(new Chunk(pgdobl + pgdobt)));
                PdfTable.AddCell(pgdobval);

                string pggenderl = "Gender : ";
                string pggenderrad = "";
                if (rbmale.Checked == true)
                {
                    pggenderrad = lblgmale.Text;
                }
                else
                {
                    pggenderrad = lblgfemale.Text;
                }
            
                PdfPCell pggenderval = new PdfPCell(new Phrase(new Chunk(pggenderl + pggenderrad)));
                PdfTable.AddCell(pggenderval);


                pdfDoc.Add(PdfTable);
                pdfDoc.Close();
                Response.ContentType = "application/pdf";

                System.Web.HttpContext.Current.Response.Write(pdfDoc);

                Response.Flush();
                Response.End();

            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
            }
        }