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 8873539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:29:24+00:00 2026-06-14T18:29:24+00:00

There is probably a simple answer to this question but I just can’t seem

  • 0

There is probably a simple answer to this question but I just can’t seem to find a solution.

So I’m currently generating a PDF using iTextSharp and sending this PDF back to the user on form submit. However, instead of sending this PDF in the response stream I’d like to render a link to the file i.e. “Thank you for submitting, click here to download the PDF”.

Looked at most iTextSharp questions on Stack but all relate to sending it via teh response stream.

Thanks

    [HttpPost]
    public ActionResult Index(FormCollection formCollection)
    {

        // Create PDF
        var doc = new Document();
        MemoryStream memoryStream = new MemoryStream();

        PdfWriter writer = PdfWriter.GetInstance(doc, memoryStream);

        doc.Open();
        doc.Add(new Paragraph("First Paragraph"));
        doc.Add(new Paragraph("Second Paragraph"));
        doc.Close();

        byte[] docData = memoryStream.GetBuffer(); // get the generated PDF as raw data

        // write the data to response stream and set appropriate headers:

        Response.AppendHeader("Content-Disposition", "attachment; filename=test.pdf");
        Response.ContentType = "application/pdf";
        Response.BinaryWrite(docData);

        Response.End();

        return View();

    }
  • 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-06-14T18:29:26+00:00Added an answer on June 14, 2026 at 6:29 pm

    This is totally independent of iTextSharp.

    You have to store the created byte array somewhere on your server and create another action to fetch that generated data later by some kind of an ID and serve it to the user.

    You can store in in the filesystem or just in the session or TempData.

    public ActionResult Index(FormCollection formCollection)
    {
        // Create PDF ...
        byte[] docData = memoryStream.GetBuffer(); 
        // create id and store data in Session
        string id = Guid.NewGuid().ToString();
        Session[id] = docData;
        return View("Index", id);
    }
    

    In the view Index.cshtml you set string as the modeltype and generate a donwload link:

    @model string
    @Html.ActionLink("Download pdf", "Download", "Controller", new { id = Model })
    

    And your new download action:

    public ActionResult Download(string id) {
        var docData = (byte[])Session[id];
    
        if (docData == null) 
          return HttpNotFound();
    
        // clear data from session
        Session[id] = null;
        // a simpler way of returning binary data with mvc
        return File(docData, "application/pdf", "test.pdf");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is probably a very simple answer to this question, but I can't for
There is probably a simple answer for this, but I couldn't find one, so
there is probably a very simple answer to this very simple question, but i
There is probably a simple answer to this question but I do not have
Simple question (probably), but I'm buggered if I can find an answer... I have
I feel like the answer to this question is probably very simple, but I'm
There's probably a Google search that'll answer this question but for the life of
All, This question probably has a very simple answer - something I'm overlooking. But
There's probably a simple answer to this, but I'm lost. I created my first
Well this is probably a stupid question with a simple answer but when using

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.