示例#1
0
        protected void btnGetPdf_Click(object sender, EventArgs e)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                Paragraph            paragraph;
                iTextSharp.text.Font fdefault = FontFactory.GetFont("Arial", 17, iTextSharp.text.Font.NORMAL, BaseColor.BLUE);
                Document             doc      = new Document(PageSize.A4);
                try
                {
                    var writer = PdfWriter.GetInstance(doc, ms);
                    doc.Open();


                    var logo = iTextSharp.text.Image.GetInstance(Server.MapPath("~/Images/logoBGSB.jpg"));
                    logo.SetAbsolutePosition(50, 730);
                    logo.ScaleAbsoluteHeight(75);
                    logo.ScaleAbsoluteWidth(70);
                    doc.Add(logo);


                    string SoET = "School of Engineering Technology";
                    paragraph = new Paragraph(SoET, fdefault);
                    paragraph.IndentationLeft = 150;
                    paragraph.SpacingAfter    = 10;
                    doc.Add(paragraph);

                    string Bgsbu = "Baba Ghulam Shah Badshah University";
                    paragraph = new Paragraph(Bgsbu, fdefault);
                    paragraph.IndentationLeft = 135;
                    paragraph.SpacingAfter    = 10;
                    paragraph.SpacingBefore   = -10;
                    doc.Add(paragraph);


                    string Rjri = "Rajouri, Jammu and Kashmir (185234).";
                    paragraph = new Paragraph(Rjri, fdefault);
                    paragraph.IndentationLeft = 137;
                    paragraph.SpacingAfter    = 10;
                    paragraph.SpacingBefore   = -10;
                    doc.Add(paragraph);

                    Paragraph LineSeparator = new Paragraph(new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100.0F, BaseColor.BLACK, Element.ALIGN_LEFT, 1)));

                    paragraph.SpacingAfter = 60;

                    doc.Add(LineSeparator);


                    PdfPTable table2 = new PdfPTable(2);
                    table2.SpacingBefore   = 20;
                    table2.WidthPercentage = 80;
                    table2.SpacingAfter    = 10;

                    PdfPCell cell1 = new PdfPCell();
                    cell1.AddElement(new Paragraph("Fee Reciept", FontFactory.GetFont("Arial", 12, Font.NORMAL)));
                    cell1.VerticalAlignment = Element.ALIGN_CENTER;

                    PdfPCell cell2 = new PdfPCell();
                    cell2.AddElement(new Paragraph("Student Copy", FontFactory.GetFont("Arial", 12, Font.NORMAL)));
                    cell1.VerticalAlignment = Element.ALIGN_CENTER;

                    table2.AddCell(cell1);
                    table2.AddCell(cell2);

                    doc.Add(table2);

                    Paragraph LineSeparator3 = new Paragraph(new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100.0F, BaseColor.BLACK, Element.ALIGN_LEFT, 1)));

                    paragraph.SpacingAfter = 60;
                    doc.Add(LineSeparator3);


                    PdfPTable table1 = new PdfPTable(2);

                    table1.WidthPercentage = 90;
                    table1.SpacingBefore   = 40;



                    PdfPCell cell11 = new PdfPCell();

                    cell11.AddElement(new Paragraph("Name : " + lblSttudentName.Text));

                    cell11.AddElement(new Paragraph("Department : " + lblDepartmentName.Text));

                    cell11.AddElement(new Paragraph("Roll no : " + lblRollno.Text));

                    cell11.AddElement(new Paragraph("Semester : " + ddlSemester.Text));

                    cell11.VerticalAlignment = Element.ALIGN_LEFT;

                    PdfPCell cell12 = new PdfPCell();

                    cell12.AddElement(new Paragraph("Reciept no : " + lbltemp3.Text));

                    cell12.AddElement(new Paragraph("Date Paid : " + lblDatePaid.Text));

                    cell12.AddElement(new Paragraph("Session : " + ddlSessionName.Text));



                    cell12.VerticalAlignment = Element.ALIGN_RIGHT;

                    table1.SpacingAfter = 18;

                    table1.AddCell(cell11);

                    table1.AddCell(cell12);
                    doc.Add(table1);



                    paragraph = new Paragraph("Recieved with thanks a sum of rupees " + lblAmount.Text + "( " + ConvertCurrency.ConvertNumbertoWords((long)Convert.ToDouble(lblAmount.Text)) + " )" + " from " + lblSttudentName.Text + " on account of " + ddlFeeType.Text + ".");
                    paragraph.IndentationLeft = 30f;
                    paragraph.SpacingBefore   = 20;
                    paragraph.SpacingAfter    = 30;
                    doc.Add(paragraph);

                    Paragraph LineSeparator5 = new Paragraph(new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100.0F, BaseColor.BLACK, Element.ALIGN_LEFT, 1)));

                    paragraph.SpacingAfter = 1;
                    Paragraph LineSeparator6 = new Paragraph(new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(0.0F, 70.0F, BaseColor.BLACK, Element.ALIGN_CENTER, 1)));

                    paragraph.SpacingAfter = 1;
                    Paragraph LineSeparator7 = new Paragraph(new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(0.0F, 40.0F, BaseColor.BLACK, Element.ALIGN_CENTER, 1)));

                    paragraph.SpacingAfter = 60;
                    doc.Add(LineSeparator5);
                    doc.Add(LineSeparator6);
                    doc.Add(LineSeparator7);

                    // paragraph = new Paragraph("tution fee" + lblAmount.Text);
                    //paragraph.IndentationLeft = 100f;
                    //paragraph.SpacingAfter = 30;
                    //doc.Add(paragraph);



                    doc.Close();
                    Response.ContentType = "pdf/application";
                    Response.AddHeader("content-disposition", "attachment;filename= " + ddlFeeType.Text + "-" + ddlSemester.Text + "-" + ddlSessionName.Text + ".pdf");
                    Response.OutputStream.Write(ms.GetBuffer(), 0, ms.GetBuffer().Length);


                    //////////
                }
                catch (Exception)
                {
                }
            }
        }