Using iTextSharp to write data to PDF works fine, but Acrobat Reader asks “Do you want to save the changes” when closing the file

I am using iTextSharp 5.3.2.0 to add information to an existing PDF file containing the W-2 form. Everything works fine, and the PDF file looks great when writing to the browser response stream; however, when the user views the PDF file, he asks: "Do you want to save the changes to" W2.pdf "before closing?" every time he views a document from a web page.

In an attempt to narrow the problem down to the end, I actually stripped all my modifications, but the problem continues. Here's a simple version of my code when my data write request is 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;
}

"" PDF , : " ", Acrobat.

, - PDF. , PDF , " " .

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

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

, iTextSharp - "" PDF , iTextSharp - .

FWIW, Acobat Reader 10.1.4, .

EDIT: PDF , , 80K. , , PDF, iTextSharp, 150 . , "" " ", Acrobat Reader, 80K. iTextSharp - .

+5
2

:

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();
    }
} 

:

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();
    }
}

, GetBuffer . , , !

MKL , Fredrik .

+14

. http://itextpdf.com/history/?branch=52&node=521

Bugfix AcroForms: Adobe Reader X , " " PDF. /AcroForm ( , OOo).

- , . , Adobe Reader 10, Adobe Reader 9. , , , , PDF , .

PDF , , /AcroForm. , Open Office. PDF , .

+1

All Articles