A problem when resaving a buggy PDF document.

Q: We own a PDFTron license to enable us to alter PDF security and
save the modified file (among other functionality). We occasionally
get an error when we reach the Save() method on pdftron.SDF.Doc class:

Message: An error occurred while trying to save the file.
            The file might be locked, corrupt, or unavailable.

Further, the relevant code we use to call your library follows.
Again, everything works fine up to the Save call:

        public static void StripSecurityFromPDF(string inFile, string
outFile) {
            Doc doc = new Doc(inFile);
            //Blow away any security settings on the original doc:
            doc.SetSecurityHandler(null); // or doc.RemoveSecurity()
            doc.Save(outFile, 0, "%PDF-1.4");
A: The problem is that the input file is corrupt. The object
references 50 and 60 referenced in the top /Pages kids array do not
exist (among other issues). The application that generated this buggy
PDF is 'AFPL Ghostscript 8.50'. Please note that Acrobat Professional
also generates errors during save and will fail to resave this

It is possible to manually fix the document using CosEdit (http://
www.pdftron.com/cosedit/) however it may be a better idea to switch to
another PDF generator.