PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon Jun 14, 2021 12:41 pm

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 

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.

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;
        new XFont("Calibri", 60, XFontStyle.Regular),
        new XRect(0, 0, size.Width, size.Height),

    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.

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

Joined: Sat Mar 14, 2015 10:15 am
Posts: 642
Location: CCAA
Maybe just a small detail is missing.

Here is a sample using ASP.NET:

Here is a sample using MVC and a different PDF library:
https://daveaglick.com/posts/using-aspn ... -pdf-files

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

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: Google [Bot] and 16 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