Convert Presentation(Ex) to secure PDF

Hi,

I can’t manage to convert a PPT or PPTX to secure PDF. I only managed to convert it to a regular PDF, or to a secure PDF but with no content. I’m using Aspose.Slides 5.6.0.0.

Could you please help me out? Thanks.

Here is my code (with secure PDF code commented out):

public byte[] ToSecurePdf(byte[] sfDocument, String extension)
{
try
{
Pdf pdfDoc = null;
using (MemoryStream docStream = new MemoryStream(sfDocument, true))
using (MemoryStream pdfStream = new MemoryStream())
{
switch (extension)
{
case “.ppt”:
Presentation pres = new Presentation(docStream);
pres.Save(pdfStream, Aspose.Slides.Export.SaveFormat.Pdf);

//pdfDoc = new Pdf(pdfStream);
break;

default:
case “.pptx”:
PresentationEx presEx = new PresentationEx(docStream);
presEx.Save(pdfStream, Aspose.Slides.Export.SaveFormat.Pdf);

//pdfDoc = new Pdf(pdfStream);
break;
}

/pdfDoc.Security = new Security();
pdfDoc.Security.IsDefaultAllAllowed = false;

pdfDoc.DefaultFontName = “Arial”;
pdfDoc.TextInfo.FontName = “Arial”;

pdfDoc.Close();
/

byte[] bytes = pdfStream.ToArray();
return bytes;
}
}
catch (Exception ex)
{
throw new Exception("Error during document conversion: " + ex.Message);
}
}

Hi Thomas,


Kindly share the source presentation along with generated PDF with us for necessary investigation. Before this, I would recommend you to try using Aspose.Slides for .NET 5.8.0 and if the issues still persist then kindly share the source presentation and generated PDF.

Many Thanks,

Hi,

Thanks for your answer.
We’re on the most recent version we can use with our license, so upgrading is not an option as of now.
The problem can be reproduced with any presentation, really, so this shouldn’t matter.

Anyway, here are all the files:

  • source.pptx (source presentation)
  • result1.pdf (generated regular PDF ; works, but is not secure)
  • result2.pdf (generated secure PDF ; empty)

Hi Thomas,


I have worked with the presentation file shared by you and have successfully generated the PDF. However, if you are using Aspose.Pdf to secure the generated PDF and as a resultant the secure PDF is empty, then it is related to Aspose.PDF. The Aspose.Slides generated the correct PDF.

I am moving this request to Aspose.PDF forum, where our fellow support team will help you further in this regard. For your kind reference, the generated PDF is also attached.

Many Thanks,

Hi Mudassir,

For the info, we eventually managed to get it to work with the following code:

public MemoryStream ToSecurePdf(byte[] sfDocument, String extension)
{
try
{
using (MemoryStream docStream = new MemoryStream(sfDocument, true))
using (MemoryStream pdfStream = new MemoryStream())
{
switch (extension)
{
case “.ppt”:
Presentation pres = new Presentation(docStream);
pres.Save(pdfStream, Aspose.Slides.Export.SaveFormat.Pdf);
break;

case “.pptx”:
PresentationEx presEx = new PresentationEx(docStream);
presEx.Save(pdfStream, Aspose.Slides.Export.SaveFormat.Pdf);
break;

case “.pdf”:
docStream.CopyTo(pdfStream);
break;

default:
throw new Exception("Format not supported: " + extension);
}

docStream.Close();

MemoryStream securePdfStream = new MemoryStream();
Aspose.Pdf.Facades.PdfFileSecurity pfs = new Aspose.Pdf.Facades.PdfFileSecurity(pdfStream, securePdfStream);
pfs.SetPrivilege(DocumentPrivilege.ForbidAll);

return securePdfStream;
}
}
catch (Exception ex)
{
throw new Exception("Error during document conversion: " + ex.Message);
}
}


Thanks for your time.