// public FileResult Export() public async Task <IActionResult> Export() { using (MemoryStream stream = new System.IO.MemoryStream()) { string fileName = HttpContext.User.GetUserName() + Path.GetRandomFileName() + ".png"; fileName = "helloWorld.cshtml"; string directory = _config["StoredFilesPath"]; string url = string.Format("{0}://{1}/{2}/{3}", HttpContext.Request.Scheme, HttpContext.Request.Host.Value, directory, fileName); var filePath = Path.Combine(new string[] { Directory.GetCurrentDirectory(), directory, fileName }); string value = System.IO.File.ReadAllText(filePath); // StringReader reader = new StringReader(value); // Stream pdfStream = new MemoryStream(Encoding.UTF8.GetBytes(value)); // Document PdfFile = new Document(PageSize.A4); // //add the collection to the document // PdfWriter writer = PdfWriter.GetInstance(PdfFile, stream); // PdfFile.Open(); // XMLWorkerHelper.GetInstance().ParseXHtml(writer, PdfFile, pdfStream,Stream.Null); // PdfFile.Close(); // return File(stream.ToArray(), "application/pdf", "ExportData.pdf"); // return new ActionAsPdf("Index", new { name = "Giorgio" }) { FileName = "Test.pdf" }; return(await _generatePdf.GetPdfViewInHtml(value)); } }
public async Task <IActionResult> Test() { var data = new TestData { Text = "This is not a test", Number = 12345678 }; return(await _generatePdf.GetPdfViewInHtml(htmlView, data)); }
public async Task <IActionResult> Get() { var data = new ProfileCard { Name = "Susan Doe", Designation = "CEO & Co-Founder", Company = "Doe Company" }; var htmlPage = await System.IO.File.ReadAllTextAsync("Templates/ProfileCard.cshtml"); return(await _generatePdf.GetPdfViewInHtml(htmlPage, data)); }
public async Task <IActionResult> Export(EstimationDto estimationDto) { using (MemoryStream stream = new System.IO.MemoryStream()) { string fileName = "estimation.cshtml"; string directory = _config["StoredFilesPath"]; string url = string.Format("{0}://{1}/{2}/{3}", HttpContext.Request.Scheme, HttpContext.Request.Host.Value, directory, fileName); var filePath = Path.Combine(new string[] { Directory.GetCurrentDirectory(), directory, fileName }); string value = System.IO.File.ReadAllText(filePath); value = value.Replace("[#GoldPrice#]", string.Format("{0}", estimationDto.GoldPrice)); value = value.Replace("[#Weight#]", string.Format("{0}", estimationDto.Weight)); value = value.Replace("[#TotalPrice#]", string.Format("{0}", estimationDto.TotalPrice)); value = value.Replace("[#Discount#]", string.Format("{0}", estimationDto.Discount)); return(await _generatePdf.GetPdfViewInHtml(value)); } }
public async Task <IActionResult> GetPDF([FromBody] Dictionary <string, object> rawdata, string template) { // first do a mustache merge. var stubble = new StubbleBuilder().Build(); string filename = $"Templates/{template}.mustache"; if (System.IO.File.Exists(filename)) { string format = System.IO.File.ReadAllText(filename); var html = stubble.Render(format, rawdata); _generatePdf.SetConvertOptions(new ConvertOptions { PageSize = Size.Letter, PageMargins = new Margins(5, 5, 5, 5) }); var pdf = await _generatePdf.GetPdfViewInHtml(html); return(pdf); } return(new NotFoundResult()); }