public static string GetStudentCertificationHtml(string DocumentDescription, StudentCertificationDrop model) { if (DocumentDescription.ToLower() == "vertetim") { StudentCertificationDrop data = model; string liquidTemplateFilePath = "./Templates/StudentCertification.html"; Template template = GetTemplate(liquidTemplateFilePath); Hash hash = Hash.FromAnonymousObject(new { Model = data }); string renderedOutput = template.Render(hash); return(renderedOutput); } else { return(null); } }
public async Task <Message <DocumentsModel> > GenerateDocuments(DocumentsModel documentsModel) { try { var studentCertificateData = await _documentsRepository.GetStudentCertificateData(Convert.ToInt32(documentsModel.UserId)); var model = new StudentCertificationDrop(); model.CreationDate = DateTime.Now; model.NoAmze = studentCertificateData[0].NrAmze; model.SchoolName = studentCertificateData[0].SchoolName; model.StudentName = studentCertificateData[0].FullName; model.StudentYear = studentCertificateData[0].ClassYear; var globalSettings = new GlobalSettings { ColorMode = ColorMode.Color, Orientation = Orientation.Portrait, PaperSize = PaperKind.A4, Margins = new MarginSettings { Top = 10 }, DocumentTitle = "Vertetim Studenti", //Out = $@"C:\inetpub\wwwroot\HighSchool-API\media\vertetim\VertetimUser{model.StudentName}.pdf" }; var objectSettings = new ObjectSettings { PagesCount = true, HtmlContent = TemplateGenerator.GetStudentCertificationHtml("vertetim", model), FooterSettings = { FontName = "Arial", FontSize = 9, Right = "Faqe [page] nga [toPage]", Line = true } }; var pdf = new HtmlToPdfDocument() { GlobalSettings = globalSettings, Objects = { objectSettings } }; var output = _converter.Convert(pdf); string documentPath = $@"C:\inetpub\wwwroot\HighSchool-API\media\vertetim\VertetimUser{model.StudentName}.pdf"; Helper.AddDocumentToDocumentSet(documentPath, output); documentsModel.FileBytes = output; Helper.SaveDocument(documentsModel, _repository, _mapper, _logger); return(new Message <DocumentsModel>() { IsSuccess = true, ReturnMessage = "OK", StatusCode = 200, Data = documentsModel }); //return File(output, "application/pdf"); } catch (Exception ex) { _logger.LogError("Error on generating", ex); return(new Message <DocumentsModel>() { IsSuccess = false, ReturnMessage = "Error", StatusCode = 500, Data = null }); } }