Quantcast
Channel: Aspose.Pdf Product Family
Viewing all articles
Browse latest Browse all 3131

How can I set a password for a newly created PDF document?

$
0
0
I am using Aspose PDF version 8.50.

I am creating a Pdf document and want to set a password. My current code doesn't work:

IO.MemoryStream PdfStream = new IO.MemoryStream();
PdfMergeDoc.Save(PdfStream);
PdfStream.Position = 0;

Aspose.Pdf..Generator.Pdf PdfSec = new Aspose.Pdf.Generator.Pdf(PdfStream);
PdfStream.Flush();
PdfSec.Security = new Aspp.Generator.Security();
PdfSec.Security.MasterPassword = "pw";
PdfSec.Save(PdfMergeDateipfadSec);

PdfMergeDoc is an Aspose.Pdf.Document object I have created, PdfMergeDateipfadSec is just the file path for the password protected document.

Although the stream is not empty the save method doesn't write the file.

I could not find a better example in the documentation than the one that creates an empty pdf document.

Please  help,

Regards,
Petrow


Viewing all articles
Browse latest Browse all 3131

Trending Articles