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 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 async Task <IActionResult> Index(string MRecordId) { var MRecord = await _mRecordService.GetMedicalRecordById(MRecordId); if (MRecord.DateCompleted > 0) { MRecord.WasPrinted = true; await _mRecordRepository.UpdateMedicalRecord(Helper.AutoDTO <MedicalRecordModel, MedicalRecord>(MRecord)); var converter = new HtmlToPdfConverter(HtmlRenderingEngine.Blink); var settings = new BlinkConverterSettings(); settings.PdfPageSize = new SizeF(PdfPageSize.A4); settings.Margin.All = 20; settings.MediaType = MediaType.Print; settings.BlinkPath = Path.Combine(_env.ContentRootPath, "BlinkBinariesWindows"); converter.ConverterSettings = settings; string html = await _renderService.RenderToStringAsync <MedicalRecordModel> ("/Views/print/print.cshtml", MRecord); var document = converter.Convert(html, "~/css/print.css"); document.EnableMemoryOptimization = true; MemoryStream stream = new MemoryStream(); document.Save(stream); return(File(stream.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf, $"{MRecordId}.pdf")); } return(BadRequest()); }
/// <summary> /// Converts html to pdfs using pdfreactor /// </summary> /// <returns> collection of filenames</returns> public async Task <IEnumerable <UploadFile> > RenderPdfs(IFormFileCollection filesToConvert, CancellationToken cancellationToken) { var stopWatch = new Stopwatch(); stopWatch.Start(); var converter = new HtmlToPdfConverter(_config); //// create a temp directory var tmpDir = GetTemporaryDirectory(); var tasks = filesToConvert.AsParallel() .WithCancellation(cancellationToken) //.WithDegreeOfParallelism(5) .Select(async file => { var tmpFilePath = Path.Combine(tmpDir, file.FileName); using var fs1 = File.Create(tmpFilePath); await file.CopyToAsync(fs1, cancellationToken); fs1.Position = 0; fs1.Dispose(); var absUri = new Uri(tmpFilePath).AbsoluteUri; var bytes = await converter.Convert(absUri); return(new UploadFile { Name = Path.ChangeExtension(file.FileName, ".pdf"), blob = new MemoryStream(bytes) }); }); var filesToUpload = await Task.WhenAll(tasks); stopWatch.Stop(); _logger.LogInformation($"took {stopWatch.ElapsedMilliseconds/1000} sec"); // delete the directory TryDeleteDirectory(tmpDir); return(filesToUpload); }
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 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 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 void Should_Return_Non_Empty_ByteArray_When_Convert_Called_With_Empty_Body_Tag() { var sut = new HtmlToPdfConverter(); var pdfByteArray = sut.Convert("<body></body>"); Assert.IsNotNull(pdfByteArray); Assert.IsTrue(pdfByteArray.Length > 1000); }
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 void Should_Return_Non_Empty_ByteArray_When_Convert_Called() { var sut = new HtmlToPdfConverter(); var pdfByteArray = sut.Convert("<body style='font-size: 30px'>Test content</body>"); // var tempOutputPathname = $"{System.IO.Path.GetTempPath()}\\PdfCreatorTempOutput.pdf"; // File.WriteAllBytes(tempOutputPathname, pdfByteArray); // System.Diagnostics.Trace.WriteLine($"Pdf written to temp folder location: {tempOutputPathname}"); Assert.IsNotNull(pdfByteArray); Assert.IsTrue(pdfByteArray.Length > 5000); // Even a PDF with very little content should more than a few KB in length }
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)); }
private static PdfPageTemplateElement FooterHTMLtoPDF(string htmlString, float height) { var vpHeight = ConvertToViewPort(height); HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit); htmlConverter.ConverterSettings = CreateConverterSetting(vpHeight); //Convert Html to PDF PdfDocument document = htmlConverter.Convert(htmlString, string.Empty); System.Drawing.RectangleF bounds = new System.Drawing.RectangleF(0, 0, document.Pages[0].GetClientSize().Width, vpHeight); PdfPageTemplateElement footer = new PdfPageTemplateElement(bounds); footer.Graphics.DrawPdfTemplate(document.Pages[0].CreateTemplate(), bounds.Location, bounds.Size); return(footer); }
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)); } }
public IActionResult downloadAnalysis() { var url = "https://localhost:44374/User/getAnalysis?pdfview=1"; HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.Blink); BlinkConverterSettings settings = new BlinkConverterSettings(); settings.AdditionalDelay = 10000; settings.BlinkPath = Path.Combine(this._hostingEnvironment.ContentRootPath, "BlinkBinariesWindows"); htmlConverter.ConverterSettings = settings; PdfDocument document = htmlConverter.Convert(url); MemoryStream stream = new MemoryStream(); document.Save(stream); return(this.File(stream.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf, "Report.pdf")); }
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 Task <Result <byte[]> > GenerateProductPdfReport(ProductReportModel model) => Result <byte[]> .TryAsync(async() => { Result <IList <ProductModel> > result = await GetProductListFromDB(model); if (!result.Success) { return(Result <byte[]> .Failed(Error.WithCode(ErrorCodes.ErrorInProductReport))); } var productModels = result.Data; //Initialize HTML to PDF converter HtmlToPdfConverter htmlToPdfConverter = new HtmlToPdfConverter() { //Assign WebKit settings to HTML converter ConverterSettings = new WebKitConverterSettings { //Set WebKit path WebKitPath = $"{Directory.GetCurrentDirectory()}" + $"{Path.DirectorySeparatorChar}bin" + $"{Path.DirectorySeparatorChar}Debug" + $"{Path.DirectorySeparatorChar}netcoreapp3.1" + $"{Path.DirectorySeparatorChar}QtBinariesWindows" } }; string templatesPath = $"{Directory.GetCurrentDirectory()}" + $"{Path.DirectorySeparatorChar}wwwroot" + $"{Path.DirectorySeparatorChar}Resources" + $"{Path.DirectorySeparatorChar}ReportTemplates"; RazorLightEngine engine = new RazorLightEngineBuilder().UseFileSystemProject(templatesPath) .UseMemoryCachingProvider().Build(); string resultt = await engine.CompileRenderAsync("ProductPdfReport.cshtml", productModels); var pdfDocument = htmlToPdfConverter.Convert(resultt, $"www.google.com"); MemoryStream stream = new MemoryStream(); pdfDocument.Save(stream); _logger.Info("Product pdf report generated"); return(Result <byte[]> .Successful(stream.ToArray())); });
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); }
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); }