Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5929259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:23:56+00:00 2026-05-22T14:23:56+00:00

My project is very similar to NerdDinner and I’m generating a pdf-document using PdfSharp.

  • 0

My project is very similar to NerdDinner and I’m generating a pdf-document using PdfSharp.

In my view I’m using this:

<%: Html.ActionLink("Pdf", "GeneratePdf1", "Persons")%>

Calling this ActionResult:

    public ActionResult GeneratePdf1()
    {
        // Create a new PDF document
        PdfDocument document = new PdfDocument();
        document.Info.Title = "Created with PDFsharp";

        // Create an empty page
        PdfPage page = document.AddPage();

        // Get an XGraphics object for drawing
        XGraphics gfx = XGraphics.FromPdfPage(page);

        // Create a font
        XFont font = new XFont("Verdana", 20, XFontStyle.BoldItalic);

        // Draw the text
        gfx.DrawString("Hello, World!", font, XBrushes.Black,
        new XRect(0, 0, page.Width, page.Height),
        XStringFormats.Center);

        // Save the document...
        const string filename = "HelloWorld.pdf";
        document.Save(filename);
        Process.Start(filename);
        return View();
    }  

A few questions/problems on this:

  • I don’t want the link to post. When you click the link it should just open the file, but I don’t know what to return to prevent it from posting.
  • I’d also like the “save/open” dialog to appear. Right now the pdf file is displayed directly.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:23:56+00:00Added an answer on May 22, 2026 at 2:23 pm

    You want to return a FileResult not an ActionResult. Also, I would save it to a MemoryStream and return the byte array, not use a file. Full solution below.

    public FileResult GeneratePdf1()
    {
        // Create a new PDF document
        PdfDocument document = new PdfDocument();
        document.Info.Title = "Created with PDFsharp";
    
        // Create an empty page
        PdfPage page = document.AddPage();
    
        // Get an XGraphics object for drawing
        XGraphics gfx = XGraphics.FromPdfPage(page);
    
        // Create a font
        XFont font = new XFont("Verdana", 20, XFontStyle.BoldItalic);
    
        // Draw the text
        gfx.DrawString("Hello, World!", font, XBrushes.Black,
        new XRect(0, 0, page.Width, page.Height),
        XStringFormats.Center);
    
    
        MemoryStream stream = new MemoryStream();
        document.Save(stream, false);
    
        return File(stream.ToArray(), "application/pdf");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Very similar to this question , I am trying to convert a project that
I am using config.autoload_paths in a way very similar to this related question to
I have generated a C# SharePoint Sequential Workflow project using the very handy STSDEV
I know there are other questions that are very similar to this, but their
Firstly, I realise that this is a very similar question to this one: Which
I'm working on an application that has a view hierarchy that is very similar
A very similar question, but not exact to those asked frequently; my project has
I'm interested in using Steve Sanderson’s MvcIntegrationTestFramework or a very similar alternative with ASP.NET
In my asp.net mvc3 (razor) project I have a grid very similar to the
I'm trying to use linq to sql for my project (very short deadline), and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.