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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:15:49+00:00 2026-05-16T14:15:49+00:00

I have been trying to generate simple PDFs from my app so that I

  • 0

I have been trying to generate simple PDFs from my app so that I can later move on to generating PDF with dynamic data. My code generates the files but I want a way to also have the browser prompt the download of the file.

I actually don’t even want to store generated files on my server but I’m not sure how to get it to just provide it to the user without first storing it in the server drive.

public ActionResult GetPDF()
{
    Document document = new Document();
    PdfWriter.GetInstance(document, new FileStream(Server.MapPath("../Content/test.pdf"), FileMode.Create));
    document.Open();
    string strHTML = "<B>I Love ASP.Net!</B>";
    HTMLWorker htmlWorker = new HTMLWorker(document);
    htmlWorker.Parse(new StringReader(strHTML));
    document.Close();

    return File(document, "application/pdf", Server.HtmlEncode(filename));//this doesnt work, obviously
}
  • 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-16T14:15:50+00:00Added an answer on May 16, 2026 at 2:15 pm

    Use a FileStreamResult Action

    public FileStreamResult Export(int? ID)
    {        
        MemoryStream stream = new MemoryStream();
    
        //Start of PDF work using iTextSharp PDF library
        Document pdf = new Document();
        PdfWriter writer = PdfWriter.GetInstance(pdf, stream);    
        pdf.Open();    
        pdf.Add(new Phrase("test"));    
        pdf.Close();
        //End of PDF work using iTextSharp PDF library
    
        //Where the download magic happens
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=Log.pdf");
        Response.Buffer = true;
        Response.Clear();
        Response.OutputStream.Write(stream.GetBuffer(), 0, stream.GetBuffer().Length);
        Response.OutputStream.Flush();
        Response.End();
    
        return new FileStreamResult(Response.OutputStream, "application/pdf");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an iPad app and I'm trying to generate a PDF from a
I've been trying to do a simple restful wcf service that will return JSON.
I have been trying to generate a QR code using Zxing. Following the minimal
I am trying to implement something seemingly very simple, and I have been beating
I am playing around with Audacity and have been trying to generate tones with
I have been trying to make a simple web service and have been following
I have been trying to convert a web project that produces a war file
Have have been trying to make a validator for my xml files. I have
I have been trying very hard to achieve rounded corners with IE6+jquery ui tabs.
I have been trying to us CALayers as sprites in an iPhone application I'm

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.