We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Opening Created PDF in Acrobat fails with "There was an error opening this document..."

We use Aspose to take scanned documents (PDFs) which we encrypt using Aspose before sending them out to clients. We have two different brands of scanner, Xerox and Kofax. The Xerox documents work fine, but the Kofax ones can be opened in a browser, but attempting to open them in Adobe Acrobat fails with There was an error opening this document. The file could not be repaired."
The Xerox scanners produce a v1.4 PDF. The Kofax scanners produce a v1.5 PDF. As a temporary workaround, I am converting all pdfs to version 1.4 before encrypting.

I have produced a small sample app that reproduces the problem:

using System;
using System.IO;
using Aspose.Pdf;
using Aspose.Pdf.Facades;

namespace ConsoleApp11
{
    class Program
    {
        private static void ActivateLicense()
        {
            var license = new Aspose.Pdf.License();
            license.SetLicense("Aspose.Total.lic");
        }

        static void Main()
        {
            ActivateLicense();
            EncryptPdf("Properties\\Xerox.pdf");
            EncryptPdf("Properties\\Kofax.pdf");
        }

        private static void EncryptPdf(string fileIn)
        {
            var buffer = File.ReadAllBytes(fileIn);

            using (var inStream = new MemoryStream(buffer))
            using (var outStream = new MemoryStream())
            {
                var doc = new Document(inStream);
                doc.Encrypt("qwerty", "qwerty", DocumentPrivilege.AllowAll,
                    CryptoAlgorithm.AESx128, false);
                doc.Save(outStream);
                var content = outStream.ToArray();

                var fileOut = $"{Path.GetDirectoryName(fileIn)}\\{Path.GetFileNameWithoutExtension(fileIn)}_{DateTime.Now:yyyyMMdd_HHmmss}.pdf";
                File.WriteAllBytes(fileOut, content);
            }
        }
    }
}

@f5f5f5

From your post, it seems that issue is related to PDFs scanned by particular printer i.e. Kofax. Could you please share if you are facing some issue creating v1.4 PDFs using Aspose.PDF? Please share some sample source and output files along with a bit more details of the issue that is related to Aspose.PDF. We will test the scenario in our environment and address it accordingly.

No, the problem is when the original pdf is v1.5. My workaround (not shown) is to convert all pdfs into v1.4 before encrypting.

I’ve uploaded example input and output from the above code. Xerox.pdf and Kofax.pdf are unencrypyted scanned images. Xerox_20200407_165634.pdf is the working output that works with Acrobat and Kofax_20200407_165644.pdf is an encrypted image that fails to load in Acrobat.

Thanks for looking at this.

Kofax.pdf (539.5 KB)
Kofax_20200407_165644.pdf (570.7 KB)
Xerox.pdf (109.2 KB)
Xerox_20200407_165634.pdf (140.3 KB)

For completeness Here is the sample code with the workaround:

using System;
using System.IO;
using Aspose.Pdf;
using Aspose.Pdf.Facades;

namespace ConsoleApp11
{
    class Program
    {
        private static void ActivateLicense()
        {
            var license = new Aspose.Pdf.License();
            license.SetLicense("Aspose.Total.lic");
        }

        static void Main()
        {
            ActivateLicense();
            EncryptPdf("Properties\\Xerox.pdf");
            EncryptPdf("Properties\\Kofax.pdf");
        }

        private static void EncryptPdf(string fileIn)
        {
            var buffer = File.ReadAllBytes(fileIn);

            using (var inStream = new MemoryStream(buffer))
            using (var outStream = new MemoryStream())
            using (var convertStream = new MemoryStream())
            using (var doc = new Document(inStream))
            {
                doc.Convert(convertStream, PdfFormat.v_1_4, ConvertErrorAction.Delete);
                doc.Encrypt("qwerty", "qwerty", DocumentPrivilege.AllowAll,
                    CryptoAlgorithm.AESx128, false);
                doc.Save(outStream);
                var content = outStream.ToArray();

                var fileOut =
                    $"{Path.GetDirectoryName(fileIn)}\\{Path.GetFileNameWithoutExtension(fileIn)}_{DateTime.Now:yyyyMMdd_HHmmss}.pdf";
                File.WriteAllBytes(fileOut, content);
            }
        }
    }
}

@f5f5f5

We have tested the scenario using Aspose.PDF for .NET 20.4 and were unable to notice the issue. Both PDFs were encrypted and able to open in Adobe Reader.

PasswordProtectedXerox.pdf (110.4 KB)
PasswordProtectedKofax.pdf (540.7 KB)

Would you please try to use the latest version of the API and in case you still face any issue, please feel free to let us know.