Acrobat Reader prompts for resaving the PDF

This forum contains a series of Technical Newsletters designed to share with our customers valuable information about implementing or using our products.
Post Reply
Devteam
Posts: 119
Joined: Fri Oct 14 2005
Location: Montreal
Contact:

Acrobat Reader prompts for resaving the PDF

Post by Devteam »

Related Products
Amyuni PDF Creator .Net, 32 and 64-bits.

Problem Description
When opening and resaving a PDF file through PDF Creator .Net, the resulting PDF file opens fine with Acrobat Reader (AR), but when the document is closed AR asks the users whether they want to save the modifications to the PDF file. This is usually an indication that there is something invalid in the PDF file. The file has been fixed with AR which is asking whether the fixed file should be resaved. This issue seems to be occurring randomly depending on the original PDF and the type of processing that was done.

Cause and Resolution
The most common cause for this issue is the use of the OpenOrCreate flag when creating the .Net stream that is used to save the PDF file. E.g.:

Code: Select all

// Warning: This code might create an INVALID PDF file
using ( var stream = new FileStream( FileName, FileMode.OpenOrCreate ) )
{
        pdfCreator.Document.Save( stream, IacFileSaveOption.acFileSaveView );
}
If the same file with the name "FileName" already exists, the file will not be truncated at the end of the PDF file stream. When the original PDF file is larger than the processed PDF, stray characters remain at the end of the file. The stray characters might or might not prevent AR from opening the file, but AR will try to remove them when closing the file.

To check if the this is the case with your PDF file, open the PDF with a text editor and search for the %%EOF token. If there are any characters after %%EOF, then you are probably facing this same situation.

Resolution
Replace the flag FileMode.OpenOrCreate by FileMode.Create.

The reason why this is not done within the PDF Creator product (e.g. truncating the stream at the end of the file) is that the stream object belongs to the calling application. It might be a file, a memory, a database or any other custom stream class. Forcing a truncation of the stream might cause undesirable effects in the host application.
Amyuni Development Team

Efficient and accurate conversion to PDF, XPS, PDF/A and more. Free trials at - https://www.amyuni.com
Post Reply