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

Free Support Forum - aspose.com

Problem with Document.Encrypt

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


Hi TIA,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for sharing the sample code.

I am able to reproduce your mentioned issue after an initial test. Your issue has been registered in our issue tracking system with issue id: PDFNEWNET-34360. We will notify you via this forum thread regarding any updates against your issue.

Sorry for the inconvenience,

The issues you have found earlier (filed as PDFNEWNET-34360) have been fixed in Aspose.Pdf for .NET 9.3.0.

Blog post for this release can be viewed over this link


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.