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.