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,
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,
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.