none
How to save the read-only presentation to pdf in C# RRS feed

  • Question

  • I  am facing the problem in conveting PPT to pdf.  When the presentation was marked as final or readonly,it throw an exception which states"Presentation (unknown member) : Invalid request.  Presentation cannot be modified"

    i am using vs2012 framework4.0 and powerpoint 2013.

    How can i resolve this question? Thanks


    • Edited by jax d Wednesday, June 4, 2014 9:22 AM
    Wednesday, June 4, 2014 9:18 AM

Answers

  • Hi,

    Based on the description, you want to convert a final or readonly presentation to PDF. As far as I know, we need to unmark the final property of the file before we save it if we want to convert it programmatically. Here is a sample for your reference:

    public bool PPTConvert(string pptPath, string pdfPath)
    
            {
    
                bool result;
    
                Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType targetFileType = Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsPDF;
    
                object missing = Type.Missing;
    
                Microsoft.Office.Interop.PowerPoint.ApplicationClass application = null;
    
                Microsoft.Office.Interop.PowerPoint.Presentation presentation = null;
    
                try
    
                {
    
                    application = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
    
                    presentation = application.Presentations.Open(pptPath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
    
                    presentation.Final = false;
    
                    //presentation.
    
                    //presentation.ExportAsFixedFormat(pdfPath,PpFixedFormatType.ppFixedFormatTypePDF,PpFixedFormatIntent.ppFixedFormatIntentPrint,MsoTriState.msoFalse,
    
                    //PpPrintHandoutOrder.ppPrintHandoutVerticalFirst,PpPrintOutputType.ppPrintOutputSlides);
    
                    presentation.SaveCopyAs(pdfPath, targetFileType);
    
                  
    
    
                    presentation.Final = true;
    
                    result = true;
    
                    return result;
    
                    Console.WriteLine("save successed!");
    
                }
    
                catch (Exception ex)
    
                {
    
    
                    result = false;
    
                    return result;
    
                    Console.WriteLine(ex.Message);
    
                    Console.ReadLine();
    
                    //log.Write(ex);
    
                }
    
    
            }

    Note, please check that you have write permission on the folder that you save the file to.

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, June 5, 2014 3:29 AM
    Moderator

All replies

  • Hello jax,

    Did you try to debug? What line of code fires the exception? What code do you use for converting presentations?

    Wednesday, June 4, 2014 11:25 AM
  • public bool PPTConvert(string pptPath, string pdfPath)
            {
                bool result;
                Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType targetFileType = Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsPDF;
                object missing = Type.Missing;
                Microsoft.Office.Interop.PowerPoint.ApplicationClass application = null;
                Microsoft.Office.Interop.PowerPoint.Presentation presentation = null;
                try
                {
                    application = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
                    presentation = application.Presentations.Open(pptPath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
                    //presentation.ExportAsFixedFormat(pdfPath,PpFixedFormatType.ppFixedFormatTypePDF,PpFixedFormatIntent.ppFixedFormatIntentPrint,MsoTriState.msoFalse,
                    //PpPrintHandoutOrder.ppPrintHandoutVerticalFirst,PpPrintOutputType.ppPrintOutputSlides);
                    presentation.SaveCopyAs(pdfPath, targetFileType);
                    result = true;
                }
                catch(Exception ex)
                {
                    
                    result = false;
                    log.Write(ex);
                }
    this is the source code . when i invoking "presentation.SaveCopyAs()" method,it fires the exception.
    Thursday, June 5, 2014 1:47 AM
  • Hi,

    Based on the description, you want to convert a final or readonly presentation to PDF. As far as I know, we need to unmark the final property of the file before we save it if we want to convert it programmatically. Here is a sample for your reference:

    public bool PPTConvert(string pptPath, string pdfPath)
    
            {
    
                bool result;
    
                Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType targetFileType = Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsPDF;
    
                object missing = Type.Missing;
    
                Microsoft.Office.Interop.PowerPoint.ApplicationClass application = null;
    
                Microsoft.Office.Interop.PowerPoint.Presentation presentation = null;
    
                try
    
                {
    
                    application = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
    
                    presentation = application.Presentations.Open(pptPath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
    
                    presentation.Final = false;
    
                    //presentation.
    
                    //presentation.ExportAsFixedFormat(pdfPath,PpFixedFormatType.ppFixedFormatTypePDF,PpFixedFormatIntent.ppFixedFormatIntentPrint,MsoTriState.msoFalse,
    
                    //PpPrintHandoutOrder.ppPrintHandoutVerticalFirst,PpPrintOutputType.ppPrintOutputSlides);
    
                    presentation.SaveCopyAs(pdfPath, targetFileType);
    
                  
    
    
                    presentation.Final = true;
    
                    result = true;
    
                    return result;
    
                    Console.WriteLine("save successed!");
    
                }
    
                catch (Exception ex)
    
                {
    
    
                    result = false;
    
                    return result;
    
                    Console.WriteLine(ex.Message);
    
                    Console.ReadLine();
    
                    //log.Write(ex);
    
                }
    
    
            }

    Note, please check that you have write permission on the folder that you save the file to.

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, June 5, 2014 3:29 AM
    Moderator
  • thanks.you are right.

    i have try  to set "presentation.ReadOnly" to false,but it failed.

    i do not understand that the attribute "presentation.ReadOnly" just can read,and that "presentation.Final" can read and write?

    Thursday, June 5, 2014 3:49 AM
  • Hi Jax,

    We can use code change the "presentation.ReadOnly", the property is readonly. You can get more detail about this property from link below:

    Presentation.ReadOnly



    Friday, June 6, 2014 10:02 AM