public MemoryStream ConvertHtml(string htmlText) { HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit); WebKitConverterSettings settings = new WebKitConverterSettings { EnableJavaScript = false }; string baseUrl = _webHostEnvironment.ContentRootPath.TrimEnd('/') + "/Temp/HTMLFiles/"; //Set WebKit path settings.WebKitPath = GetWebKitPath(); //Assign WebKit settings to HTML converter htmlConverter.ConverterSettings = settings; //Convert HTML string to PDF PdfDocument document = htmlConverter.Convert(htmlText, baseUrl); //Save the document into stream. MemoryStream stream = new MemoryStream(); document.Save(stream); stream.Position = 0; //Close the document. document.Close(true); return(stream); }
public IActionResult ConvertToPdf(string Url, string name) { HtmlToPdfConverter converter = new HtmlToPdfConverter(); WebKitConverterSettings settings = new WebKitConverterSettings(); settings.WebKitPath = Path.Combine(hostingEnvironment.ContentRootPath, "QtBinariesWindows"); converter.ConverterSettings = settings; // PdfDocument doc = converter.Convert(string.Concat("https://localhost:44301", Url)); MemoryStream ms = new MemoryStream(); doc.Save(ms); doc.Close(true); ms.Position = 0; FileStreamResult fileStream = new FileStreamResult(ms, "application/pdf"); fileStream.FileDownloadName = name; return(fileStream); }
public object GerarPdf(string html, string contratoNome) { HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); WebKitConverterSettings settings = new WebKitConverterSettings(); //Set WebKit path settings.WebKitPath = Path.Combine(_hosting.ContentRootPath, "QtBinariesLinux"); //Assign WebKit settings to HTML converter htmlConverter.ConverterSettings = settings; //Convert URL to PDF try{ var x = htmlConverter.Convert(html); }catch (Exception ex) { } PdfDocument document = new PdfDocument(); MemoryStream stream = new MemoryStream(); document.Save(stream); return(new FileContentResult(stream.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf)); //var htmlToPdf = new HtmlToPdf(); //var pdf = htmlToPdf.ConvertHtmlString(html); //return pdf; }
public IActionResult ExportToPDF() { //Set Environment variable for OpenSSL assemblies folder string SSLPath = Path.Combine(_hostingEnvironment.ContentRootPath, "OpenSSL"); Environment.SetEnvironmentVariable("Path", SSLPath); //Initialize HTML to PDF converter HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); WebKitConverterSettings settings = new WebKitConverterSettings(); //Set WebKit path settings.WebKitPath = Path.Combine(_hostingEnvironment.ContentRootPath, "QtBinariesWindows"); //Assign WebKit settings to HTML converter htmlConverter.ConverterSettings = settings; //Convert URL to PDF int id = int.Parse(User.Identity.GetUserId()); string url = "https://localhost:44327/UserHub/Pdf/" + id; PdfDocument document = htmlConverter.Convert(url); MemoryStream stream = new MemoryStream(); document.Save(stream); DateTime today = DateTime.Today; return(File(stream.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf, "Raport-" + today.ToShortDateString() + ".pdf")); }
public MemoryStream GetPdf(string html) { HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit); WebKitConverterSettings settings = new WebKitConverterSettings(); //Set WebKit path settings.WebKitPath = @"../../QtBinariesDotNetCore/"; settings.Margin = new Syncfusion.Pdf.Graphics.PdfMargins { All = 30 }; settings.PdfPageSize = new SizeF(512, 692); settings.WebKitViewPort = new Size(800, 0); //Assign WebKit settings to HTML converter htmlConverter.ConverterSettings = settings; //Convert URL to PDF PdfDocument document = htmlConverter.Convert(html, ""); string filePath = "D:\\DemoProjects\\Movers\\MoversApi\\temp\\RevisedEstimate_back.pdf"; FileStream fileStream = new FileStream(filePath, FileMode.Open); PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream); //Save and close the PDF document MemoryStream stream = new MemoryStream(); PdfDocumentBase.Merge(document, loadedDocument); document.Save(stream); document.Close(true); return(stream); }
public IActionResult Print() { HtmlToPdfConverter converter = new HtmlToPdfConverter(); WebKitConverterSettings settings = new WebKitConverterSettings(); settings.WebKitPath = Path.Combine(_hostEnvironment.ContentRootPath, "QtBinariesWindows"); converter.ConverterSettings = settings; PdfDocument document = converter.Convert("https://localhost:44389/reports/report"); MemoryStream ms = new MemoryStream(); document.Save(ms); document.Close(true); ms.Position = 0; FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf"); fileStreamResult.FileDownloadName = "Students.pdf"; return(fileStreamResult); }
public static bool GeneratePDF(string htmlContent, string fullPath) { HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); WebKitConverterSettings settings = new WebKitConverterSettings(); settings.Margin.All = 8; //Set WebKit path if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows)) { settings.WebKitPath = Path.Combine(Configurations.Environment.ContentRootPath, "lib", "QtBinariesDotNetCore"); } else { settings.WebKitPath = Path.Combine(Configurations.Environment.ContentRootPath, "lib", "QtBinaries"); } //Assign WebKit settings to HTML converter htmlConverter.ConverterSettings = settings; //Convert URL to PDF Syncfusion.Pdf.PdfDocument document = htmlConverter.Convert(htmlContent, ""); //Save and close the PDF document new FileInfo(fullPath).Directory.Create(); using (var streamWriter = File.Create(fullPath)) { document.Save(streamWriter); } document.Close(true); return(true); }
public ActionResult AddModal(string CustName, string CustEmail, string CustCategory) { //Initialize the HTML to PDF converter HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit); WebKitConverterSettings settings = new WebKitConverterSettings(); //Set WebKit path settings.WebKitPath = @"D:/Data/7th Semester/IPT/Project/WEB APP/SmartPOS_CRUD/packages/Syncfusion.HtmlToPdfConverter.QtWebKit.AspNet.17.3.0.26/lib/QtBinaries"; //Assign WebKit settings to HTML converter htmlConverter.ConverterSettings = settings; //Convert URL to PDF PdfDocument document = htmlConverter.Convert("http://*****:*****@gmail.com"); msg.To.Add(new MailAddress(CustEmail)); msg.Subject = "Thank You For Shopping"; msg.Body = "Please check the Invoice Attached below."; Attachment attachment; attachment = new Attachment("D:/Data/7th Semester/IPT/Project/WEB APP/SmartPOS_CRUD/MVC/Invoice/" + CustName + ".pdf"); attachment.Name = "Invoice.pdf"; msg.Attachments.Add(attachment); SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", Convert.ToInt32(587)); System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("*****@*****.**", "TijaratPOS000"); smtpClient.Credentials = credentials; smtpClient.EnableSsl = true; smtpClient.Send(msg); mvcCustomerModel cust = new mvcCustomerModel(); cust.CustName = CustName; cust.CustEmail = CustEmail; cust.CustCategory = CustCategory; HttpResponseMessage response = GlobalHttp.WebApiClient.PostAsJsonAsync("Customers", cust).Result; TempData["SuccessMessage"] = "Shopping Receipt Has Been Send To Customer"; } catch (Exception ex) { TempData["AlertMessage"] = "Something Went Wrong Please Check Your Connection Or Enter Valid Email Address"; } return(RedirectToAction("Index")); }
public FileContentResult ConvertPdf() { HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); WebKitConverterSettings settings = new WebKitConverterSettings(); settings.WebKitPath = Path.Combine(_hostingEnvironment.ContentRootPath, "QtBinariesWindows"); htmlConverter.ConverterSettings = settings; PdfDocument document = htmlConverter.Convert($"https://localhost:44302/pdf/resultadospdf/?id=" + Ninio.Id); MemoryStream stream = new MemoryStream(); document.Save(stream); return(File(stream.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf, $"Resultados.pdf")); }
public IActionResult ExportToPDF(int?Id) { //Initialize HTML converter HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); // WebKit converter settings WebKitConverterSettings webKitSettings = new WebKitConverterSettings(); //Assign the WebKit binaries path webKitSettings.WebKitPath = @"QtBinariesWindows\"; // Enable table of contents webKitSettings.EnableToc = true; //Assign the WebKit settings htmlConverter.ConverterSettings = webKitSettings; //Convert HTML to PDF PdfDocument document = htmlConverter.Convert("https://localhost:44339/product"); //Save the document into stream. MemoryStream stream = new MemoryStream(); document.Save(stream); stream.Position = 0; //Close the document. document.Close(true); //Defining the ContentType for pdf file. string contentType = "application/pdf"; //Define the file name. string fileName = " Output.pdf"; //Creates a FileContentResult object by using the file contents, content type, and file name. return(File(stream, contentType, fileName)); //return new ViewAsPdf("Details", _Product.GetProduct(Id??1)); }
public PdfHandler() { archiveFolder = Path.Combine(Environment.CurrentDirectory, "Archives"); qtBinariespath = Path.Combine(Environment.CurrentDirectory, "QtBinariesDotNetCore"); templatePath = Path.Combine(Directory.GetCurrentDirectory(), "Resources\\pdftemplate.pdf"); tempFolder = Path.GetTempPath(); htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit); webKitSettings = new WebKitConverterSettings(); webKitSettings.WebKitPath = qtBinariespath; webKitSettings.EnableForm = true; htmlConverter.ConverterSettings = webKitSettings; }
public IActionResult ExportToPDF(String submit) { HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); WebKitConverterSettings settings = new WebKitConverterSettings(); settings.WebKitPath = Path.Combine(_hostingEnvironment.ContentRootPath, "QtBinariesWindows"); htmlConverter.ConverterSettings = settings; PdfDocument document = htmlConverter.Convert("https://lms.kpcerc.com/"); document.PageSettings.Margins.Left = 10; document.PageSettings.Margins.Right = 10; document.PageSettings.Margins.Top = 20; document.PageSettings.Margins.Bottom = 20; MemoryStream stream = new MemoryStream(); document.Save(stream); document.Close(true); stream.Position = 0; FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf"); fileStreamResult.FileDownloadName = "Qouation.pdf"; return(fileStreamResult); ////Create a new PDF document //PdfDocument document = new PdfDocument(); ////Add a page to the document //PdfPage page = document.Pages.Add(); ////Create PDF graphics for the page //PdfGraphics graphics = page.Graphics; ////Set the standard font //PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); ////Draw the text //graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new PointF(0, 0)); ////Saving the PDF to the MemoryStream // MemoryStream stream = new MemoryStream(); // document.Save(stream); ////If the position is not set to '0' then the PDF will be empty. // stream.Position = 0; ////Download the PDF document in the browser. // FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf"); // fileStreamResult.FileDownloadName = "Output.pdf"; // return fileStreamResult; }
private void ConvertHtmlToPdf(string directoryPath) { try { var mainUrl = Path.Combine(_env.ContentRootPath, "wwwroot"); HtmlToPdfConverter converter = new HtmlToPdfConverter(); WebKitConverterSettings settings = new WebKitConverterSettings(); settings.WebKitPath = Path.Combine(mainUrl, "QtBinariesWindows"); converter.ConverterSettings = settings; //test settings.TempPath = Path.Combine(mainUrl, "QtBinariesWindows", "temp"); // string[] filePaths = Directory.GetFiles(directoryPath); foreach (string file in filePaths) { FileInfo info = new FileInfo(file); if (File.Exists(info.FullName)) { if (info.Extension.Equals(".html")) { Syncfusion.Pdf.PdfDocument document = converter.Convert(info.FullName); MemoryStream ms = new MemoryStream(); document.Save(ms); document.Close(true); ms.Position = 0; FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf"); var fileName = info.Name.Split(".")[0] + ".pdf"; var destSource = Path.Combine(directoryPath, fileName); var fileStream = new FileStream(destSource, FileMode.Create, FileAccess.Write); fileStreamResult.FileStream.CopyTo(fileStream); fileStream.Close(); } } } } catch (Exception ex) { DeleteDirectory(directoryPath); throw ex; } }
private static MemoryStream ConvertFromHtml(string htmlString) { var htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit); var settings = new WebKitConverterSettings { WebKitPath = $"{_functionAppDirectory}/QtBinaries" }; htmlConverter.ConverterSettings = settings; var outputStream = new MemoryStream(); var document = htmlConverter.Convert(htmlString, ""); document.Save(outputStream); document.Close(true); return(outputStream); }
public async Task <IActionResult> SendCard(string id) { string contactType = id; Card card = JsonSerializer.Deserialize <Card>(TempData["Card"] as string); if (card == null) { return(NotFound()); } else { TempData["Card"] = null; } var list = await _context.EmailLists.Include(e => e.ApplicationUser).Where(e => (contactType == "All" || e.ContactType == (ContactTypes)Enum.Parse(typeof(ContactTypes), contactType)) && e.ApplicationUser.UserName == User.Identity.Name).ToListAsync(); if (list == null) { return(NotFound()); } var emailAddresses = list.Select(l => l.Email); HtmlToPdfConverter converter = new HtmlToPdfConverter(); WebKitConverterSettings settings = new WebKitConverterSettings(); converter.ConverterSettings = settings; PdfDocument document = converter.Convert("wwwroot\\img\\Pony.png"); MemoryStream ms = new MemoryStream(); document.Save(ms); document.Close(true); ms.Position = 0; FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf"); fileStreamResult.FileDownloadName = "test.pdf"; return(fileStreamResult); //return RedirectToActionPermanent("Success"); }
public void ConvertToPdf(string source, string destination) { try { var htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit); var settings = new WebKitConverterSettings { WebKitPath = @"/QtBinaries/" }; htmlConverter.ConverterSettings = settings; var document = htmlConverter.Convert("https://www.google.com"); document.Save(destination); document.Close(true); } catch (Exception ex) { FileLogger.SetLog(string.Format(ExceptionConstants.ConvertToPdf, source, ex.Message)); } }
private static IHtmlConverterSettings CreateConverterSetting(float height = 0) { var setting = new WebKitConverterSettings(); if (height > 0) { setting.PdfPageSize = new System.Drawing.SizeF(PdfPageSize.A4.Width, height); setting.Orientation = PdfPageOrientation.Landscape; } setting.EnableRepeatTableHeader = true; setting.EnableRepeatTableFooter = true; setting.EnableHyperLink = true; setting.SplitTextLines = false; setting.SplitImages = false; setting.MediaType = MediaType.Print; setting.WebKitPath = HttpContext.Current.Server.MapPath("/" + QtBinariesPath); setting.WebKitViewPort = new System.Drawing.Size(800, 0); return(setting); }
public IActionResult ExportToPDF(int?Id) { //Initialize HTML to PDF converter HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); WebKitConverterSettings settings = new WebKitConverterSettings(); //HTML string and Base URL string htmlText = "<html><body><img src=\"syncfusion_logo.gif\" alt=\"Syncfusion_logo\" width=\"200\" height=\"70\"><p> Hello World</p></body></html>"; string baseUrl = @"E:/Anglar 5/"; //Set WebKit path settings.WebKitPath = @"QtBinariesWindows\"; //Assign WebKit settings to HTML converter htmlConverter.ConverterSettings = settings; //Convert HTML string to PDF PdfDocument document = htmlConverter.Convert(htmlText, baseUrl); //Save the document into stream. MemoryStream stream = new MemoryStream(); document.Save(stream); stream.Position = 0; //Close the document. document.Close(true); //Defining the ContentType for pdf file. string contentType = "application/pdf"; //Define the file name. string fileName = " Output.pdf"; //Creates a FileContentResult object by using the file contents, content type, and file name. return(File(stream, contentType, fileName)); //return new ViewAsPdf("Details", _InvoiceList.ListInvoice(Id)); }
public void Email(Reports report) { HtmlToPdfConverter converter = new HtmlToPdfConverter(); WebKitConverterSettings settings = new WebKitConverterSettings(); settings.WebKitPath = Path.Combine(_hostingEnviroment.ContentRootPath, "QtBinariesWindows"); converter.ConverterSettings = settings; String Id = (report.ReportId).ToString(); PdfDocument document = converter.Convert("https://*****:*****@gmail.com", "*******"); client.Send(message); client.Disconnect(true); } }
//Html to PDF public ActionResult PDF() { //Initialize the HTML to PDF converter HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit); WebKitConverterSettings settings = new WebKitConverterSettings(); //Set WebKit path settings.WebKitPath = @"D:/Data/7th Semester/IPT/Project/WEB APP/SmartPOS_CRUD/packages/Syncfusion.HtmlToPdfConverter.QtWebKit.AspNet.17.3.0.26/lib/QtBinaries"; //Assign WebKit settings to HTML converter htmlConverter.ConverterSettings = settings; //Convert URL to PDF PdfDocument document = htmlConverter.Convert("http://localhost:62054/Cart/Invoice"); //Save and close the PDF document document.Save("D:/Data/7th Semester/IPT/Project/WEB APP/SmartPOS_CRUD/Output.pdf"); document.Close(true); return(RedirectToAction("Index")); }
public FileStreamResult Download(Reports report) { HtmlToPdfConverter converter = new HtmlToPdfConverter(); WebKitConverterSettings settings = new WebKitConverterSettings(); settings.WebKitPath = Path.Combine(_hostingEnviroment.ContentRootPath, "QtBinariesWindows"); converter.ConverterSettings = settings; String Id = (report.ReportId).ToString(); PdfDocument document = converter.Convert("https://localhost:44381/Report/Email?reportId=" + Id); //PdfDocument document = converter.Convert("https://i.stack.imgur.com/xhzgN.png"); MemoryStream ms = new MemoryStream(); document.Save(ms); document.Close(true); ms.Position = 0; FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf") { FileDownloadName = "Report.pdf" }; return(fileStreamResult); }
public IActionResult PostRelatorio([FromBody] RelatorioFinalObjectDTO relatorioFinalObjectDTO) { Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development"); //Initialize HTML to PDF converter HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); WebKitConverterSettings settings = new WebKitConverterSettings(); string htmlText = relatorioAluno(relatorioFinalObjectDTO); string baseUrl = string.Empty; //Set WebKit path settings.WebKitPath = Path.Combine(_hostingEnvironment.ContentRootPath, "QtBinariesLinux"); //Assign WebKit settings to HTML converter htmlConverter.ConverterSettings = settings; //Convert HTML string to PDF PdfDocument document = htmlConverter.Convert(htmlText, baseUrl);//"http://www.google.com"); //Save the document into stream MemoryStream stream = new MemoryStream(); document.Save(stream); stream.Position = 0; //Close the document document.Close(true); //Defining the ContentType for pdf file string contentType = "application/pdf"; //Define the file name string fileName = "Output.pdf"; //Creates a FileContentResult object by using the file contents, content type, and file name return(File(stream, contentType, fileName)); }
public IActionResult GeneratePDFReportCard(int id) { HtmlToPdfConverter converter = new HtmlToPdfConverter(); WebKitConverterSettings settings = new WebKitConverterSettings(); settings.WebKitPath = Path.Combine(_hostingEnvironment.ContentRootPath, "QtBinariesWindows"); converter.ConverterSettings = settings; PdfDocument document = converter.Convert("https://localhost:44349/reviewer/GetScoreCard/" + id.ToString()); MemoryStream ms = new MemoryStream(); document.Save(ms); document.Close(true); ms.Position = 0; FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf"); fileStreamResult.FileDownloadName = "ScoreCard.pdf"; return(fileStreamResult); }
public IActionResult Index() { HtmlToPdfConverter converter = new HtmlToPdfConverter(); WebKitConverterSettings settings = new WebKitConverterSettings(); settings.WebKitPath = Path.Combine(Environment.CurrentDirectory, "QtBinariesWindows"); converter.ConverterSettings = settings; string path = "https://localhost:44347/Invoice/ShowInvoice?OrderId=2015"; PdfDocument document = converter.Convert("https://www.google.com"); MemoryStream ms = new MemoryStream(); document.Save(ms); document.Close(true); ms.Position = 0; FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf"); fileStreamResult.FileDownloadName = "CHUJ.pdf"; return(fileStreamResult); }
public IActionResult ExportToPDF() { //Initialize HTML to PDF converter HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit); WebKitConverterSettings settings = new WebKitConverterSettings(); //Set WebKit path settings.WebKitPath = Path.Combine(WebHostEnvironment.ContentRootPath, "QtBinariesWindows"); //Assign WebKit settings to HTML converter htmlConverter.ConverterSettings = settings; //Convert URL to PDF PdfDocument document = htmlConverter.Convert("https://www.google.com"); //Saving the PDF to the MemoryStream MemoryStream stream = new MemoryStream(); document.Save(stream); //Download the PDF document in the browser return(File(stream.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf, "Output.pdf")); }
static void Main(string[] args) { HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); WebKitConverterSettings settings = new WebKitConverterSettings(); //Set WebKit path settings.WebKitPath = "QtBinariesLinux"; //Assign WebKit settings to HTML converter htmlConverter.ConverterSettings = settings; //Convert URL to PDF PdfDocument document = htmlConverter.Convert("https://www.google.com.co/?gws_rd=ssl"); FileStream fileStream = new FileStream("Sample.pdf", FileMode.CreateNew, FileAccess.ReadWrite); MemoryStream stream = new MemoryStream(); document.Save(stream); var aaa = 2; //Save and close the PDF document //document.Save(fileStream); //document.Close(true); }
public byte[] RenderViewToPdf(string html, string basePath, string baseUrl) { //Register Syncfusion license Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("MTA3NjkwQDMxMzcyZTMxMmUzMGRpNUF0QThQTklxRFlMeDhXR3NRZFlHcnU4VjN5Z2tGS3FaT2sxM1hER1E9;MTA3NjkxQDMxMzcyZTMxMmUzMFVqQ0tFMGcxclFlNUVKVUJtdWpGcWlmQ1gvbE9PMGxZYWxHTFZYSmxHZDQ9;MTA3NjkyQDMxMzcyZTMxMmUzMEZMTENrQjNCYjUvNmtKTHFNRHBGRkxXVlFXNGZReDVrbWl2WXZsczFORlk9;MTA3NjkzQDMxMzcyZTMxMmUzME5MY3VCaXEydmZyS085RmhzdWtMK2pjNE4wQmY1RUZxMHorMHhHZGlpOFU9;MTA3Njk0QDMxMzcyZTMxMmUzMERPVCtOWHBlT0NZVkM5aExMOUhtL3JMdDFyMWcySEl1cGdlZjBubm1wQW89;MTA3Njk1QDMxMzcyZTMxMmUzMFM5YmYyTDhoL1N4Z2RIeEZ4S1p6KzF5eGxkdkp2VDNIMFpkZHBwYWVndFE9;MTA3Njk2QDMxMzcyZTMxMmUzMEtFZTNrcnBaelBHUXg4TC9kdGE0TjVQTHNIVVloTDZ3N1I4VHQ0NysvTEE9;MTA3Njk3QDMxMzcyZTMxMmUzMExlamxrNmhmL0RyR3Y2QzBoYitxOXhyazRnR0JZUUJBZThJZmhENG1oVGs9;MTA3Njk4QDMxMzcyZTMxMmUzMGRrTFo4clJIR29kZEZrdlRSUlFsQ3VvckJGRjNiZCtscFNYbE0zRThQSGc9;MTA3Njk5QDMxMzcyZTMxMmUzMERPVCtOWHBlT0NZVkM5aExMOUhtL3JMdDFyMWcySEl1cGdlZjBubm1wQW89"); HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit); WebKitConverterSettings settings = new WebKitConverterSettings { WebKitPath = basePath, SinglePageLayout = Syncfusion.Pdf.HtmlToPdf.SinglePageLayout.FitWidth }; htmlConverter.ConverterSettings = settings; PdfDocument document = htmlConverter.Convert(html, baseUrl); MemoryStream memoryStream = new MemoryStream(); document.Save(memoryStream); byte[] bytes = memoryStream.ToArray(); memoryStream.Close(); document.Close(); return(bytes); }
public IActionResult RelatorioProfessor([FromBody] List <RelatorioFinalObjectDTO> dTO) { StringBuilder stringB = new StringBuilder(); foreach (var item in dTO) { var perguntas = item.Perguntas.ToArray(); var respostas = item.Resposta.ToArray(); var porcentagem = ((respostas.Where(x => x.Acertou).Count() * 100) / 10); stringB.Append(@"<html> <head> <meta charset='UTF-8'> <style> body{width:80%;position:relative;left:10%} p{font-family: 'Roboto', sans-serif;font-size:2em;text-align:center} th, td {bz'order: 1px solid black;} </style> <link rel='preconnect' href='https://fonts.gstatic.com'> <link href='https://fonts.googleapis.com/css2?family=Dancing+Script&family=Roboto&display=swap' rel='stylesheet'> </head> <body> <p>Parabéns por finalizar o quizz Web</p>" + $"<p>{item.NomeAluno}</p>" + @"<br> <h5>Rendimento:</h5> <table border='1' style='width:100%'> <tr> <th>Pergunta</th> <th>Situacao da Resposta</th> <th>Resposta</th> <th>Pontuacao</th> <th>Resposta Certa</th> </tr> <tr style='text-align:center;'>" + $"<td>{perguntas[0].Descricao}</td>" + $"<td>{(respostas[0].Acertou == true ? "Acertou":"Errou")}</td>" + $"<td>{respostas[0].Descricao}</td>" + $"<td>{respostas[0].Valor}</td>" + $"<td>{perguntas[0].OpcaoCerta}</td>" + "</tr>" + " <tr style='text-align:center;'>" + $"<td>{perguntas[1].Descricao}</td>" + $"<td>{(respostas[1].Acertou == true ? "Acertou":"Errou")}</td>" + $"<td>{respostas[1].Descricao}</td>" + $"<td>{respostas[1].Valor}</td>" + $"<td>{perguntas[1].OpcaoCerta}</td>" + "</tr>" + " <tr style='text-align:center;'>" + $"<td>{perguntas[2].Descricao}</td>" + $"<td>{(respostas[2].Acertou == true ? "Acertou":"Errou")}</td>" + $"<td>{respostas[2].Descricao}</td>" + $"<td>{respostas[2].Valor}</td>" + $"<td>{perguntas[2].OpcaoCerta}</td>" + "</tr>" + " <tr style='text-align:center;'>" + $"<td>{perguntas[3].Descricao}</td>" + $"<td>{(respostas[3].Acertou == true ? "Acertou":"Errou")}</td>" + $"<td>{respostas[3].Descricao}</td>" + $"<td>{respostas[3].Valor}</td>" + $"<td>{perguntas[3].OpcaoCerta}</td>" + "</tr>" + " <tr style='text-align:center;'>" + $"<td>{perguntas[4].Descricao}</td>" + $"<td>{(respostas[4].Acertou == true ? "Acertou":"Errou")}</td>" + $"<td>{respostas[4].Descricao}</td>" + $"<td>{respostas[4].Valor}</td>" + $"<td>{perguntas[4].OpcaoCerta}</td>" + "</tr>" + " <tr style='text-align:center;'>" + $"<td>{perguntas[5].Descricao}</td>" + $"<td>{(respostas[5].Acertou == true ? "Acertou":"Errou")}</td>" + $"<td>{respostas[5].Descricao}</td>" + $"<td>{respostas[5].Valor}</td>" + $"<td>{perguntas[5].OpcaoCerta}</td>" + "</tr>" + " <tr style='text-align:center;'>" + $"<td>{perguntas[6].Descricao}</td>" + $"<td>{(respostas[6].Acertou == true ? "Acertou":"Errou")}</td>" + $"<td>{respostas[6].Descricao}</td>" + $"<td>{respostas[6].Valor}</td>" + $"<td>{perguntas[6].OpcaoCerta}</td>" + "</tr>" + " <tr style='text-align:center;'>" + $"<td>{perguntas[7].Descricao}</td>" + $"<td>{(respostas[7].Acertou == true ? "Acertou":"Errou")}</td>" + $"<td>{respostas[7].Descricao}</td>" + $"<td>{respostas[7].Valor}</td>" + $"<td>{perguntas[7].OpcaoCerta}</td>" + "</tr>" + " <tr style='text-align:center;'>" + $"<td>{perguntas[8].Descricao}</td>" + $"<td>{(respostas[8].Acertou == true ? "Acertou":"Errou")}</td>" + $"<td>{respostas[8].Descricao}</td>" + $"<td>{respostas[8].Valor}</td>" + $"<td>{perguntas[8].OpcaoCerta}</td>" + "</tr>" + " <tr style='text-align:center;'>" + $"<td>{perguntas[9].Descricao}</td>" + $"<td>{(respostas[9].Acertou == true ? "Acertou":"Errou")}</td>" + $"<td>{respostas[9].Descricao}</td>" + $"<td>{respostas[9].Valor}</td>" + $"<td>{perguntas[9].OpcaoCerta}</td>" + "</tr>" + $@" </table> <h3>Porcentagem de acerto : {porcentagem} % </h3> </body> </html>"); } Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development"); //Initialize HTML to PDF converter HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); WebKitConverterSettings settings = new WebKitConverterSettings(); string htmlText = stringB.ToString(); string baseUrl = string.Empty; //Set WebKit path settings.WebKitPath = Path.Combine(_hostingEnvironment.ContentRootPath, "QtBinariesLinux"); //Assign WebKit settings to HTML converter htmlConverter.ConverterSettings = settings; //Convert HTML string to PDF PdfDocument document = htmlConverter.Convert(htmlText, baseUrl);//"http://www.google.com"); //Save the document into stream MemoryStream stream = new MemoryStream(); document.Save(stream); stream.Position = 0; //Close the document document.Close(true); //Defining the ContentType for pdf file string contentType = "application/pdf"; //Define the file name string fileName = "Output.pdf"; //Creates a FileContentResult object by using the file contents, content type, and file name return(File(stream, contentType, fileName)); }
public IActionResult pdf(int id) { //Initialize HTML to PDF converter HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); WebKitConverterSettings settings = new WebKitConverterSettings(); //Set WebKit path settings.WebKitPath = Path.Combine(hosting.ContentRootPath, "QtBinariesWindows"); //Assign WebKit settings to HTML converter htmlConverter.ConverterSettings = settings; //Convert URL to PDF Application mrki = _db.Application.Where(a => a.ApplicationId == id).Include(b => b.Applicant).ThenInclude(c => c.ApplicationUser).Include(d => d.Infos).ThenInclude(q => q.Citizenship).Include(e => e.HomeInstitutions).Include(f => f.Languages).Include(g => g.Contacts).ThenInclude(z => z.Country).Include(h => h.Documents).Include(i => i.Others).FirstOrDefault(); PdfDocument pdfDocument = new PdfDocument(); //Add a page to the PDF document. PdfPage pdfPage = pdfDocument.Pages.Add(); PdfPage pdfPage2 = pdfDocument.Pages.Add(); //Create a PDF Template. PdfTemplate template = new PdfTemplate(900, 900); PdfTemplate template2 = new PdfTemplate(900, 900); //Draw a rectangle on the template graphics template.Graphics.DrawRectangle(PdfBrushes.White, new Syncfusion.Drawing.RectangleF(0, 0, 900, 900)); template2.Graphics.DrawRectangle(PdfBrushes.White, new Syncfusion.Drawing.RectangleF(0, 0, 900, 900)); PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12); PdfFont font2 = new PdfStandardFont(PdfFontFamily.Helvetica, 20); PdfFont font3 = new PdfStandardFont(PdfFontFamily.Helvetica, 16); PdfBrush brush = new PdfSolidBrush(Color.Black); //Draw a string using the graphics of the template. RectangleF bounds = new RectangleF(0, 0, pdfDocument.Pages[0].GetClientSize().Width, 52); PdfPageTemplateElement header = new PdfPageTemplateElement(bounds); //Load the PDF document FileStream imageStream = new FileStream("unmo_logo.png", FileMode.Open, FileAccess.Read); PdfImage image = new PdfBitmap(imageStream); //Draw the image in the header. header.Graphics.DrawImage(image, new PointF(75, 0), new SizeF(137, 52)); header.Graphics.DrawString("Application number " + mrki.ApplicationId, font2, brush, 205, 12); //Add the header at the top. pdfDocument.Template.Top = header; template.Graphics.DrawString("About", font3, brush, 10, 17); template.Graphics.DrawString("Full name: ", font, brush, 32, 42); template.Graphics.DrawString(mrki.Applicant.ApplicationUser.Name + " " + mrki.Applicant.ApplicationUser.Surname, font, brush, 280, 42); template.Graphics.DrawString("Account created: ", font, brush, 32, 57); template.Graphics.DrawString(mrki.Applicant.CreatedProfile.ToString(), font, brush, 280, 57); template.Graphics.DrawString("Application created: ", font, brush, 32, 72); template.Graphics.DrawString(mrki.CreatedApp.ToString(), font, brush, 280, 72); template.Graphics.DrawString("Application submitted: ", font, brush, 32, 87); template.Graphics.DrawString(mrki.FinishedTime.ToString(), font, brush, 280, 87); template.Graphics.DrawString("Information", font3, brush, 10, 107); template.Graphics.DrawString("Gender: ", font, brush, 32, 132); template.Graphics.DrawString(mrki.Infos.Gender, font, brush, 280, 132); template.Graphics.DrawString("Date of birth: ", font, brush, 32, 149); template.Graphics.DrawString(mrki.Infos.DateOfBirth.ToShortDateString(), font, brush, 280, 149); template.Graphics.DrawString("Place of birth: ", font, brush, 32, 166); template.Graphics.DrawString(mrki.Infos.PlaceOfBirth.ToString(), font, brush, 280, 166); template.Graphics.DrawString("Citizenship: ", font, brush, 32, 183); template.Graphics.DrawString(mrki.Infos.Citizenship.Name.ToString(), font, brush, 280, 183); template.Graphics.DrawString("Passport number: ", font, brush, 32, 200); template.Graphics.DrawString(mrki.Infos.PassportNumber.ToString(), font, brush, 280, 200); template.Graphics.DrawString("Passport issue date: ", font, brush, 32, 217); template.Graphics.DrawString(mrki.Infos.PassportIssueDate.ToShortDateString(), font, brush, 280, 217); template.Graphics.DrawString("Passport expiry date: ", font, brush, 32, 234); template.Graphics.DrawString(mrki.Infos.PassportExpiryDate.ToShortDateString(), font, brush, 280, 234); template.Graphics.DrawString("Contacts", font3, brush, 10, 259); template.Graphics.DrawString("E-mail: ", font, brush, 32, 284); template.Graphics.DrawString(mrki.Contacts.Email.ToString(), font, brush, 280, 284); template.Graphics.DrawString("Phone number: ", font, brush, 32, 301); template.Graphics.DrawString(mrki.Contacts.Telephone.ToString(), font, brush, 280, 301); template.Graphics.DrawString("Street name: ", font, brush, 32, 318); template.Graphics.DrawString(mrki.Contacts.StreetName.ToString(), font, brush, 280, 318); template.Graphics.DrawString("City, town, village: ", font, brush, 32, 335); template.Graphics.DrawString(mrki.Contacts.PlaceName.ToString(), font, brush, 280, 335); template.Graphics.DrawString("Postal code: ", font, brush, 32, 352); template.Graphics.DrawString(mrki.Contacts.PostalCode.ToString(), font, brush, 280, 352); template.Graphics.DrawString("Country of residence: ", font, brush, 32, 369); template.Graphics.DrawString(mrki.Contacts.Country.Name.ToString(), font, brush, 280, 369); template.Graphics.DrawString("Languages", font3, brush, 10, 394); template.Graphics.DrawString("Native language: ", font, brush, 32, 419); template.Graphics.DrawString(mrki.Languages.Native.ToString(), font, brush, 280, 419); template.Graphics.DrawString("First foreign language: ", font, brush, 32, 436); string ff = mrki.Languages.ForeignFirst + " | " + mrki.Languages.ForeignFirstProficiency; template.Graphics.DrawString(ff, font, brush, 280, 436); template.Graphics.DrawString("Second foreign language: ", font, brush, 32, 453); string sf = mrki.Languages.ForeignSecond + " | " + mrki.Languages.ForeignSecondProficiency; template.Graphics.DrawString(sf, font, brush, 280, 453); template.Graphics.DrawString("Third foreign language: ", font, brush, 32, 470); string tf = mrki.Languages.ForeignThird + " | " + mrki.Languages.ForeignThirdProficiency; template.Graphics.DrawString(tf, font, brush, 280, 470); template.Graphics.DrawString("Number of foreign experiences: ", font, brush, 32, 487); template.Graphics.DrawString(mrki.Languages.ForeignExperienceNumber.ToString(), font, brush, 280, 487); template.Graphics.DrawString("Home institution", font3, brush, 10, 512); template.Graphics.DrawString("University: ", font, brush, 32, 537); template.Graphics.DrawString(mrki.HomeInstitutions.OfficialName.ToString(), font, brush, 280, 537); //template.Graphics.DrawString("Faculty: ", font, brush, 5, 335); //template.Graphics.DrawString(mrki.Applicant.FacultyName.ToString(), font, brush, 280, 335); template.Graphics.DrawString("Department name: ", font, brush, 32, 554); template.Graphics.DrawString(mrki.HomeInstitutions.DepartmentName.ToString(), font, brush, 280, 554); template.Graphics.DrawString("Study programme: ", font, brush, 32, 571); template.Graphics.DrawString(mrki.HomeInstitutions.StudyProgramme.ToString(), font, brush, 280, 571); template.Graphics.DrawString("Study cycle: ", font, brush, 32, 588); template.Graphics.DrawString(mrki.Applicant.StudyCycle, font, brush, 280, 588); template.Graphics.DrawString("Current term/year: ", font, brush, 32, 605); template.Graphics.DrawString(mrki.HomeInstitutions.CurrentTermOrYear.ToString(), font, brush, 280, 605); template.Graphics.DrawString("Coordinator full name: ", font, brush, 32, 622); template.Graphics.DrawString(mrki.HomeInstitutions.CoordinatorFullName.ToString(), font, brush, 280, 622); template.Graphics.DrawString("Coordinator e-mail: ", font, brush, 32, 639); template.Graphics.DrawString(mrki.HomeInstitutions.CoordinatorEmail.ToString(), font, brush, 280, 639); template.Graphics.DrawString("Coordinator phone number: ", font, brush, 32, 656); template.Graphics.DrawString(mrki.HomeInstitutions.CoordinatorPhoneNum.ToString(), font, brush, 280, 656); template.Graphics.DrawString("Coordinator address: ", font, brush, 32, 673); template.Graphics.DrawString(mrki.HomeInstitutions.CoordinatorAddress.ToString(), font, brush, 280, 673); template.Graphics.DrawString("Coordinator position: ", font, brush, 32, 690); template.Graphics.DrawString(mrki.HomeInstitutions.CoordinatorPosition.ToString(), font, brush, 280, 690); template2.Graphics.DrawString("Others", font3, brush, 10, 5); template2.Graphics.DrawString("Medical info: ", font, brush, 32, 30); template2.Graphics.DrawString(mrki.Others.MedicalInfo.ToString(), font, brush, 280, 30); template2.Graphics.DrawString("Additional requests: ", font, brush, 32, 47); template2.Graphics.DrawString(mrki.Others.AdditionalRequests.ToString(), font, brush, 280, 47); var path1 = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot\\uploads\\", mrki.Documents.LearningAgreement); var path2 = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot\\uploads\\", mrki.Documents.CV); var path3 = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot\\uploads\\", mrki.Documents.EngProficiency); var path4 = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot\\uploads\\", mrki.Documents.TranscriptOfRecords); var path5 = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot\\uploads\\", mrki.Documents.MotivationLetter); var path6 = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot\\uploads\\", mrki.Documents.ReferenceLetter); FileStream stream1 = new FileStream(path1, FileMode.Open, FileAccess.Read); FileStream stream2 = new FileStream(path2, FileMode.Open, FileAccess.Read); FileStream stream3 = new FileStream(path3, FileMode.Open, FileAccess.Read); FileStream stream4 = new FileStream(path4, FileMode.Open, FileAccess.Read); FileStream stream5 = new FileStream(path5, FileMode.Open, FileAccess.Read); //FileStream stream6 = new FileStream(path6, FileMode.Open, FileAccess.Read); // Creates a PDF stream for merging Stream[] streams = { stream1, stream2, stream3, stream4, stream5 };// stream6 }; // Merges PDFDocument. PdfDocumentBase.Merge(pdfDocument, streams); ////Draw the template on the page graphics of the document. pdfPage.Graphics.DrawPdfTemplate(template, PointF.Empty); pdfPage2.Graphics.DrawPdfTemplate(template2, PointF.Empty); //Save the document into stream MemoryStream stream = new MemoryStream(); pdfDocument.Save(stream); stream.Position = 0; pdfDocument.Close(true); //Define the file name FileStreamResult nova = new FileStreamResult(stream, "application/pdf"); string nameOfFile = "Application_" + mrki.ApplicationId + "_" + mrki.Applicant.ApplicationUser.Name + "_" + mrki.Applicant.ApplicationUser.Surname + ".pdf"; nova.FileDownloadName = nameOfFile; return(nova); }
public IActionResult pdf(int id) { //Initialize HTML to PDF converter HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); WebKitConverterSettings settings = new WebKitConverterSettings(); //Set WebKit path settings.WebKitPath = Path.Combine(hosting.ContentRootPath, "QtBinariesWindows"); //Assign WebKit settings to HTML converter htmlConverter.ConverterSettings = settings; //Convert URL to PDF Nomination mrki = _db.Nomination.Where(a => a.NominationId == id).Include(b => b.Applicant).ThenInclude(q => q.University).Include(b => b.Applicant).ThenInclude(c => c.ApplicationUser).ThenInclude(x => x.Country).FirstOrDefault(); PdfDocument pdfDocument = new PdfDocument(); //Add a page to the PDF document. PdfPage pdfPage = pdfDocument.Pages.Add(); //Create a PDF Template. PdfTemplate template = new PdfTemplate(900, 900); //Draw a rectangle on the template graphics template.Graphics.DrawRectangle(PdfBrushes.White, new Syncfusion.Drawing.RectangleF(0, 0, 900, 900)); PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12); PdfFont font2 = new PdfStandardFont(PdfFontFamily.Helvetica, 20); PdfFont font3 = new PdfStandardFont(PdfFontFamily.Helvetica, 16); PdfBrush brush = new PdfSolidBrush(Color.Black); //Draw a string using the graphics of the template. RectangleF bounds = new RectangleF(0, 0, pdfDocument.Pages[0].GetClientSize().Width, 52); //dirao PdfPageTemplateElement header = new PdfPageTemplateElement(bounds); //Load the PDF document FileStream imageStream = new FileStream("unmo_logo.png", FileMode.Open, FileAccess.Read); PdfImage image = new PdfBitmap(imageStream); //Draw the image in the header. header.Graphics.DrawImage(image, new PointF(75, 0), new SizeF(137, 52)); header.Graphics.DrawString("Nomination number " + mrki.NominationId, font2, brush, 205, 12); //Add the header at the top. pdfDocument.Template.Top = header; template.Graphics.DrawString("Full name: ", font, brush, 32, 15); template.Graphics.DrawString(mrki.Applicant.ApplicationUser.Name + " " + mrki.Applicant.ApplicationUser.Surname, font, brush, 280, 15); template.Graphics.DrawString("Account created: ", font, brush, 32, 30); template.Graphics.DrawString(mrki.Applicant.CreatedProfile.ToString(), font, brush, 280, 30); template.Graphics.DrawString("Nomination created: ", font, brush, 32, 45); template.Graphics.DrawString(mrki.CreatedNom.ToString(), font, brush, 280, 45); template.Graphics.DrawString("Nomination submitted: ", font, brush, 32, 60); template.Graphics.DrawString(mrki.FinishedTime.ToString(), font, brush, 280, 60); template.Graphics.DrawString("Information", font3, brush, 10, 87); template.Graphics.DrawString("E-mail: ", font, brush, 32, 112); template.Graphics.DrawString(mrki.Applicant.ApplicationUser.Email.ToString(), font, brush, 280, 112); template.Graphics.DrawString("Phone number: ", font, brush, 32, 127); template.Graphics.DrawString(mrki.Applicant.ApplicationUser.PhoneNumber.ToString(), font, brush, 280, 127); template.Graphics.DrawString("Nationality: ", font, brush, 32, 142); template.Graphics.DrawString(mrki.Applicant.ApplicationUser.Country.Name.ToString(), font, brush, 280, 142); template.Graphics.DrawString("Faculty: ", font, brush, 32, 157); template.Graphics.DrawString(mrki.Applicant.FacultyName.ToString(), font, brush, 280, 157); template.Graphics.DrawString("University: ", font, brush, 32, 172); template.Graphics.DrawString(mrki.Applicant.University.Name.ToString(), font, brush, 280, 172); template.Graphics.DrawString("Student/staff: ", font, brush, 32, 187); template.Graphics.DrawString(mrki.Applicant.TypeOfApplication.ToString(), font, brush, 280, 187); var path1 = ""; if (mrki.LearningAgreement != null) { path1 = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\uploads\\", mrki.LearningAgreement); } else if (mrki.WorkPlan != null) { path1 = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\uploads\\", mrki.WorkPlan); } var path2 = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot\\uploads\\", mrki.CV); var pathx = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot\\uploads\\", mrki.Passport); var path3 = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot\\uploads\\", mrki.EngProficiency); var path4 = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot\\uploads\\", mrki.TranscriptOfRecords); var path5 = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot\\uploads\\", mrki.MotivationLetter); var path6 = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot\\uploads\\", mrki.ReferenceLetter); FileStream stream1 = new FileStream(path1, FileMode.Open, FileAccess.Read); FileStream stream2 = new FileStream(path2, FileMode.Open, FileAccess.Read); FileStream streamx = new FileStream(pathx, FileMode.Open, FileAccess.Read); FileStream stream3 = new FileStream(path3, FileMode.Open, FileAccess.Read); FileStream stream4 = new FileStream(path4, FileMode.Open, FileAccess.Read); FileStream stream5 = new FileStream(path5, FileMode.Open, FileAccess.Read); // Creates a PDF stream for merging Stream[] streams = { stream1, stream2, stream3, streamx, stream4, stream5 }; // Merges PDFDocument. PdfDocumentBase.Merge(pdfDocument, streams); ////Draw the template on the page graphics of the document. pdfPage.Graphics.DrawPdfTemplate(template, PointF.Empty); //Save the document into stream MemoryStream stream = new MemoryStream(); pdfDocument.Save(stream); stream.Position = 0; pdfDocument.Close(true); //Define the file name FileStreamResult nova = new FileStreamResult(stream, "nomination/pdf"); string nameOfFile = "Nomination_" + mrki.NominationId + "_" + mrki.Applicant.ApplicationUser.Name + "_" + mrki.Applicant.ApplicationUser.Surname + ".pdf"; nova.FileDownloadName = nameOfFile; return(nova); }