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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:20:31+00:00 2026-06-11T22:20:31+00:00

I’m using iTextSharp 5.3.2.0 to add information to an existing PDF file that contains

  • 0

I’m using iTextSharp 5.3.2.0 to add information to an existing PDF file that contains a W-2 form. Everything is working perfectly and the PDF file looks great when written into the browser’s response stream; however, when the user is done looking at the PDF, he is asked “Do you want to save changes to ‘W2.pdf’ before closing?” every time he views the document from the web page.

In trying to narrow the problem down, I’ve actually stripped out all of my modifications but the problem continues. Here’s the simple version of my code, with my data-writing call commented out:

PdfReader pdfReader = new PdfReader(dataSource.ReportTemplate);

using(MemoryStream outputStream = new MemoryStream())
using (PdfStamper pdfStamper = new PdfStamper(pdfReader, outputStream))
{
   //dataSource.DrawDataFields(pdfStamper);
   pdfStamper.FormFlattening = true;
   return outputStream;
}

In this case, the “empty” PDF is written to the browser and looks good, but I still get asked, “Do you want to save” when I close the Acrobat window.

At this point I was thinking that there was something wrong with the source PDF file. However, when I send back the PDF file’s raw bytes to the browser, I am NOT asked the “Do you want to save” question when using the code below.

byte[] bytes = File.ReadAllBytes(dataSource.ReportTemplate);

using (MemoryStream outputStream = new MemoryStream())
{
    outputStream.Write(bytes, 0, bytes.Length);
    return outputStream;
}

My conclusion is that iTextSharp is doing something “bad” to the PDF in the process of opening it and writing the bytes to the stream, but I’m new to iTextSharp and could easily be missing something.

FWIW, this is Acobat Reader 10.1.4 that we’re talking about.

EDIT: The original PDF used as a template is approximately 80K in size. If I look at the temporary file that’s been streamed down through my browser, the PDF file written by iTextSharp is approximately 150K. However, when I answer “Yes” to the “Save Changes” question asked by Acrobat Reader, the resulting file is approximately 80K again. iTextSharp is definitely doing something unexpected to this file.

  • 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-11T22:20:33+00:00Added an answer on June 11, 2026 at 10:20 pm

    Non-working:

    public byte[] MergeDataByDrawing(int copies)
    {
        PdfReader pdfReader = new PdfReader(reportTemplate);
    
        using (MemoryStream outputStream = new MemoryStream())
        using (PdfStamper pdfStamper = new PdfStamper(pdfReader, outputStream))
        {
            pdfStamper.FormFlattening = true;
            return outputStream.GetBuffer();
        }
    } 
    

    Working:

    public byte[] MergeDataByDrawing(int copies)
    {
        PdfReader pdfReader = new PdfReader(reportTemplate);
    
        using (MemoryStream outputStream = new MemoryStream())
        using (PdfStamper pdfStamper = new PdfStamper(pdfReader, outputStream))
        {
            pdfStamper.FormFlattening = true;
            return outputStream.ToArray();
        }
    }
    

    Seems the GetBuffer method is a problem. I don’t understand why, but I’ll take the result!

    Props to MKL for giving me an idea and Fredrik for the right example at the right time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are using XSLT to translate a RIXML file to XML. Our RIXML contains
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.