예제 #1
0
        private void InvoiceReport()
        {
            int    lastInsertedBillNo = billManager.LastInsertedBillNo();
            string name = patientNameTextBox.Text;

            LoadGridData();

            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("<table width = '100%' cellspacing='0' cellpadding ='2'");
            stringBuilder.Append("<tr><td align = 'centre'>Bill No.</td>");
            stringBuilder.Append("<td>");
            stringBuilder.Append(lastInsertedBillNo);
            stringBuilder.Append("</td></tr>");
            stringBuilder.Append("<tr><td align = 'centre'>Patient</td>");
            stringBuilder.Append("<td>");
            stringBuilder.Append(name);
            stringBuilder.Append("</td></tr></table>");

            StringReader strReader = new StringReader(stringBuilder.ToString());

            PdfPTable pdfTable = new PdfPTable(testEntryGridView.HeaderRow.Cells.Count);

            foreach (TableCell headerCell in testEntryGridView.HeaderRow.Cells)
            {
                PdfPCell tableCell = new PdfPCell(new Phrase(headerCell.Text));
                pdfTable.AddCell(tableCell);
            }

            foreach (GridViewRow gridViewRow in testEntryGridView.Rows)
            {
                foreach (TableCell tableCell in gridViewRow.Cells)
                {
                    PdfPCell pdfCell = new PdfPCell(new Phrase(tableCell.Text));
                    pdfTable.AddCell(pdfCell);
                }
            }

            Document   pdfDocument = new Document(PageSize.A4, 10f, 10f, 10f, 10f);
            HTMLWorker htmlPerser  = new HTMLWorker(pdfDocument);

            PdfWriter.GetInstance(pdfDocument, Response.OutputStream);

            pdfDocument.Open();
            htmlPerser.Parse(strReader);
            pdfDocument.Add(pdfTable);
            pdfDocument.Close();

            Response.ContentType = "application/pdf";
            Response.AppendHeader("content-disposition", "attachment;filename=Test.pdf");
            Response.Write(pdfDocument);
            Response.Flush();
            Response.End();
        }