//document header private void AddDocHeader() { try { Table bankTransferTable = new Table(5); bankTransferTable.WidthPercentage = 100; bankTransferTable.Padding = 1; bankTransferTable.Spacing = 1; bankTransferTable.Border = Table.NO_BORDER; Cell employernameCell = new Cell(new Phrase(_ViewModel.employername.ToUpper(), new Font(Font.TIMES_ROMAN, 12, Font.BOLD | Font.UNDERLINE, Color.BLACK))); employernameCell.HorizontalAlignment = Cell.ALIGN_CENTER; employernameCell.Colspan = 5; employernameCell.Border = Cell.NO_BORDER; bankTransferTable.AddCell(employernameCell); Cell employeraddressCell = new Cell(new Phrase(_ViewModel.employeraddress, new Font(Font.TIMES_ROMAN, 10, Font.BOLD | Font.UNDERLINE, Color.BLACK))); employeraddressCell.HorizontalAlignment = Cell.ALIGN_CENTER; employeraddressCell.Colspan = 5; employeraddressCell.Border = Cell.NO_BORDER; bankTransferTable.AddCell(employeraddressCell); Cell reportNameCell = new Cell(new Phrase(_ViewModel.ReportName, hFont1)); reportNameCell.HorizontalAlignment = Cell.ALIGN_CENTER; reportNameCell.Colspan = 5; reportNameCell.Border = Cell.NO_BORDER; bankTransferTable.AddCell(reportNameCell); Cell reportdateCell = new Cell(new Phrase("Print Date: " + _ViewModel.PrintedOn.ToString("dd-dddd-MMMM-yyyy"), tHfont1)); reportdateCell.HorizontalAlignment = Cell.ALIGN_LEFT; reportdateCell.Colspan = 4; reportdateCell.Border = Cell.NO_BORDER; bankTransferTable.AddCell(reportdateCell); //create the logo PDFGen pdfgen = new PDFGen(); Image img0 = pdfgen.DoGetImageFile(_ViewModel.CompanyLogo); img0.Alignment = Image.ALIGN_MIDDLE; Cell logoCell = new Cell(img0); logoCell.HorizontalAlignment = Cell.ALIGN_LEFT; logoCell.Border = Cell.NO_BORDER; logoCell.Add(new Phrase(_ViewModel.CompanySlogan, new Font(Font.HELVETICA, 8, Font.ITALIC, Color.BLACK))); bankTransferTable.AddCell(logoCell); } catch (Exception ex) { Utils.ShowError(ex); } }
private void AddDocHeader() { PDFGen pdfgen = new PDFGen(); Image img0 = pdfgen.DoGetImageFile(_resourcePath + "kra2.jpg"); img0.Alignment = Image.ALIGN_CENTER; Table empInfoTable = new Table(3, 4); empInfoTable.WidthPercentage = 100; empInfoTable.Border = Table.NO_BORDER; Phrase header1 = new Phrase(_ViewModel.ReportName, hFont2); Cell c2 = new Cell(header1); c2.Border = Cell.NO_BORDER; c2.HorizontalAlignment = Cell.ALIGN_CENTER; // c1.Colspan = 3; empInfoTable.AddCell(c2, new System.Drawing.Point(1, 1)); // Phrase header1 = new Phrase(_ViewModel.ReportName, hFont2); Cell c1 = new Cell(img0);// header1); c1.Border = Cell.NO_BORDER; c1.HorizontalAlignment = Cell.ALIGN_CENTER; // c1.Colspan = 3; empInfoTable.AddCell(c1, new System.Drawing.Point(0, 1)); Chunk employerName = new Chunk("Employers Name ..." + _ViewModel.EmployerName.ToUpper().Trim() + "..", bFont1); Cell empCell = new Cell(employerName); empCell.Border = Cell.NO_BORDER; empInfoTable.AddCell(empCell, new System.Drawing.Point(2, 0)); Chunk employerPIN = new Chunk("Employer's PIN ..." + _ViewModel.EmployerPin.Trim() + "..", bFont1); Cell empPINCell = new Cell(employerPIN); empPINCell.Border = Cell.NO_BORDER; empInfoTable.AddCell(empPINCell, new System.Drawing.Point(2, 2)); Chunk employeeName = new Chunk("Employee’s Main Name………" + _ViewModel.EmployeeMainName.Trim() + "……....", bFont1); Cell empNameCell = new Cell(employeeName); empNameCell.Border = Cell.NO_BORDER; empInfoTable.AddCell(empNameCell, new System.Drawing.Point(3, 0)); Chunk employeeOName = new Chunk("Employee’s Other Names……" + _ViewModel.EmployeeOtherNames.Trim() + "……....", bFont1); Cell empeONameCell = new Cell(employeeOName); empeONameCell.Border = Cell.NO_BORDER; empInfoTable.AddCell(empeONameCell, new System.Drawing.Point(4, 0)); Chunk employeePIN = new Chunk("Employee’s PIN…………………" + _ViewModel.EmployeePin.Trim() + "………....", bFont1); Cell empePINCell = new Cell(employeePIN); empePINCell.Border = Cell.NO_BORDER; empInfoTable.AddCell(empePINCell, new System.Drawing.Point(4, 2)); document.Add(empInfoTable); document.Add(new Phrase("", new Font(Font.TIMES_ROMAN, 2, Font.NORMAL))); }
//document header private void AddDocHeader() { Table nssfTable = new Table(5); nssfTable.WidthPercentage = 100; nssfTable.Padding = 1; nssfTable.Spacing = 1; nssfTable.Border = Table.NO_BORDER; Cell EmployerNameCell = new Cell(new Phrase(_ViewModel.EmployerName.ToUpper() + "\n", new Font(Font.TIMES_ROMAN, 15, Font.BOLD | Font.UNDERLINE, Color.BLACK))); EmployerNameCell.HorizontalAlignment = Cell.ALIGN_CENTER; EmployerNameCell.Colspan = 5; EmployerNameCell.Border = Cell.NO_BORDER; nssfTable.AddCell(EmployerNameCell); Cell employerAdressCell = new Cell(new Phrase(_ViewModel.EmpAddress, new Font(Font.TIMES_ROMAN, 9, Font.BOLD | Font.UNDERLINE, Color.BLACK))); employerAdressCell.HorizontalAlignment = Cell.ALIGN_CENTER; employerAdressCell.Colspan = 5; employerAdressCell.Border = Cell.NO_BORDER; nssfTable.AddCell(employerAdressCell); Cell bCell = new Cell(new Phrase("NSSF", hFont1)); bCell.HorizontalAlignment = Cell.ALIGN_CENTER; bCell.Colspan = 5; bCell.Border = Cell.NO_BORDER; nssfTable.AddCell(bCell); Cell reportNameCell = new Cell(new Phrase(_ViewModel.ReportName, hFont2)); reportNameCell.HorizontalAlignment = Cell.ALIGN_CENTER; reportNameCell.Colspan = 5; reportNameCell.Border = Cell.NO_BORDER; nssfTable.AddCell(reportNameCell); Cell employerNSSFCell = new Cell(new Phrase("NSSF No: " + _ViewModel.EmployerCode.Trim(), hFont2)); employerNSSFCell.HorizontalAlignment = Cell.ALIGN_CENTER; employerNSSFCell.Border = Cell.NO_BORDER; employerNSSFCell.Colspan = 5; nssfTable.AddCell(employerNSSFCell); Cell PrintedonCell = new Cell(new Phrase("Printed on: " + _ViewModel.PrintedOn.ToString("dd-dddd-MMMM-yyyy"), hFont2)); PrintedonCell.HorizontalAlignment = Cell.ALIGN_LEFT; PrintedonCell.Colspan = 4; PrintedonCell.Border = Cell.NO_BORDER; nssfTable.AddCell(PrintedonCell); //create the logo PDFGen pdfgen = new PDFGen(); Image img0 = pdfgen.DoGetImageFile(_ViewModel.CompanyLogo); img0.Alignment = Image.ALIGN_MIDDLE; Cell logoCell = new Cell(img0); logoCell.HorizontalAlignment = Cell.ALIGN_LEFT; logoCell.Border = Cell.NO_BORDER; logoCell.Add(new Phrase(_ViewModel.CompanySlogan, new Font(Font.HELVETICA, 8, Font.ITALIC, Color.BLACK))); nssfTable.AddCell(logoCell); document.Add(nssfTable); }
//document header private void AddDocHeader() { Table bankTransferTable = new Table(5); bankTransferTable.WidthPercentage = 100; bankTransferTable.Padding = 1; bankTransferTable.Spacing = 1; bankTransferTable.Border = Table.NO_BORDER; Cell employernameCell = new Cell(new Phrase(_ViewModel.employername.ToUpper(), new Font(Font.TIMES_ROMAN, 12, Font.BOLD | Font.UNDERLINE, Color.BLACK))); employernameCell.HorizontalAlignment = Cell.ALIGN_CENTER; employernameCell.Colspan = 5; employernameCell.Border = Cell.NO_BORDER; bankTransferTable.AddCell(employernameCell); Cell employeraddressCell = new Cell(new Phrase(_ViewModel.employeraddress, new Font(Font.TIMES_ROMAN, 10, Font.BOLD | Font.UNDERLINE, Color.BLACK))); employeraddressCell.HorizontalAlignment = Cell.ALIGN_CENTER; employeraddressCell.Colspan = 5; employeraddressCell.Border = Cell.NO_BORDER; bankTransferTable.AddCell(employeraddressCell); Cell reportNameCell = new Cell(new Phrase(_ViewModel.ReportName, hFont1)); reportNameCell.HorizontalAlignment = Cell.ALIGN_CENTER; reportNameCell.Colspan = 5; reportNameCell.Border = Cell.NO_BORDER; bankTransferTable.AddCell(reportNameCell); StringBuilder sb = new StringBuilder(); sb.AppendLine("The Manager"); sb.AppendLine(_ViewModel.Bank); sb.AppendLine(_ViewModel.BankBranch); Cell salutationCell = new Cell(new Chunk(sb.ToString(), hfont2)); salutationCell.Border = Cell.NO_BORDER; salutationCell.HorizontalAlignment = Cell.ALIGN_LEFT; salutationCell.Colspan = 5; bankTransferTable.AddCell(salutationCell); Cell reportdateCell = new Cell(new Phrase("Print Date: " + _ViewModel.PrintedOn.ToString("dd-dddd-MMMM-yyyy"), tHfont1)); reportdateCell.HorizontalAlignment = Cell.ALIGN_LEFT; reportdateCell.Colspan = 4; reportdateCell.Border = Cell.NO_BORDER; bankTransferTable.AddCell(reportdateCell); //create the logo PDFGen pdfgen = new PDFGen(); Image img0 = pdfgen.DoGetImageFile(_ViewModel.CompanyLogo); img0.Alignment = Image.ALIGN_MIDDLE; Cell logoCell = new Cell(img0); logoCell.HorizontalAlignment = Cell.ALIGN_LEFT; logoCell.Border = Cell.NO_BORDER; logoCell.Add(new Phrase(_ViewModel.CompanySlogan, new Font(Font.HELVETICA, 8, Font.ITALIC, Color.BLACK))); bankTransferTable.AddCell(logoCell); document.Add(bankTransferTable); document.Add(new Phrase("\n\nDear Sir/Madam", new Font(Font.TIMES_ROMAN, 8, Font.NORMAL))); document.Add(new Phrase("\nRE: CREDIT TRANSFER - SALARY PROCESSING", new Font(Font.TIMES_ROMAN, 8, Font.BOLD | Font.UNDERLINE))); document.Add(new Phrase("\n\nBelow is a list of Names, Banks, Branches, Account and Amounts to be credited in their respective Accounts", new Font(Font.TIMES_ROMAN, 8, Font.NORMAL))); }
//document header private void AddDocHeader() { Table statementInfoTable = new Table(5); statementInfoTable.WidthPercentage = 100; statementInfoTable.Padding = 1; statementInfoTable.Spacing = 1; statementInfoTable.Border = Table.NO_BORDER; Cell employernameCell = new Cell(new Phrase(_ViewModel.employername.ToUpper(), new Font(Font.TIMES_ROMAN, 12, Font.BOLD | Font.UNDERLINE, Color.BLACK))); employernameCell.HorizontalAlignment = Cell.ALIGN_CENTER; employernameCell.Colspan = 5; employernameCell.Border = Cell.NO_BORDER; statementInfoTable.AddCell(employernameCell); Cell employeraddressCell = new Cell(new Phrase(_ViewModel.employeraddress, new Font(Font.TIMES_ROMAN, 10, Font.BOLD | Font.UNDERLINE, Color.BLACK))); employeraddressCell.HorizontalAlignment = Cell.ALIGN_CENTER; employeraddressCell.Colspan = 5; employeraddressCell.Border = Cell.NO_BORDER; statementInfoTable.AddCell(employeraddressCell); Cell bCell = new Cell(new Phrase("SCHEDULE FOR:", hFont1)); bCell.HorizontalAlignment = Cell.ALIGN_CENTER; bCell.Colspan = 5; bCell.Border = Cell.NO_BORDER; statementInfoTable.AddCell(bCell); Cell sidCell = new Cell(new Phrase(_ViewModel.itemid, hFont1)); sidCell.HorizontalAlignment = Cell.ALIGN_CENTER; sidCell.Border = Cell.NO_BORDER; sidCell.Colspan = 5; statementInfoTable.AddCell(sidCell); Cell reportCell = new Cell(new Phrase(_ViewModel.ReportName, hFont1)); reportCell.HorizontalAlignment = Cell.ALIGN_CENTER; reportCell.Colspan = 5; reportCell.Border = Cell.NO_BORDER; statementInfoTable.AddCell(reportCell); Cell PrintedonCell = new Cell(new Phrase("Printed on: " + _ViewModel.PrintedOn.ToString("dd-dddd-MMMM-yyyy"), hFont2)); PrintedonCell.HorizontalAlignment = Cell.ALIGN_LEFT; PrintedonCell.Colspan = 4; PrintedonCell.Border = Cell.NO_BORDER; statementInfoTable.AddCell(PrintedonCell); //create the logo PDFGen pdfgen = new PDFGen(); Image img0 = pdfgen.DoGetImageFile(_ViewModel.CompanyLogo); img0.Alignment = Image.ALIGN_MIDDLE; Cell logoCell = new Cell(img0); logoCell.HorizontalAlignment = Cell.ALIGN_LEFT; logoCell.Border = Cell.NO_BORDER; logoCell.Add(new Phrase(_ViewModel.CompanySlogan, new Font(Font.HELVETICA, 8, Font.ITALIC, Color.BLACK))); statementInfoTable.AddCell(logoCell); document.Add(statementInfoTable); }
private void BuildPDF() { try { // step 1: creation of a document-object document = new Document(PageSize.A4.Rotate()); // step 2: we create a writer that listens to the document PdfWriter.GetInstance(document, new FileStream(sFilePDF, FileMode.Create)); document.Open(); PDFGen pdfgen = new PDFGen(); Image img0 = pdfgen.DoGetImageFile(_resourcePath + "kra2.jpg"); img0.Alignment = Image.ALIGN_CENTER; Table empInfoTable = new Table(3, 3); empInfoTable.WidthPercentage = 100; empInfoTable.Border = Table.NO_BORDER; Phrase header1 = new Phrase(_ViewModel.ReportName, hFont2); Cell c2 = new Cell(header1); c2.Border = Cell.NO_BORDER; c2.HorizontalAlignment = Cell.ALIGN_CENTER; empInfoTable.AddCell(c2, new System.Drawing.Point(1, 1)); Cell c1 = new Cell(img0);// header1); c1.Border = Cell.NO_BORDER; c1.HorizontalAlignment = Cell.ALIGN_CENTER; empInfoTable.AddCell(c1, new System.Drawing.Point(0, 1)); empInfoTable.Border = Table.NO_BORDER; Chunk employerName = new Chunk("Employers Name ..." + _ViewModel.EmployerName.ToUpper().Trim() + "..", bFont1); Cell empCell = new Cell(employerName); empCell.Border = Cell.NO_BORDER; empInfoTable.AddCell(empCell, new System.Drawing.Point(2, 0)); Chunk employerPIN = new Chunk("Employer's PIN ..." + _ViewModel.EmployerPin.Trim() + "..", bFont1); Cell empPINCell = new Cell(employerPIN); empPINCell.Border = Cell.NO_BORDER; empInfoTable.AddCell(empPINCell, new System.Drawing.Point(2, 2)); Chunk employeeName = new Chunk("Employee’s Main Name………" + _ViewModel.EmployeeMainName.Trim() + "……....", bFont1); Cell empNameCell = new Cell(employeeName); empNameCell.Border = Cell.NO_BORDER; empInfoTable.AddCell(empNameCell, new System.Drawing.Point(3, 0)); Chunk employeeOName = new Chunk("Employee’s Other Names……" + _ViewModel.EmployeeOtherNames.Trim() + "……....", bFont1); Cell empeONameCell = new Cell(employeeOName); empeONameCell.Border = Cell.NO_BORDER; empInfoTable.AddCell(empeONameCell, new System.Drawing.Point(4, 0)); Chunk employeePIN = new Chunk("Employee’s PIN…………………" + _ViewModel.EmployeePin.Trim() + "………....", bFont1); Cell empePINCell = new Cell(employeePIN); empePINCell.Border = Cell.NO_BORDER; empInfoTable.AddCell(empePINCell, new System.Drawing.Point(4, 2)); document.Add(empInfoTable); document.Add(new Phrase("", new Font(Font.TIMES_ROMAN, 2, Font.NORMAL))); Table taxTable = new Table(15, 16); taxTable.Padding = 1; taxTable.Spacing = 1; taxTable.WidthPercentage = 100; //Add table headers AddTableHeaders(taxTable); for (int i = 1; i <= 12; i++) { var monthRecs = (from mr in _ViewModel.P9AHospEmpList where mr.MonthInt == i select mr).SingleOrDefault(); AddTableRow(i, taxTable, monthRecs); } //Add totals AddTotals(taxTable); document.Add(taxTable); AddFooter(); document.Close(); } catch (DocumentException de) { this.Message = de.Message; } catch (IOException ioe) { this.Message = ioe.Message; } catch (Exception ex) { Log.WriteToErrorLogFile(ex); } }
//document header private void AddDocHeader() { PDFGen pdfgen = new PDFGen(); Image img0 = pdfgen.DoGetImageFile(_resourcePath + "kra2.jpg"); img0.Alignment = Image.ALIGN_CENTER; Table p11taxInfoTable = new Table(4); p11taxInfoTable.WidthPercentage = 100; p11taxInfoTable.Border = Table.NO_BORDER; Cell header = new Cell(img0); header.Border = Cell.NO_BORDER; header.HorizontalAlignment = Cell.ALIGN_CENTER; p11taxInfoTable.AddCell(header, new System.Drawing.Point(0, 1)); Cell p11reportname = new Cell(new Phrase("Income Tax Department", hFont1)); p11reportname.HorizontalAlignment = Cell.ALIGN_CENTER; p11reportname.Border = Cell.NO_BORDER; p11taxInfoTable.AddCell(p11reportname, new System.Drawing.Point(2, 1)); Cell emppayeecreditslip = new Cell(new Phrase("P.A.Y.E CREDIT SLIP", hFont2)); emppayeecreditslip.HorizontalAlignment = Cell.ALIGN_CENTER; emppayeecreditslip.Border = Cell.NO_BORDER; p11taxInfoTable.AddCell(emppayeecreditslip, new System.Drawing.Point(3, 1)); Cell emporiginal = new Cell(new Phrase("ORIGINAL", tcFont2)); emporiginal.HorizontalAlignment = Cell.ALIGN_RIGHT; emporiginal.Border = Cell.NO_BORDER; p11taxInfoTable.AddCell(emporiginal, new System.Drawing.Point(3, 3)); Cell empserialno = new Cell(new Phrase("SERIAL NO......................", tcFont2)); empserialno.HorizontalAlignment = Cell.ALIGN_LEFT; empserialno.Border = Cell.NO_BORDER; p11taxInfoTable.AddCell(empserialno, new System.Drawing.Point(4, 2)); Cell emppayrollmonth = new Cell(new Phrase("Pay Roll Month..." + _ViewModel.payrollmonth, tcFont2)); emppayrollmonth.HorizontalAlignment = Cell.ALIGN_LEFT; emppayrollmonth.Border = Cell.NO_BORDER; p11taxInfoTable.AddCell(emppayrollmonth, new System.Drawing.Point(5, 2)); Cell empemployerpin = new Cell(new Phrase("Employer's P.I.N..." + " " + _ViewModel.employerpin, tcFont2)); empemployerpin.HorizontalAlignment = Cell.ALIGN_LEFT; empemployerpin.Border = Cell.NO_BORDER; p11taxInfoTable.AddCell(empemployerpin, new System.Drawing.Point(6, 2)); document.Add(p11taxInfoTable); p11taxInfoTable = new Table(1); p11taxInfoTable.WidthPercentage = 100; p11taxInfoTable.Border = Table.NO_BORDER; Cell empemployername = new Cell(new Phrase("Employer's Name..." + _ViewModel.employername.ToUpper() + "\nTo...........................................Bank. \nPlease pay the Central Bank of Kenya , for the credit of the Paymaster - General, PAYE Account No. 05-010-0056 \n " + "Amount..........." + _ViewModel.totalpayee.ToString("C2") + "\n(In words) Kenya Shillings...........................................................................................................................................\n", tcFont2)); empemployername.HorizontalAlignment = Cell.ALIGN_LEFT; empemployername.Border = Cell.NO_BORDER; p11taxInfoTable.AddCell(empemployername, new System.Drawing.Point(0, 0)); Cell emppayment = new Cell(new Phrase("NATURE OF PAYMENT.", new Font(Font.TIMES_ROMAN, 8, Font.BOLD | Font.UNDERLINE))); emppayment.HorizontalAlignment = Cell.ALIGN_LEFT; emppayment.Border = Cell.NO_BORDER; p11taxInfoTable.AddCell(emppayment, new System.Drawing.Point(1, 0)); Cell payment = new Cell(new Phrase("1...................................................................\n2.....................................................................", tcFont2)); payment.HorizontalAlignment = Cell.ALIGN_LEFT; payment.Border = Cell.NO_BORDER; p11taxInfoTable.AddCell(payment, new System.Drawing.Point(2, 0)); Cell pay = new Cell(new Phrase(".", bFont2)); pay.HorizontalAlignment = Cell.ALIGN_LEFT; pay.Border = Cell.NO_BORDER; p11taxInfoTable.AddCell(pay, new System.Drawing.Point(3, 0)); document.Add(p11taxInfoTable); }
protected void ApproveFormBtn_Click(object sender, EventArgs e) { FormResult.Visible = false; //updating a form not, creating it if (Request.QueryString["pfid"] != null) { int formId = int.Parse(Request.QueryString["pfid"]); Form f = FormUtil.GetForm(formId); Project p = ProjectUtil.GetProject(f.ProjectId); WorkflowModel w = WorkflowUtil.GetWorkflow(p.WorkflowId); User user = (User)Session["User"]; FormUtil.ApproveForm(formId, user.RoleId); Log.Info(user.Identity + " approved " + CompanyUtil.GetCompanyName(p.CompanyId) + "'s form " + f.FormName + " - " + p.Name); FormResult.CssClass = "success"; FormResult.Text = "Approved form " + f.FormName; FormResult.Visible = true; //prep html for pdf generation HtmlDocument doc = new HtmlDocument(); string pdfName = string.Format("{0} - {1} - {2}", w.WorkflowName, f.FormName, CompanyUtil.GetCompanyName(p.CompanyId)); string html = formViewerData.Value; if (html.Contains("user-data")) { html = html.Replace("user-data", "value"); } if (html.Contains("\"")) { html = html.Replace("\"", "'"); } doc.LoadHtml(html); doc.Save("PDFGen/" + CompanyUtil.GetCompanyName(p.CompanyId) + "_" + f.FormName + "_" + p.Name + ".html"); //radiobtns foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//input[@type]")) { HtmlAttribute type = link.Attributes["type"]; if (type.Value.Equals("radio")) { if (link.Attributes.Contains("checked")) { } else { if (link.Attributes.Contains("id")) { string toDelId = link.Attributes["id"].Value; foreach (HtmlNode label in doc.DocumentNode.SelectNodes("//label[@for]")) { string forId = label.Attributes["for"].Value; if (forId.Equals(toDelId)) { label.Remove(); } } } } link.Attributes.Remove("value"); } } //text fields, dates, + similar foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//input[@value]")) { HtmlAttribute value = link.Attributes["value"]; if (link.Attributes.Contains("placeholder")) { link.Attributes.Remove("placeholder"); } string val = value.Value; link.InnerHtml = val; link.Attributes.Remove("value"); } //text areas foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//textarea[@value]")) { HtmlAttribute value = link.Attributes["value"]; if (link.Attributes.Contains("placeholder")) { link.Attributes.Remove("placeholder"); } string val = value.Value; link.InnerHtml = val; link.Attributes.Remove("value"); } //attached files if (f.FilePath.Length > 0) { foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//input[@type]")) { HtmlAttribute type = link.Attributes["type"]; if (type.Value.Equals("file")) { string fileType = f.FilePath.Split('.')[1]; string fileName = string.Format("{0} {1} Attachment.{2}", CompanyUtil.GetCompanyName(p.CompanyId), f.FormName, fileType); link.InnerHtml = "See " + fileName; } } } doc.Save("PDFGen/" + CompanyUtil.GetCompanyName(p.CompanyId) + "_" + f.FormName + "_" + p.Name + ".html"); doc.Load("PDFGen/" + CompanyUtil.GetCompanyName(p.CompanyId) + "_" + f.FormName + "_" + p.Name + ".html"); html = doc.Text; //pdf gen PDFGen.CreateHTMLPDF(html, pdfName); Response.Redirect("Forms.aspx?pfid=" + formId); } }
private void BuildP10PDF() { try { document = new Document(PageSize.A4.Rotate()); PdfWriter.GetInstance(document, new FileStream(sFilePDF, FileMode.Create)); document.Open(); PDFGen pdfgen = new PDFGen(); Image img0 = pdfgen.DoGetImageFile(_resourcePath + "kra2.jpg"); img0.Alignment = Image.ALIGN_CENTER; Table empInfoTable = new Table(3, 3); empInfoTable.WidthPercentage = 100; empInfoTable.Border = Table.NO_BORDER; Phrase header1 = new Phrase(_ViewModel.ReportName, hFont2); Cell c2 = new Cell(header1); c2.Border = Cell.NO_BORDER; c2.HorizontalAlignment = Cell.ALIGN_CENTER; // c1.Colspan = 3; empInfoTable.AddCell(c2, new System.Drawing.Point(1, 1)); // Phrase header1 = new Phrase(p9A.ReportName, hFont2); Cell c1 = new Cell(img0);// header1); c1.Border = Cell.NO_BORDER; c1.HorizontalAlignment = Cell.ALIGN_CENTER; // c1.Colspan = 3; empInfoTable.AddCell(c1, new System.Drawing.Point(0, 1)); Chunk name = new Chunk("_ViewModel", bFont1); Cell empPINCell1 = new Cell(name); empPINCell1.Border = Cell.NO_BORDER; empInfoTable.AddCell(empPINCell1, new System.Drawing.Point(1, 0)); Chunk employerPIN = new Chunk("Employer's PIN ..." + _ViewModel.EmployerPin.Trim() + "...", bFont1); Cell empPINCell = new Cell(employerPIN); empPINCell.Border = Cell.NO_BORDER; empInfoTable.AddCell(empPINCell, new System.Drawing.Point(1, 2)); document.Add(empInfoTable); Table empInfoTable2 = new Table(1, 4); empInfoTable2.WidthPercentage = 100; empInfoTable2.Border = Table.NO_BORDER; Phrase header2 = new Phrase("To Senior Assistant Commissioner...........\n", bFont1); Cell c3 = new Cell(header2); c3.Border = Cell.NO_BORDER; c3.HorizontalAlignment = Cell.ALIGN_LEFT; c3.VerticalAlignment = Cell.ALIGN_CENTER; empInfoTable2.AddCell(c3, new System.Drawing.Point(1, 0)); Chunk info = new Chunk("We/I forward herewith...................Tax Deduction Cards(P9A/P9B)showing the Total tax deducted\n (as listed on P10A) amounting to Kshs........" + _ViewModel.TotalPAYETax.ToString("#,##0") + "\n This Total tax has been paid as follows:- ", bFont1); Cell info1 = new Cell(info); info1.Border = Cell.NO_BORDER; info1.HorizontalAlignment = Cell.ALIGN_LEFT; empInfoTable2.AddCell(info1, new System.Drawing.Point(2, 0)); Chunk info2 = new Chunk(".", bFont1); Cell info3 = new Cell(info2); info3.Border = Cell.NO_BORDER; info3.HorizontalAlignment = Cell.ALIGN_LEFT; empInfoTable2.AddCell(info3, new System.Drawing.Point(3, 0)); document.Add(empInfoTable2); Table taxTable = new Table(5, 14); taxTable.Padding = 1; taxTable.Spacing = 1; taxTable.WidthPercentage = 100; //Add table headers AddTableHeaders(taxTable); for (int i = 1; i <= 12; i++) { var monthRecs = (from mr in _ViewModel.P10tax where mr.MonthInt == i select mr).SingleOrDefault(); AddTableRow(i, taxTable, monthRecs); } //Add totals AddTotals(taxTable); document.Add(taxTable); AddFooter(); document.Close(); } catch (DocumentException de) { this.Message = de.Message; } catch (IOException ioe) { this.Message = ioe.Message; } catch (Exception ex) { Log.WriteToErrorLogFile(ex); } }
private void BuildPDF() { try { // step 1: creation of a document-object document = new Document(PageSize.A4); // step 2: we create a writer that listens to the document PdfWriter.GetInstance(document, new FileStream(sFilePDF, FileMode.Create)); document.Open(); PDFGen pdfgen = new PDFGen(); Image img0 = pdfgen.DoGetImageFile(_resourcePath + "kra2.jpg"); img0.Alignment = Image.ALIGN_LEFT; Table empInfoTable = new Table(1); empInfoTable.WidthPercentage = 100; empInfoTable.Border = Table.NO_BORDER; Phrase header1 = new Phrase(_ViewModel.ReportName, hFont2); Cell c2 = new Cell(header1); c2.Border = Cell.NO_BORDER; c2.HorizontalAlignment = Cell.ALIGN_CENTER; // c1.Colspan = 3; empInfoTable.AddCell(c2, new System.Drawing.Point(1, 0)); Cell c1 = new Cell(img0);// header1); c1.Border = Cell.NO_BORDER; c1.HorizontalAlignment = Cell.ALIGN_CENTER; // c1.Colspan = 3; empInfoTable.AddCell(c1, new System.Drawing.Point(0, 0)); Chunk name = new Chunk("P.A.Y.E SUPPORTING LIST FOR END OF YEAR CERTIFICATE: YEAR.." + _ViewModel.Year.ToString() + "..", bFont2); Cell emp2Cell = new Cell(name); emp2Cell.Border = Cell.NO_BORDER; empInfoTable.AddCell(emp2Cell, new System.Drawing.Point(2, 0)); Chunk formname = new Chunk("P10A", bFont1); Cell emp1Cell = new Cell(formname); emp1Cell.Border = Cell.NO_BORDER; emp1Cell.HorizontalAlignment = Cell.ALIGN_LEFT; empInfoTable.AddCell(emp1Cell, new System.Drawing.Point(3, 0)); Chunk employerName = new Chunk("Employer's Name ..." + _ViewModel.EmployerName.ToUpper().Trim() + ".......... Employer's PIN ..." + _ViewModel.EmployerPin.Trim() + "..", bFont1); Cell empCell = new Cell(employerName); empCell.Border = Cell.NO_BORDER; empInfoTable.AddCell(empCell, new System.Drawing.Point(4, 0)); document.Add(empInfoTable); document.Add(new Phrase("", new Font(Font.TIMES_ROMAN, 2, Font.NORMAL))); Table taxTable = new Table(4); taxTable.Padding = 1; taxTable.Spacing = 1; taxTable.WidthPercentage = 100; //Add table headers AddTableHeaders(taxTable); //Add table details foreach (var tr in _ViewModel.P10AList) { AddTableRow(taxTable, tr); } //Add totals AddTotals(taxTable); document.Add(taxTable); AddFooter(); document.Close(); } catch (DocumentException de) { this.Message = de.Message; } catch (IOException ioe) { this.Message = ioe.Message; } catch (Exception ex) { Log.WriteToErrorLogFile(ex); } }