PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Wed Nov 25, 2020 2:45 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri Nov 06, 2020 3:03 pm 
Offline

Joined: Fri Nov 06, 2020 2:46 pm
Posts: 1
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.


Top
 Profile  
Reply with quote  
PostPosted: Mon Nov 09, 2020 9:04 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 592
Location: CCAA
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

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 25 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group