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

  • Home
  • SEARCH
  • 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 632949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:07:55+00:00 2026-05-13T20:07:55+00:00

In an ASP.NET application, I’m using iTextSharp (PdfStamper, mostly) to fill in some content

  • 0

In an ASP.NET application, I’m using iTextSharp (PdfStamper, mostly) to fill in some content on a PDF and send it to the user. The following code is inside an OnClick event:

PdfReader r = new PdfReader(
  new RandomAccessFileOrArray(Request.MapPath(compatiblePdf)), null
);

ps = new PdfStamper(r, Response.OutputStream);
AcroFields af = ps.AcroFields;

af.SetField("ContactInfo[0]", o.mallName);
af.SetField("ClientName", string.Format("{0} {1}", c.firstName, c.lastName));
af.SetField("ClientEmail", c.emailAddress);
ps.FormFlattening = true;
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment; filename=Form.pdf");
ps.Close();
Response.End();

So, basically, PdfReader gets the file, PdfStamper takes the PdfReader as an argument, and will push its finished PDF to Response.OutputStream.

The problem is that, with IE and Adobe Reader, if you select “Open” from the file dialog, Adobe Reader throws an error saying “file could not be found”. Users can “Save” the file just fine, and even starting the download again (clicking “Open” again when asked) seems to work. But on a new machine that’s never downloaded the file, Adobe Reader seems to misplace the file between it going to the Temporary Files or whatever IE does.

I can only imagine one thing right now: Response.End(), should, maybe, be Response.Close() instead, or maybe the whole thing should have Response.Flush() before it. But I don’t know for sure that that won’t make the problem worse, and I’m having a hard time testing (because, once you’ve downloaded the file once, the error isn’t thrown again).

Might that fix the problem? Do I have something wrong in the headers? Or is there something else I should be doing with the Response / PdfStamper objects?

  • 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-13T20:07:55+00:00Added an answer on May 13, 2026 at 8:07 pm

    Whenever I force content at a user, I follow this set of steps for the Response:

    Response.Clear()
    Response.ClearHeaders()
    Response.Buffer = True
    Response.ContentType = "your mime type"
    Response.CacheControl = "public"
    Response.AddHeader("Pragma", "public")
    Response.AddHeader("Expires", "0")
    Response.AddHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0")
    Response.AddHeader("Content-Description", "Description of your content")
    Response.AddHeader("Content-Disposition", "attachment; filename=""somefile.pdf""")
    
    ' Add your content to the buffer here
    
    Response.Flush()
    Response.End()
    

    This seems to be pretty good at preventing all the “file not found” garbage.

    EDIT: For those interested in what these headers actually mean:

    1. Pragma: public helps control cache for backwards compatibility with HTTP/1.0 requests. It ensures that your request makes it to the server even if there’s already a cached response.
    2. Expires: 0 is an interval in seconds after which the response expires. Setting to 0 expires the response immediately, helping avoid a stale cache.
    3. Cache-control: must-revalidate tells the cache that it must obey your every command (i.e. it must give you a new response when you ask for it).
    4. Cache-control: post-check=0, pre-check=0: this is an interval in seconds that a response must be checked for freshness after/prior to (respectively) being served the content. Setting to 0 forces freshness of the response to be checked immediately. (More at MSDN.)
    5. The remainder are simply describing the content you want the user to receive. Specifying “attachment” tells the browser to offer the file as a download and to not display it inline.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The other answers are correct. Here is some code you… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer you ruin the noConflict concept by reassigning the jquery to… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer If you get that particular error, you don't actually have… May 14, 2026 at 9:40 am

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.