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

Free Support Forum - aspose.com

Password protect PDF

Hi,

I am using latest version of Aspose.Words and Aspose.Pdf 17.6 which I downloaded from
https://downloads.aspose.com/words/net
and
https://downloads.aspose.com/pdf/net
respectively.

I am trying to password protect the pdf being generated from html but I do not see this working.

My code is

using (MemoryStream stream = new MemoryStream(byteArray))
{
Aspose.Words.Document wordDoc = new Aspose.Words.Document(stream);
wordDoc.Protect(Aspose.Words.ProtectionType.ReadOnly, password);
wordDoc.Save(pathToSaveServer + "\\" + filename);

//Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf(stream);
//pdf1.Security = new Aspose.Pdf.Generator.Security();
//pdf1.Security.UserPassword = password;
//pdf1.Save(pathToSaveServer + "\" + filename);
}

Here with previous version of aspose.pdf I had reference of Aspose.Pdf.Generator but with above version of dlls I do not see any reference for Aspose.Pdf.Generator

I have followed the links

So basically what I am trying is to save html string as pdf with password protection.
So please guide me how this can be done

Thanks
Rohit

Hi Rohit,

Thanks for your inquiry. Please make sure that you are using the latest version of Aspose.Words for .NET 17.6 and using following code example. If you still face problem, please share your input HTML and output PDF here for testing. We will investigate the issue and provide you more information on this.

Document doc = new Document(MyDir + "in.html");
PdfSaveOptions saveOptions = new PdfSaveOptions();
// Create encryption details and set user password = 1
PdfEncryptionDetails encryptionDetails = new PdfEncryptionDetails("1", "2", PdfEncryptionAlgorithm.RC4\_128);
// Disallow all
encryptionDetails.Permissions = PdfPermissions.DisallowAll;
// Allow printing
encryptionDetails.Permissions = PdfPermissions.Printing;
saveOptions.EncryptionDetails = encryptionDetails;
doc.Save(MyDir + "17.6.pdf", saveOptions);