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

Free Support Forum - aspose.com

Set user password to a pdf Document

Hi,


I’m trying to set the userpassword to a pdf document by using aspose pdf.
My source document is an aspose.slides presentation.

By following this example:
http://www.aspose.com/docs/display/pdfnet/Set+User+or+Master+Password

I made my code as follow:

Presentation pres = new Presentation(Path);
using (MemoryStream memory= new MemoryStream())
{
pres.Save(memory, Aspose.Slides.Export.SaveFormat.Pdf);
Aspose.Pdf.Generator.Pdf doc = new Aspose.Pdf.Generator.Pdf(memory);
doc.Security = new Security();
doc.Security.UserPassword = “test”;
doc.Save(OutputPath);
}

but it doesn’t save anything.
Am I doing something wrong?

thanks,
Devid.

Hi Devid,


Aspose.Slides for .NET provides the feature to create and manipulate MS PowerPoint presentations. It also offers the capabilities to transform PPT/PPTX file to PDF format. However I am not entirely certain that either it supports the feature to apply security restrictions while converting Presentation to PDF format. I have asked my fellow worker to further look into this requirement.

Besides this, Aspose.Pdf for .NET supports the feature to create and manipulate existing PDF document. You can use Aspose.Pdf.Generator namespace to create PDF document using its API and you can use Aspose.Pdf/Aspose.Pdf.Facades namespace to manipulate existing PDF files. In order to apply security restrictions on PDF documents, please follow the instructions specified over Encrypt PDF File using Different Encryption Types and Algorithms

PS, First you need to convert PowerPoint presentation to PDF format and then you can use Aspose.Pdf for .NET to encrypt the PDF file. In the event of any further query, please feel free to contact.

Hi Nayyer Shahbaz,


As I wrote in a topic there isn’t any way to set the user and the owner password directly from aspose.slides, this is why I need Aspose.Pdf .

you told:
"First you need to convert PowerPoint presentation to PDF format and then you can use Aspose.Pdf for .NET to encrypt the PDF file."

As you can see from my code I save my presentation in a MemoryStream in pdf format.
Do I have to do something more?

Thanks,
Devid
Devid.Fabris:
As I wrote in a topic there isn't any way to set the user and the owner password directly from aspose.slides, this is why I need Aspose.Pdf .
Hi Devid,

The reason you could not accomplish your requirement is because you have been loading PDF document into Aspose.Pdf.Generator.Pdf object. As shared earlier, please try following the approach shared in 471756.

Hi,


Ok I’ll follow the link that you sent me, but what if I just want to set the UserPassword and not the OwnerPassword (or MasterPassword)?

Thanks,
Devid

Hi Devid,


In order to skip the Owner Password, you may pass null as second argument to Encrypt(…) method.

Hi,


Thanks a lot for your help!
But I have another question, what about if I want to allow the user to have all the permissions?
How can I do that?

thanks,
Devid

Hi Devid,


In order to allow the users to have all the permissions, please try using the following code snippet.

[C#]

//create DocumentPrivileges object<o:p></o:p>

DocumentPrivilege privilege = DocumentPrivilege.AllowAll;

//open PDF document

PdfFileSecurity fileSecurity = new PdfFileSecurity();

// bind source PDF file

fileSecurity.BindPdf("c:/pdftest/ForbidAll_output.pdf");

//set document privileges

fileSecurity.SetPrivilege(privilege);

// save updated document

fileSecurity.Save(“c:/pdftest/AllowAll_output.pdf”);