public async Task <IActionResult> MyAction([FromServices] INodeServices nodeServices) { var filePath = "./external/templates/registration/firRequest.html"; var letterHeading = await _letterHeadingService.GetAsync(1); var letter = (await _letterService.GetAsync(x => x.ModuleDocument.DocumentType.DocumentTypeCode == "PORR")); var data = new IpermitPDFData() { company = letterHeading.CompanyName, logoUrl = letterHeading.LogoUrl, header = letter.Title,//"PURCHASE ORDER APPLICATION ACKNOWLEDGMENT LETTER", address = "Nifas silk Lafto subcity, wored 06, H.No 803 ETHIOPIA", to = "HOSAM PHARMACEUTICALS TRADING", date = "3/28/17 11:35 AM", body = letter.Body,//"Your purchase order application for the below products have been accepted for evaluation. It is anticipated that the evaluation will be completed by approximately 3 days from the date of submission. The anticipated date of completion of the evaluation has been provided for your convenience and it is an estimate only", submissionDate = "March 28, 2017", applicationNumber = "00018/IP/2017", totalPrice = "6750", price = "500", shippingMethod = "By Air", delivery = "90 days", freight = "0", comment = "Freightcost to be paid at sight", portOfEntry = "Addis Ababa Bole air port", paymentMode = "L/c at site", performaInvoiceNumber = "0015/2016-17", tempFolderName = "5c5c90ba-dcf0-4152-979e-bedb249c9a46", fileName = "Approve.pdf", items = new List <IpermitPDFDataDetail> { new IpermitPDFDataDetail { product = "OXOL", manufacturer = "VENUS REMEDIES LTD", site = "HILL TOP INDUSTRIAL ESTATE, JHARMAJIRI EPIP,PHSEI,BHATOLI KALAN,BADDI DIST SOLAN (H.P.)", country = "India", quantity = "1", unitprice = "1000", currency = "USD" }, new IpermitPDFDataDetail { product = "OXOL", manufacturer = "VENUS REMEDIES LTD", site = "HILL TOP INDUSTRIAL ESTATE, JHARMAJIRI EPIP,PHSEI,BHATOLI KALAN,BADDI DIST SOLAN (H.P.)", country = "India", quantity = "4", unitprice = "1000", currency = "USD" }, new IpermitPDFDataDetail { product = "OXOL", manufacturer = "VENUS REMEDIES LTD", site = "HILL TOP INDUSTRIAL ESTATE, JHARMAJIRI EPIP,PHSEI,BHATOLI KALAN,BADDI DIST SOLAN (H.P.)", country = "India", quantity = "3", unitprice = "1000", currency = "USD" }, } }; //await _generateDocument.GeneratePDFDocument(filePath, data, nodeServices); var htmlString = string.Join(" ", System.IO.File.ReadAllLines(filePath)); var result = await nodeServices.InvokeAsync <byte[]>("./external/js/pdf", htmlString, data); HttpContext.Response.ContentType = "application/pdf"; string filename = @"report.pdf"; HttpContext.Response.Headers.Add("x-filename", filename); HttpContext.Response.Headers.Add("Access-Control-Expose-Headers", "x-filename"); HttpContext.Response.Body.Write(result, 0, result.Length); return(new ContentResult()); }
public async Task GeneratePDFDocument(string htmlFilePath, ImportStatusLog ipermit, INodeServices nodeServices, string documenttypeCode, string submoduleCode, ImportPermit iipermit) { try { var letterHeading = await _letterHeadingService.GetAsync(1); var letter = (await _letterService.GetAsync(x => x.ModuleDocument.DocumentType.DocumentTypeCode == documenttypeCode && x.ModuleDocument.Submodule.SubmoduleCode == submoduleCode)); var moduleDocument = await _moduleDocumentService.GetAsync(letter.ModuleDocumentID); var moduleCode = moduleDocument.Submodule.Module.ModuleCode; IpermitPDFData data = new IpermitPDFData(iipermit, letterHeading, letter, ipermit.Comment); var ipemitStatues = (await _statusService.GetIPermitStatus(iipermit.ID)); data.submissionDate = ipemitStatues.FirstOrDefault(s => s.ToImportPermitStatus.ImportPermitStatusCode == "RQST")?.CreatedDate.ToString(); data.approvedDate = ipemitStatues.FirstOrDefault(s => s.ToImportPermitStatus.ImportPermitStatusCode == "APR")?.CreatedDate.ToString(); data.rejectedDate = ipemitStatues.FirstOrDefault(s => s.ToImportPermitStatus.ImportPermitStatusCode == "REJ")?.CreatedDate.ToString(); data.expiryDate = iipermit.ExpiryDate?.ToString();; data.reason = ipemitStatues.FirstOrDefault(s => s.ToImportPermitStatus.ImportPermitStatusCode == "REJ")?.Comment; var htmlString = string.Join(" ", System.IO.File.ReadAllLines(htmlFilePath)); htmlString = buildCSS(htmlString); var pdfPath = $".{Path.DirectorySeparatorChar}external{Path.DirectorySeparatorChar}js{Path.DirectorySeparatorChar}pdf"; var result = await nodeServices.InvokeAsync <byte[]> (pdfPath, htmlString, data); var relativeDirectory = $"{Path.DirectorySeparatorChar}{moduleCode}{Path.DirectorySeparatorChar}{data.tempFolderName}"; var directory = $"{_rootUrl}{relativeDirectory}"; var filePath = $"{relativeDirectory}{Path.DirectorySeparatorChar}{data.fileName}"; await FileHelper.SaveFileAsync(directory, data.fileName, result); Domain.Document.Document docEntity = new Domain.Document.Document() { ModuleDocumentID = letter.ModuleDocumentID, FilePath = filePath, FileType = "application/pdf", ReferenceID = ipermit.ID, CreatedBy = ipermit.ChangedBy, UpdatedBy = ipermit.ChangedBy }; await _documentService.CreateOrUpdateAsync(docEntity, true, r => r.ModuleDocumentID == docEntity.ModuleDocumentID && r.FilePath == docEntity.FilePath && r.ReferenceID == docEntity.ReferenceID); } catch (Exception ex) { _logger.Log(ex); } }