Setting Security on PDF created by eCopy ShareScan scanner damages PDF

I have a client with a new scanner. When they scan to a PDF with the eCopy ShareScan and then use our product to clean metadata, while asking our product to set a secure password, the resulting PDF cannTest.pdf (3.5 KB)
ot be opened.

“There was an error opening this document. The file is damanged and could not be repaired.”

If we create a PDF by any other means, “scrub” and set security the PDF comes out correct, undamaged.

A sample of a PDF created by this scanner is attached.

Version used in our Scrub product: Aspose.Pdf.dll 17.1.0.0

Thanks,
Kristen Theologus
Product Specialist
BigHand

@KTechnogal,
Thank you for sending a source PDF. After setting the privileges on your PDF document, we managed to replicate the said error in our environment. It has been logged under the ticket ID PDFNET-42978 in our bug tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates. However, we would recommend you to share your code to cover the actual scenario as well.

Best Regards,
Imran Rafique

Can you provide an eta on when we might have a fix for this issue?

Thanks,
Kristen

@KTechnogal,
It is difficult for us to share an ETA at this stage before the completion of the analysis phase. However, we have logged an ETA request under the same ticket ID PDFNET-42978. We will let you know once a significant progress has been made in this regard.

Best Regards,
Imran Rafique

Code as previously requested:

public void ClearAuthorAndTitleFromPdf(string path)
{
var pdf = new Aspose.Pdf.Document(path);
var pdfInfo = new Aspose.Pdf.DocumentInfo(pdf);
pdfInfo.Author = string.Empty;
pdfInfo.Title = string.Empty;
if (!SetSecurity(pdf, false, false, false, false, true, “userPassword”, “ownerPassword”))
throw new Exception();
pdf.Save();
}

    public bool SetSecurity(Aspose.Pdf.Document pdf, bool allowCopy, bool allowModification, bool allowPrint, bool allowModifyNotes, bool strongerEncryption, string userPsw, string ownerPsw)
    {
        DocumentPrivilege dp = DocumentPrivilege.ForbidAll;

        dp.AllowCopy = allowCopy;
        dp.AllowModifyContents = allowModification;
        dp.AllowPrint = allowPrint;
        dp.AllowModifyAnnotations = allowModifyNotes;

        PdfFileSecurity security = new PdfFileSecurity(pdf);
        
        if (strongerEncryption)
        {
            return security.EncryptFile(userPsw, ownerPsw, dp, KeySize.x128, Algorithm.AES);
        }
        else
        {
            return security.EncryptFile(userPsw, ownerPsw, dp, KeySize.x40, Algorithm.RC4);
        }
    }

Just to clarify. We can remove metadata successfully if we do not attempt to set security on the PDF.

Hope this is helpful.

Thanks,
Kristen

@KTechnogal,
We have included this information under the same ticket ID PDFNET-42978 in our issue tracking system. We will let you know once we have an update.

Any update on this ticket?

@KTechnogal,

Unfortunately, there is no update on this yet and we are in communication to get the latest update. The priority level of the linked ticket ID PDFNET-42978 has also been raised.

The issues you have found earlier (filed as PDFNET-42978) have been fixed in Aspose.PDF for .NET 19.3.