PDF security - default password?

Hi,


I’m setting the security settings on my PDFs like this to allow print only:
pdfdoc.Security = new Aspose.Pdf.Security();
pdfdoc.Security.IsDefaultAllAllowed = false;
pdfdoc.Security.IsPrintingAllowed = true;
pdfdoc.Save(sFileName);

and was just wondering what the permissions password for the document will get set to by default? Is it nothing, or the Windows password of the user logged in? I’m using impersonation too (for saving the created PDF), so will that password get used?

Cheers.

Hello James,

Thanks for considering Aspose.

The password over PDF file is not set by default. In fact you need to set it by yourself. There are two levels of password, one is MasterPassword & the other is UserPassword. You can MasterPassword & UserPassword properties in Security class to accomplish your requirement.

Please visit the following link for more information and sample code for setting password over PDF file. Set User or Master Password

In case it does not satisfy your requirement or you have any further query, please feel free to contact.

I have code that is doing :


_pdf.Security = new Security();
_pdf.Security.IsAnnotationsModifyingAllowed = false;
_pdf.Security.IsContentsModifyingAllowed = false;
_pdf.Security.IsCopyingAllowed = false;
_pdf.Security.IsPrintingAllowed = true;
_pdf.Security.IsFormFillingAllowed = false;

But NOT setting a password (MasterPassword or UserPassword ) and yet the resulting PDF is password protected. What’s the default password?.

Thanks.

nicolas.sampietro:
I have code that is doing:

_pdf.Security = new Security();
_pdf.Security.IsAnnotationsModifyingAllowed = false;
_pdf.Security.IsContentsModifyingAllowed = false;
_pdf.Security.IsCopyingAllowed = false;
_pdf.Security.IsPrintingAllowed = true;
_pdf.Security.IsFormFillingAllowed = false;

But NOT setting a password (MasterPassword, or UserPassword ) and yet the resulting PDF is password protected. What’s the default password?

Thanks.

Hi Nicolas,

Thanks for contacting support.

I have tested the scenario using the [latest release of Aspose.Pdf for .NET 11.6.0](On Premise File Format API Releases | Aspose 11.6.0/) where I have used the following code snippet and as per my observations, I do not get any prompt when viewing the resultant document.

Can you please share your code snippet so we can again test the scenario in our environment. We are sorry for this inconvenience.

C#

Aspose.Pdf.Generator.Pdf _pdf = new Aspose.Pdf.Generator.Pdf();
_pdf.Security = new Aspose.Pdf.Generator.Security();
 _pdf.Security.IsAnnotationsModifyingAllowed = false;
 _pdf.Security.IsContentsModifyingAllowed = false;
 _pdf.Security.IsCopyingAllowed = false;
 _pdf.Security.IsPrintingAllowed = true;
 _pdf.Security.IsFormFillingAllowed = false;
 _pdf.Sections.Add();
 _pdf.Sections[0].Paragraphs.Add(new Aspose.Pdf.Generator.Text("Hello World...") );
_pdf.Save("c:/pdftest/SecurePdf.pdf");

If you go to File / Properties /Security , you’ll see the file is password protected. If you try to remove this setting, It will ask you for a password. This file can’t be Combined with other PDFs, please advice.

Hi Nicolas,

Thanks for sharing the details.

The reason pages of this document cannot be merged with other documents is because content modification and content copy are not permitted, and I have also noticed security restrictions over the PDF file. However, we recommend you try using the following code snippet based on the new Document Object Model of the Aspose.Pdf namespace to encrypt and then decrypt the PDF document (in order to modify PDF contents).

[C#]

// Load a source PDF file

using (Document document = new Document())
{
    document.Pages.Add();
    document.Pages[1].Paragraphs.Add(new Aspose.Pdf.Text.TextFragment("Hello World..."));

    // Instantiate Document Privileges object
    // Apply restrictions on all privileges
    DocumentPrivilege documentPrivilege = DocumentPrivilege.ForbidAll;
    documentPrivilege.AllowModifyAnnotations = false;
    documentPrivilege.AllowModifyContents = false;
    documentPrivilege.AllowCopy = false;
    documentPrivilege.AllowPrint = false;
    documentPrivilege.AllowFillIn = false;

    // Encrypt the file with User and Owner password.
    // Need to set the password, so that once the user views
    // the file with user password,
    // only screen reading option is enabled
    document.Encrypt("","", documentPrivilege, CryptoAlgorithm.AESx128, false);

    // Save updated document
    document.Save("c:/pdftest/TempFile_Secured.pdf");
}

Document newpdf = new Document("c:/pdftest/TempFile_Secured.pdf");
DocumentPrivilege newprivileges = DocumentPrivilege.ModifyContents;
newprivileges.AllowModifyContents = true;
newpdf.Decrypt();
newpdf.Save("c:/pdftest/DecryptedPDF.pdf");

OK, I’ll use this code to run a process and remove the security on the PDFs. Thanks for you help.

Hi Nicolas,


Please continue using our API’s and in the event of any further query, please feel free to contact.