Convert Presentation(Ex) to secure PDF

Last post 01-05-2012, 3:51 AM by ThomasGG. 4 replies.
Sort Posts: Previous Next
  •  01-04-2012, 3:55 AM 352945

    Convert Presentation(Ex) to secure PDF .NET

    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);
        }
    }
     
  •  01-04-2012, 6:35 AM 352973 in reply to 352945

    Re: Convert Presentation(Ex) to secure PDF

    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,

    Mudassir Fayyaz
    Support Developer
    Aspose Sialkot Team
    Contact Us
    Aspose - The .NET and Java Component Publisher

    Keep in touch! We're on Twitter and Facebook
     
  •  01-04-2012, 7:15 AM 352986 in reply to 352973

    Re: Convert Presentation(Ex) to secure PDF .NET

    Attachment: Present (inaccessible)
    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)
     
  •  01-05-2012, 3:15 AM 353202 in reply to 352986

    Re: Convert Presentation(Ex) to secure PDF

    Attachment: Present (inaccessible)
    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,

    Mudassir Fayyaz
    Support Developer
    Aspose Sialkot Team
    Contact Us
    Aspose - The .NET and Java Component Publisher

    Keep in touch! We're on Twitter and Facebook
     
  •  01-05-2012, 3:51 AM 353212 in reply to 353202

    Re: Convert Presentation(Ex) to secure PDF

    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.
     
View as RSS news feed in XML