public bool ConvertHtmlToPdf(int RequestID) { var payslips = _payslipDetailReponsitory.FindAll().Where(x => x.RequestID == RequestID).ToList(); var request = _requestDetailService.GetById(RequestID); var temp = _requestDetailReponsitory.FindById(RequestID); _requestDetailReponsitory.Commit(); string month = months[request.PayslipForMonth]; if (payslips == null) { return(false); } foreach (var item in payslips) { PdfDocument checkPDF = null; InputPdfFile model = InputPdfFile(item); string StringHtml = _viewRenderService.RenderToStringAsync(@"../../Pages/PayslipTemplate", model).GetAwaiter().GetResult(); string folderPath = @"..\OSDPayslip.Web\wwwroot\PDF\" + RequestID.ToString(); string pdfPath = folderPath + @"\" + model.Id + "_Payslips_" + month + ".pdf"; var pdfPrintOptions = new PdfPrintOptions() { DPI = 300, }; if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } HtmlToPdf Renderer = new HtmlToPdf(pdfPrintOptions); Renderer.PrintOptions.PaperSize = PdfPrintOptions.PdfPaperSize.A2; checkPDF = Renderer.RenderHtmlAsPdf(StringHtml).SaveAs(pdfPath); if (checkPDF != null) { PdfDocument Pdf = PdfDocument.FromFile(pdfPath); PdfSecuritySettings securitySettings = Pdf.SecuritySettings; securitySettings.UserPassword = CreatePassWord(model.IdentidyId, model.BirthDay); if (Pdf.Password != null) { Pdf.SaveAs(pdfPath); } } } return(true); }
public InputPdfFile InputPdfFile(PayslipDetail item) { var date = DateTime.Now; Employee employee = _employeeReponsitory.FindById(item.EmployeeID); InputPdfFile model = new InputPdfFile() { Id = item.EmployeeID, FullName = employee.FullName, DeptTeam = employee.DeptTeam, StandardWorkingDay = item.StandardWorkingDay, ActualWorkingDay = item.ActualWorkingDay, UnpaidLeave = item.UnpaidLeave, LeaveBalance = item.LeaveBalance, Holidays = item.Holidays, BasicSalary = item.BasicSalary, GrossSalary = item.GrossSalary, ActuaSalary = item.ActuaSalary, Allowance = item.Allowance, Bonus = item.Bonus, Salary13Th = item.Salary13Th, IncomeOther = item.IncomeOther, OtherDeductions = item.OtherDeductions, Insurance = item.Insurance, SocialInsurance = item.SocialInsurance, HealthInsurance = item.HealthInsurance, UnemploymentInsurance = item.UnemploymentInsurance, NoOfDependants = item.NoOfDependants, PersonalIncomeTax = item.PersonalIncomeTax, PaymentFromSocialInsurance = item.PaymentFromSocialInsurance, FinalizationOfPIT = item.FinalizationOfPIT, PaymentOther = item.PaymentOther, NetIncome = item.NetIncome, MonthYear = date.Month.ToString() + date.Year.ToString(), TotalGrossIncome = item.ActuaSalary + item.Allowance + item.IncomeOther + item.OtherDeductions, TotalInsurance = item.SocialInsurance + item.HealthInsurance + item.UnemploymentInsurance, TotalDeduction = item.SocialInsurance + item.HealthInsurance + item.UnemploymentInsurance + item.PersonalIncomeTax, TotalOtherPayment = item.PaymentFromSocialInsurance + item.FinalizationOfPIT + item.PaymentOther, BirthDay = employee.BirthDay, IdentidyId = employee.IdentidyId, Notes = item.Notes.Split(';') }; return(model); }