예제 #1
0
        public static void Convert(PowerpointDocument ppt, PresentationDocument pptx)
        {
            using (pptx)
            {
                // Setup the writer
                XmlWriterSettings xws = new XmlWriterSettings();
                xws.OmitXmlDeclaration = false;
                xws.CloseOutput        = true;
                xws.Encoding           = Encoding.UTF8;
                xws.ConformanceLevel   = ConformanceLevel.Document;

                // Setup the context
                ConversionContext context = new ConversionContext(ppt);
                context.WriterSettings = xws;
                context.Pptx           = pptx;

                // Write presentation.xml
                ppt.Convert(new PresentationPartMapping(context));

                //AppMapping app = new AppMapping(pptx.AddAppPropertiesPart(), xws);
                //app.Apply(null);

                //CoreMapping core = new CoreMapping(pptx.AddCoreFilePropertiesPart(), xws);
                //core.Apply(null);
            }
        }
예제 #2
0
        public static OpenXmlPackage.DocumentType DetectOutputType(PowerpointDocument ppt)
        {
            OpenXmlPackage.DocumentType returnType = OpenXmlPackage.DocumentType.Document;

            try
            {
                //ToDo: Find better way to detect macro type
                if (ppt.VbaProject != null)
                {
                    returnType = OpenXmlPackage.DocumentType.MacroEnabledDocument;
                }
            }
            catch (Exception)
            {
            }

            return(returnType);
        }
예제 #3
0
        private static void processFile(String InputFile)
        {
            // copy processing file
            ProcessingFile procFile = new ProcessingFile(InputFile);

            //make output file name
            if (ChoosenOutputFile == null)
            {
                if (InputFile.Contains("."))
                {
                    ChoosenOutputFile = InputFile.Remove(InputFile.LastIndexOf(".")) + ".pptx";
                }
                else
                {
                    ChoosenOutputFile = InputFile + ".pptx";
                }
            }

            //open the reader
            using (StructuredStorageReader reader = new StructuredStorageReader(procFile.File.FullName))
            {
                // parse the ppt document
                PowerpointDocument ppt = new PowerpointDocument(reader);

                // detect document type and name
                OpenXmlPackage.DocumentType outType = Converter.DetectOutputType(ppt);
                string conformOutputFile            = Converter.GetConformFilename(ChoosenOutputFile, outType);

                // create the pptx document
                PresentationDocument pptx = PresentationDocument.Create(conformOutputFile, outType);

                //start time
                DateTime start = DateTime.Now;
                TraceLogger.Info("Converting file {0} into {1}", InputFile, conformOutputFile);

                // convert
                Converter.Convert(ppt, pptx);

                // stop time
                DateTime end  = DateTime.Now;
                TimeSpan diff = end.Subtract(start);
                TraceLogger.Info("Conversion of file {0} finished in {1} seconds", InputFile, diff.TotalSeconds.ToString(CultureInfo.InvariantCulture));
            }
        }
예제 #4
0
        static void Main(string[] args)
        {
            TraceLogger.LogLevel = TraceLogger.LoggingLevel.DebugInternal;

            const string outputDir = "dumps";

            if (Directory.Exists(outputDir))
            {
                Directory.Delete(outputDir, true);
            }

            Directory.CreateDirectory(outputDir);

            string         inputFile = args[0];
            ProcessingFile procFile  = new ProcessingFile(inputFile);

            StructuredStorageReader file   = new StructuredStorageReader(procFile.File.FullName);
            PowerpointDocument      pptDoc = new PowerpointDocument(file);

            // Dump unknown records
            foreach (Record record in pptDoc)
            {
                if (record is UnknownRecord)
                {
                    string filename = String.Format(@"{0}\{1}.record", outputDir, record.GetIdentifier());

                    using (FileStream fs = new FileStream(filename, FileMode.Create))
                    {
                        record.DumpToStream(fs);
                    }
                }
            }

            // Output record tree
            Console.WriteLine(pptDoc);
            Console.WriteLine();

            // Let's make development as easy as pie.
            System.Diagnostics.Debugger.Break();
        }
예제 #5
0
 public ConversionContext(PowerpointDocument ppt)
 {
     this.Ppt = ppt;
 }