PDFsharp & MigraDoc Foundation http://forum.pdfsharp.com/ |
|
Generating PDF from MVC action returns blank document http://forum.pdfsharp.com/viewtopic.php?f=2&t=4198 |
Page 1 of 1 |
Author: | smitty [ Fri Nov 06, 2020 3:03 pm ] |
Post subject: | Generating PDF from MVC action returns blank document |
I'm attempting to generate a PDF in a controller action and return it to the browser. The document generates and I can open it, but it's just a blank page. Any idea what I'm doing wrong here? Code is below. Code: [HttpPost] public ActionResult Print() { PdfDocument doc = new PdfDocument(); PdfPage page = doc.AddPage(); page.Width = XUnit.FromInch(8.5); page.Height = XUnit.FromInch(11); XGraphics gfx = XGraphics.FromPdfPage(page); XSize size = gfx.PageSize; gfx.DrawString( "STUB", new XFont("Calibri", 60, XFontStyle.Regular), XBrushes.Black, new XRect(0, 0, size.Width, size.Height), XStringFormats.Center); FileContentResult response; using (MemoryStream stream = new MemoryStream()) { doc.Save(stream, false); response = new FileContentResult(stream.ToArray(), "application/pdf"); } return response; } This is using v 1.50.5147.0 of PDFSharp in a .NET 4.6.2 project. |
Author: | TH-Soft [ Mon Nov 09, 2020 9:04 am ] |
Post subject: | Re: Generating PDF from MVC action returns blank document |
Maybe just a small detail is missing. Here is a sample using ASP.NET: http://pdfsharp.net/wiki/Clock-sample.ashx Here is a sample using MVC and a different PDF library: https://daveaglick.com/posts/using-aspn ... -pdf-files |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |