Encrypt and Email

Hello,

I am currently using Aspose.pdf and .NET version 3.5.

I use a local API that returns for me a Stream from a PDF document. I need to encrypt the Stream,

attach it to the email (using the Attachment class), and email it out to the customer. The customer will then enter the password and view the content.

The issue is that when I create a Document object to encrypt the content, how do I get the stream back from the document so I can attach it and send it out.

Here is a code sample that I have so far:

var document = new Document(pdfStream);
document.Encrypt("user", string.Empty, 0, Aspose.Pdf.CryptoAlgorithm.RC4x128);

var rtnAttachment = new Attachment(StreamFormDocumentGoesHere, "Invoice " + invoiceID + ".pdf");

Hi Ayad,


Thanks for using our products.

Document class also supports the feature to save the output in stream object so as per your requirement, once the PDF file is encrypted, you can save the output in MemoryStream object so that it can be further used for attachment (related purposes). Please take a look over following code snippet.

In case I have not properly understood your requirement, please share some further details.

[C#]

// load source PDF file<o:p></o:p>

Document pdf = new Document(@"c:\pdftest\RequiredField_output.pdf");

// encrypt the PDF file

pdf.Encrypt("user", "owner", Permissions.AssembleDocument, CryptoAlgorithm.AESx256);

// MemoryStream object

MemoryStream stream = new MemoryStream();

// save the output in stream object

pdf.Save(stream);