Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert ppt to pptx throw a System.ObjectDisposedException:“Cannot access a closed stream” #8

Open
298029lkk opened this issue Mar 23, 2023 · 1 comment

Comments

@298029lkk
Copy link

using b2xtranslator.OpenXmlLib.PresentationML;
using b2xtranslator.PptFileFormat;
using b2xtranslator.PresentationMLMapping;
using b2xtranslator.Shell;
using b2xtranslator.StructuredStorage.Reader;
using System;
using System.Globalization;

namespace PPTAnalysis
{
    internal class Program
    {
        public static string ChoosenOutputFile;
        static void Main(string[] args)
        {
            var InputFile = @"D:\myppt.ppt";         
            var procFile = new ProcessingFile(InputFile);
            if (ChoosenOutputFile == null)
            {
                if (InputFile.Contains("."))
                {
                    ChoosenOutputFile = InputFile.Remove(InputFile.LastIndexOf(".")) + ".pptx";
                }
                else
                {
                    ChoosenOutputFile = InputFile + ".pptx";
                }
            }          
            using (var reader = new StructuredStorageReader(procFile.File.FullName))
            {
                var ppt = new PowerpointDocument(reader);               
                var outType = Converter.DetectOutputType(ppt);
                string conformOutputFile = Converter.GetConformFilename(ChoosenOutputFile, outType);              
                var pptx = PresentationDocument.Create(conformOutputFile, outType);               
                var start = DateTime.Now;
                Console.WriteLine("Converting file {0} into {1}", InputFile, conformOutputFile);             
                Converter.Convert(ppt, pptx);            
                var end = DateTime.Now;
                var diff = end.Subtract(start);
                Console.WriteLine("Conversion of file {0} finished in {1} seconds", InputFile, diff.TotalSeconds.ToString(CultureInfo.InvariantCulture));
                reader.Dispose();
            }
            Console.WriteLine("OK");
            Console.ReadKey();
        }
    }
}

When executed [var ppt = new PowerpointDocument(reader)], throw the exception.
image
My project framework is. net core3.1
I encountered the same error running on. net framework 4.6.1

@DagothMor
Copy link

Did you solved this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants