I have a problem when I try to set a password for generated document.
If I set the password on an existing document, everything is OK; but when I create and empty document, and the add pages from existing ones, the call to Encrypt does not set any protection.
I’ve reproduced a very small example which clearly shows the problem. In short,
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Aspose.Pdf; using AsposeWrapper; namespace PasswordProtect { class Program { static void Main(string[] args) { //(new License()).SetLicense("..."); // this way password is set OpenAndSave(); // this way password is NOT set AppendAndSave(); } private static void OpenAndSave() { var pdf = new Document(@"path\to\file.pdf"); pdf.Encrypt("password", "", Permissions.PrintDocument | Permissions.PrintingQuality, CryptoAlgorithm.RC4x128); pdf.Save(@".\edited.pdf"); pdf.Dispose(); } // Open a new file, append pages from an existing file, and // set user password for the new file private static void AppendAndSave() { var pdfFrom = new Document(@"path\to\file.pdf"); var pdfTo = new Document(); pdfTo.Pages.Add(pdfFrom.Pages) ; pdfTo.Encrypt("password", "", Permissions.PrintDocument | Permissions.PrintingQuality, CryptoAlgorithm.RC4x128); pdfTo.Save(@".\edited2.pdf"); pdfFrom.Dispose(); pdfTo.Dispose(); } } }
The initial file itself is not encrypted.
This simple code gives the same result with any 7.x Aspose.pdf.dll.
Am I missing something? or is this a bug?
TIA