Hi,
I am merging the PDF using ASPOSE.PDF kit. While sending the mail i am getting the merged PDF file as MemoryStream. Mail is sent successfully but the attached PDF showing as 0 KB.
Its working fine when sending the merged PDF file without setting any security (PDFPriveleges). If I set the owner password mail sent with 0 KB attachment.
public static MemoryStream GetMergedFile(FileStream[] files)
{
MemoryStream ms = new MemoryStream();
MemoryStream msOut = new MemoryStream();
try
{
PdfFileEditor editor = new PdfFileEditor();
editor.Concatenate(files, ms);
PdfFileSecurity pfs = new PdfFileSecurity(ms, msOut);
DocumentPrivilege dp = DocumentPrivilege.ForbidAll;
dp.AllowFillIn = true;
dp.AllowPrint = true;
dp.AllowCopy = true;
dp.PrintAllowLevel = 2;
pfs.EncryptFile("", Constants.OWNER_PASSWORD, dp, true);
if (ms != null)
ms.Close();
}
catch (Exception ex)
{
foreach (FileStream fs in files)
fs.Close();
log.Error(ex);
throw;
}
foreach (FileStream fs in files)
fs.Close();
return msOut;
}
Email Portion
-------------
MemoryStream ms = new MemoryStream();
ms = PDFHelper.GetMergedFile(files);
try
{
SmtpClient smtpClient = new SmtpClient(ConfigurationSettings.AppSettings["MailServer"]);
MailMessage message = new MailMessage(txtFrom.Text, txtTo.Text);
if(txtCC.Text.Trim() != "")
message.CC.Add(txtCC.Text);
if(txtBCC.Text.Trim() != "")
message.Bcc.Add(txtBCC.Text);
message.Subject = txtSubject.Text;
message.IsBodyHtml = true;
message.Body = txtMessage.Text;
if (ms != null)
message.Attachments.Add(new Attachment(ms, "MergedPDF.pdf", "application/pdf"));
smtpClient.Send(message);
.....................................
Anybody know the solution please let me know
Regards,