/************************** FINAL PPT-to-Image ***************************** * http://www.free-power-point-templates.com/articles/c-code-to-convert-powerpoint-to-image/ */ public void ppt2Image(string pptfilePath, string exportPath, string prefix) { Console.WriteLine("PPT File Location:" + pptfilePath); Microsoft.Office.Interop.PowerPoint.Application pptApplication = new Microsoft.Office.Interop.PowerPoint.Application(); Presentation pptPresentation = pptApplication.Presentations .Open(pptfilePath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse); int pageWidth = 800; int pageHeight = (int)(pageWidth / pptPresentation.PageSetup.SlideWidth * pptPresentation.PageSetup.SlideHeight); Console.WriteLine("w/H" + pageWidth + ":" + pageHeight); //slides to image int slide_count = pptPresentation.Slides.Count; Console.Write("count=" + slide_count); for (int i = 1; i <= slide_count; ++i) { /* full HD*/ pptPresentation.Slides[i].Export(exportPath + @"\" + "slide" + i + ".png", "png", pageWidth, pageHeight); /* Thumbnail*/ pptPresentation.Slides[i].Export(exportPath + @"\" + "thumb.slide" + i + ".png", "png", pageWidth / 2, pageHeight / 2); } ppt2ContentImages(pptPresentation, exportPath.Replace(@"\ppt-img", @"\" + "content-img")); pptPresentation.Close(); }
/************************** FINAL PPT- Content Images - Extract ***************************** * //slide extract image content * // https://stackoverflow.com/questions/4990825/export-movies-from-powerpoint-to-file-in-c-sharp * //https://stackoverflow.com/questions/42442659/c-sharp-save-ppt-shape-msopicture-as-image-w-office-interop */ public void pptContentExtract(string src_pptfilePath, string exportPath, string prefix) { Console.WriteLine("PPT File Location:" + src_pptfilePath); Microsoft.Office.Interop.PowerPoint.Application pptApplication = new Microsoft.Office.Interop.PowerPoint.Application(); Presentation pptPresentation = pptApplication.Presentations .Open(src_pptfilePath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse); foreach (PowerPoint.Slide slide in pptPresentation.Slides) { PowerPoint.Shapes slideShapes = slide.Shapes; int count = 0; foreach (PowerPoint.Shape shape in slideShapes) { if (shape.Type == MsoShapeType.msoPicture) { //LinkFormat.SourceFullName contains the movie path //get the path like this shape.Export(exportPath + @"\" + "content" + slide.SlideNumber + "_" + count++ + ".png", Microsoft.Office.Interop.PowerPoint.PpShapeFormat.ppShapeFormatPNG); Console.WriteLine("Exported" + exportPath + @"\" + "content" + slide.SlideNumber + "_" + count++ + ".png"); //System.IO.File.Copy(shape.LinkFormat.SourceFullName, path + imageBase + @"\" + "content" + slide.SlideNumber + "_"+ count++ + ".png"); } } } pptPresentation.Close(); }
internal static string Conversion(string path) { Microsoft.Office.Interop.PowerPoint.Application PowerPoint_App = new Microsoft.Office.Interop.PowerPoint.Application(); Microsoft.Office.Interop.PowerPoint.Presentations multi_presentations = PowerPoint_App.Presentations; Microsoft.Office.Interop.PowerPoint.Presentation presentation = multi_presentations.Open(@path); string presentationText = ""; //slides do not start at 0 index// for (int i = 1; i < presentation.Slides.Count + 1; i++) { //loop again inside each individual slide to check the notes section// for (int b = 1; b <= presentation.Slides[i].NotesPage.Shapes.Count; b++) { var noteShape = presentation.Slides[i].NotesPage.Shapes[b]; if (noteShape.Type == Microsoft.Office.Core.MsoShapeType.msoPlaceholder) { if (noteShape.PlaceholderFormat.Type == PowerPoint.PpPlaceholderType.ppPlaceholderBody) { if (noteShape.HasTextFrame == MsoTriState.msoTrue) { presentationText = noteShape.TextFrame.TextRange.Text; System.Diagnostics.Debug.WriteLine(presentationText); } } } } } //end main for loop// PowerPoint_App.Quit(); return presentationText; }
public static IList <string> GetPresentationTitles(string pptPath) { IList <string> result = new List <string>(); var presentationApp = new Microsoft.Office.Interop.PowerPoint.Application(); try { presentationApp.Visible = Microsoft.Office.Core.MsoTriState.msoTrue; Microsoft.Office.Interop.PowerPoint.Presentations presentations = presentationApp.Presentations; var readOnly = Microsoft.Office.Core.MsoTriState.msoTrue; var untitled = Microsoft.Office.Core.MsoTriState.msoTrue; var withWindow = Microsoft.Office.Core.MsoTriState.msoFalse; Microsoft.Office.Interop.PowerPoint.Presentation presentation = presentations.Open(pptPath, readOnly, untitled, withWindow); int i = 0; foreach (PowerPoint.Slide slide in presentation.Slides) { string defaultTitle = String.Format("Slide {0}", i); String shapeTitle = ExtractSlideTitlefromShape(slide, defaultTitle); result.Add(shapeTitle); } } finally { presentationApp.Quit(); } return(result); }
//string filePath; public string gettext(string filePath) { string fileData = ""; Microsoft.Office.Interop.PowerPoint.Application PowerPoint_App = new Microsoft.Office.Interop.PowerPoint.Application(); Microsoft.Office.Interop.PowerPoint.Presentations multi_presentations = PowerPoint_App.Presentations; Microsoft.Office.Interop.PowerPoint.Presentation presentation = multi_presentations.Open(@filePath, MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoFalse); for (int i = 0; i < presentation.Slides.Count; i++) { foreach (var item in presentation.Slides[i + 1].Shapes) { var shape = (PowerPoint.Shape)item; if (shape.HasTextFrame == MsoTriState.msoTrue) { if (shape.TextFrame.HasText == MsoTriState.msoTrue) { var textRange = shape.TextFrame.TextRange; var text = textRange.Text; fileData += text + " "; } } } } PowerPoint_App.Quit(); return(fileData); }
static void Main(string[] args) { string fileName = @"C:\Presentation1.pptx"; string exportName = "video_of_presentation"; string exportPath = @"C:\{0}.wmv"; Microsoft.Office.Interop.PowerPoint.Application ppApp = new Microsoft.Office.Interop.PowerPoint.Application(); ppApp.Visible = MsoTriState.msoTrue; ppApp.WindowState = PpWindowState.ppWindowMinimized; Microsoft.Office.Interop.PowerPoint.Presentations oPresSet = ppApp.Presentations; Microsoft.Office.Interop.PowerPoint._Presentation oPres = oPresSet.Open(fileName, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse); try { oPres.CreateVideo(exportName); oPres.SaveCopyAs(String.Format(exportPath, exportName), PowerPoint.PpSaveAsFileType.ppSaveAsWMV, MsoTriState.msoCTrue); } finally { ppApp.Quit(); } }
private void button5_Click(object sender, EventArgs e) { string fileName = @"D:\Univer\Anul-III\Sem-II\SM\Lab4\SM_Lab_4\curs2.ppt"; string exportName = "video_of_presentation"; string exportPath = @"D:\Univer\Anul-III\Sem-II\SM\Lab4\SM_Lab_4\{0}.mp4"; Microsoft.Office.Interop.PowerPoint.Application ppApp = new Microsoft.Office.Interop.PowerPoint.Application(); ppApp.Visible = MsoTriState.msoTrue; ppApp.WindowState = PpWindowState.ppWindowMinimized; Microsoft.Office.Interop.PowerPoint.Presentations oPresSet = ppApp.Presentations; Microsoft.Office.Interop.PowerPoint._Presentation oPres = oPresSet.Open(fileName, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse); try { oPres.CreateVideo(exportName); oPres.SaveCopyAs(String.Format(exportPath, exportName), PowerPoint.PpSaveAsFileType.ppSaveAsWMV, MsoTriState.msoCTrue); } finally { ppApp.Quit(); } }
public static void PPTToHtml(string path) { Microsoft.Office.Interop.PowerPoint.Application ppApp = new Microsoft.Office.Interop.PowerPoint.Application(); string strSourceFile = path; string strDestinationFile = path.Substring(0, path.Length - 3) + ".html"; Microsoft.Office.Interop.PowerPoint.Presentation prsPres = ppApp.Presentations.Open(strSourceFile, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse); prsPres.SaveAs(strDestinationFile, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsHTML, MsoTriState.msoTrue); prsPres.Close(); ppApp.Quit(); }
/* PPT 2 PDF by Slide Range : ASP/PowerShell example. * https://stackoverflow.com/questions/4086541/powerpoint-exportasfixedformat-in-powershell */ public void ppt2pdfByFilesSeparatePages(string pptfile, string path, List <DataPair> slides) { // see Overloaded function for custom slide start - end Ranges. Console.WriteLine("PPT File Location:" + pptfile); Microsoft.Office.Interop.PowerPoint.Application pptApplication = new Microsoft.Office.Interop.PowerPoint.Application(); Presentation pptPresentation = pptApplication.Presentations .Open(pptfile, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse); //Save as PDF for text Extraction string pdfpath = pptfile.Replace(".ppt", "") + ".pdf"; //string pdfpath = @path+"\\"+ id + ".pdf"; //Publish PPT - to - PDF // publishes hidden slide to pdf // pptPresentation.ExportAsFixedFormat(pdfpath, PpFixedFormatType.ppFixedFormatTypePDF, PpFixedFormatIntent.ppFixedFormatIntentPrint, MsoTriState.msoFalse, PpPrintHandoutOrder.ppPrintHandoutHorizontalFirst, PpPrintOutputType.ppPrintOutputSlides, MsoTriState.msoTrue); object unknownType = Type.Missing; if (pptPresentation != null) { foreach (DataPair slide in slides) { pdfpath = @path + @"\\" + slide.Key + ".pdf"; // define the slide ranges for pdf printing. try { PowerPoint.PrintRanges ranges = pptPresentation.PrintOptions.Ranges; PowerPoint.PrintRange range = ranges.Add(slide.Value, slide.Value); // note: PowerPoint.PpPrintRangeType.ppPrintSlideRange not PrintAll. pptPresentation.ExportAsFixedFormat((string)pdfpath, PowerPoint.PpFixedFormatType.ppFixedFormatTypePDF, PowerPoint.PpFixedFormatIntent.ppFixedFormatIntentPrint, MsoTriState.msoFalse, PowerPoint.PpPrintHandoutOrder.ppPrintHandoutVerticalFirst, PowerPoint.PpPrintOutputType.ppPrintOutputSlides, MsoTriState.msoTrue, range /*null*/, PowerPoint.PpPrintRangeType.ppPrintSlideRange, string.Empty, true, true, true, true, false, unknownType); } // do not publish hidden slides to pdf - messes up slide # b/w ppt and pdf // pptPresentation.ExportAsFixedFormat(pdfpath, PpFixedFormatType.ppFixedFormatTypePDF, PpFixedFormatIntent.ppFixedFormatIntentPrint, MsoTriState.msoFalse); catch (Exception ex) { Console.Write(ex.ToString()); Console.ReadLine(); return; } } } }
/// <summary> /// Executes a shell command synchronously. /// </summary> /// <param name="command">string command</param> /// <returns>string, as output of the command.</returns> public static void OpenPowerPoint(string file) { Microsoft.Office.Interop.PowerPoint.Application pptApp = new Microsoft.Office.Interop.PowerPoint.Application(); Microsoft.Office.Core.MsoTriState ofalse = Microsoft.Office.Core.MsoTriState.msoFalse; Microsoft.Office.Core.MsoTriState otrue = Microsoft.Office.Core.MsoTriState.msoTrue; pptApp.Visible = otrue; pptApp.Activate(); Microsoft.Office.Interop.PowerPoint.Presentations ps = pptApp.Presentations; Microsoft.Office.Interop.PowerPoint.Presentation p = ps.Open(file, ofalse, ofalse, otrue); System.Diagnostics.Debug.Print(p.Windows.Count.ToString()); MessageBox.Show(pptApp.ActiveWindow.Caption); }
public void ppt2pdf(string pptfile, string pdfname, string pdfpath, string prefix) { Console.WriteLine("PPT File Location:" + pptfile); Microsoft.Office.Interop.PowerPoint.Application pptApplication = new Microsoft.Office.Interop.PowerPoint.Application(); Presentation pptPresentation = pptApplication.Presentations .Open(pptfile, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse); //Save as PDF for text Extraction pdfpath = pdfpath + @"\" + pdfname + ".pdf"; //Publish PPT - to - PDF try { // publishes hidden slide to pdf // pptPresentation.ExportAsFixedFormat(pdfpath, PpFixedFormatType.ppFixedFormatTypePDF, PpFixedFormatIntent.ppFixedFormatIntentPrint, MsoTriState.msoFalse, PpPrintHandoutOrder.ppPrintHandoutHorizontalFirst, PpPrintOutputType.ppPrintOutputSlides, MsoTriState.msoTrue); object unknownType = Type.Missing; if (pptPresentation != null) { pptPresentation.ExportAsFixedFormat((string)pdfpath, PowerPoint.PpFixedFormatType.ppFixedFormatTypePDF, PowerPoint.PpFixedFormatIntent.ppFixedFormatIntentPrint, MsoTriState.msoFalse, PowerPoint.PpPrintHandoutOrder.ppPrintHandoutVerticalFirst, PowerPoint.PpPrintOutputType.ppPrintOutputSlides, MsoTriState.msoTrue, null, PowerPoint.PpPrintRangeType.ppPrintAll, string.Empty, true, true, true, true, false, unknownType); } // do not publish hidden slides to pdf - messes up slide # b/w ppt and pdf // pptPresentation.ExportAsFixedFormat(pdfpath, PpFixedFormatType.ppFixedFormatTypePDF, PpFixedFormatIntent.ppFixedFormatIntentPrint, MsoTriState.msoFalse); } catch (Exception ex) { Console.Write(ex.ToString()); Console.ReadLine(); return; } }
/// <summary> /// PPT 2 PDF /// </summary> /// <param name="sourcePath">源路径</param> /// <param name="targetPath">目标路径</param> /// <returns></returns> public static bool PptToPNG(string sourcePath, string targetPath) { bool result; PowerPoint.PpSaveAsFileType targetFileType = PowerPoint.PpSaveAsFileType.ppSaveAsPNG; object missing = Type.Missing; Microsoft.Office.Interop.PowerPoint.Application application = null; PowerPoint.Presentation persentation = null; try { application = new Microsoft.Office.Interop.PowerPoint.Application(); persentation = application.Presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse); persentation.SaveAs(targetPath, targetFileType, Microsoft.Office.Core.MsoTriState.msoTrue); result = true; } catch { result = false; } finally { if (persentation != null) { persentation.Close(); persentation = null; } if (application != null) { application.Quit(); application = null; } GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); } return(result); }
public PowerPointDocumentParser(string inputFilePath, EquationToLaTeXConverter form) { this.form = form; char[] separator = { '\\' }; string[] directories = inputFilePath.Split(separator, StringSplitOptions.RemoveEmptyEntries); string dir = ""; for (int i = 0; i < directories.Length - 1; i++) { dir += directories[i] + '\\'; } this.inputFileDir = dir; this.inputFileName = directories[directories.Length - 1]; Console.WriteLine(inputFileName); this.app = new PowerPoint.Application(); object isVisible = true; File.SetAttributes(inputFilePath, FileAttributes.Normal); if (form.checkBox1.Checked == false) { pptOpen = this.app.Presentations.Open(inputFilePath, MsoTriState.msoFalse, MsoTriState.msoFalse, WithWindow: MsoTriState.msoFalse); } if (form.checkBox1.Checked == true) { pptOpen = this.app.Presentations.Open(inputFilePath, MsoTriState.msoTrue, MsoTriState.msoTrue, WithWindow: MsoTriState.msoTrue); } //pptOpen.Activate(); this.slides = pptOpen.Slides; }
/************************** FINAL *****************************/ void mergePPTs(string pptfile2, string pptfile1) { Console.WriteLine("PPT File Location:" + pptfile1 + ", " + pptfile2); PowerPoint.Application pptApplication1 = new Microsoft.Office.Interop.PowerPoint.Application(); PowerPoint.Application pptApplication2 = new Microsoft.Office.Interop.PowerPoint.Application(); PowerPoint.Application app = new PowerPoint.Application(); Presentation pptPresentation1 = pptApplication1.Presentations.Open(pptfile1, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse); Presentation pptPresentation2 = pptApplication1.Presentations.Open(pptfile2, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse); //Take the first PPT and and merge rest. pptPresentation1.SaveAs(exeBase + @"\" + @"temp.pptx", PowerPoint.PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoTrue); pptPresentation1.Close(); PowerPoint.Presentation mergedPPT = app.Presentations.Open(exeBase + @"\" + @"temp.pptx", MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoTrue); int slide_count = 5; // pptPresentation1.Slides.Count; Console.Write("count=" + slide_count); //mergedPPT.Slides.InsertFromFile(pptfile1, 1, -1); mergedPPT.Slides.InsertFromFile(pptfile2, 0, 1, -1); mergedPPT.SaveAs(exeBase + @"\" + @"merged.pptx", PowerPoint.PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoTrue); mergedPPT.Close(); app.Quit(); for (int i = 1; i <= slide_count; ++i) { /* full HD*/ //pptPresentation1.Slides[i].Export(imageBase + @"\" + prefix + "slide" + i + ".png", "png", 800, 600); /* Thumbnail*/ //pptPresentation1.Slides[i].Export(imageBase + @"\" + prefix + "thumb.slide" + i + ".png", "png", 320, 240); } }
public void pptThumbnail(string sourceFile, string targetFile, int thumbW, int thumbH) { // Open the document and convert into HTML pages Microsoft.Office.Interop.PowerPoint.Application oApp = new Microsoft.Office.Interop.PowerPoint.Application(); PowerPoint.Presentation oDoc = oApp.Presentations.Open( sourceFile, Microsoft.Office.Core.MsoTriState.msoTrue, // read only Microsoft.Office.Core.MsoTriState.msoTrue, // untitled Microsoft.Office.Core.MsoTriState.msoFalse); // with window string tmpHtmlFile = System.IO.Path.GetTempFileName() + ".html"; oApp.Presentations[1].SaveCopyAs( tmpHtmlFile, PowerPoint.PpSaveAsFileType.ppSaveAsHTML, // format Microsoft.Office.Core.MsoTriState.msoTrue); // embed true type font // Create the thumbnail from the HTML pages Size browserSize = new Size(800, 800); WebBrowser browser = new WebBrowser(); browser.Size = browserSize; browser.Navigate(tmpHtmlFile); while (WebBrowserReadyState.Complete != browser.ReadyState) { Application.DoEvents(); } Bitmap bm = new Bitmap(browserSize.Width, browserSize.Height); browser.DrawToBitmap(bm, new Rectangle(0, 0, browserSize.Width, browserSize.Height)); Bitmap thumbnail = new Bitmap(thumbW, thumbH); Graphics g = Graphics.FromImage(thumbnail); g.DrawImage( bm, new Rectangle(0, 0, thumbnail.Width, thumbnail.Height), new Rectangle(0, 0, browserSize.Width, browserSize.Height), GraphicsUnit.Pixel); thumbnail.Save(targetFile); }
private static string SaveAsPptx(string pptPathIn) { Microsoft.Office.Interop.PowerPoint.Application presentationApp = new Microsoft.Office.Interop.PowerPoint.Application(); string pptxPathOut = null; try { string pptDir = Path.GetDirectoryName(pptPathIn); string pptFileNameOnly = Path.GetFileNameWithoutExtension(pptPathIn); pptxPathOut = Path.Combine(pptDir, pptFileNameOnly + ".pptx"); presentationApp.Visible = Microsoft.Office.Core.MsoTriState.msoTrue; Microsoft.Office.Interop.PowerPoint.Presentations presentations = presentationApp.Presentations; Microsoft.Office.Core.MsoTriState readOnly = Microsoft.Office.Core.MsoTriState.msoFalse; Microsoft.Office.Core.MsoTriState untitled = Microsoft.Office.Core.MsoTriState.msoFalse; Microsoft.Office.Core.MsoTriState withWindow = Microsoft.Office.Core.MsoTriState.msoFalse; Debug.Print("Opening ppt file {0} ...", pptPathIn); Microsoft.Office.Interop.PowerPoint.Presentation presentation = presentations.Open(pptPathIn, readOnly, untitled, withWindow); Debug.Print("Starting creation of pptx from ppt {0}", pptPathIn); presentation.SaveCopyAs(pptxPathOut, PowerPoint.PpSaveAsFileType.ppSaveAsOpenXMLPresentation, Microsoft.Office.Core.MsoTriState.msoFalse); Debug.Print("Successfully created pptx {0} from ppt {1}", pptxPathOut, pptPathIn); } catch (Exception e) { Debug.Print("Error during creating pptx from ppt " + pptPathIn, e); } finally { presentationApp.Quit(); } return(pptxPathOut); }
static void Main(string[] args) { if (args.Length == 0) { Console.WriteLine(@"Usage: ppt2img <ppt|pptx> [options] Option: -t|--type <png|jpg> -o|--output <dir>"); return; } try { for (int i = 0; i < args.Length; ++i) { if (args[i] == "--type" || args[i] == "-t") { ++i; imgType = args[i]; } else if (args[i] == "--output" || args[i] == "-o") { ++i; outDir = args[i]; } else if (inPpt.Length == 0) { inPpt = args[i]; } else { throw new Exception("Unknow option '" + args[i] + "'"); } } } catch (Exception e) { Console.WriteLine("Invalid args"); Console.WriteLine("{0}", e.Message); return; } outDir = Path.GetFullPath(outDir); inPpt = Path.GetFullPath(inPpt); baseName = Path.GetFileNameWithoutExtension(inPpt); Microsoft.Office.Interop.PowerPoint.Application PowerPoint_App = new Microsoft.Office.Interop.PowerPoint.Application(); Microsoft.Office.Interop.PowerPoint.Presentations multi_presentations = PowerPoint_App.Presentations; Microsoft.Office.Interop.PowerPoint.Presentation presentation = multi_presentations.Open(inPpt, MsoTriState.msoTrue /* ReadOnly=true */, MsoTriState.msoTrue /* Untitled=true */, MsoTriState.msoFalse /* WithWindow=false */); int count = presentation.Slides.Count; for (int i = 0; i < count; i++) { Console.WriteLine("Saving slide {0} of {1}...", i + 1, count); String outName = String.Format(@"{0}\{1}_slide{2}.{3}", outDir, baseName, i, imgType); try { presentation.Slides[i + 1].Export(outName, imgType, width, height); } catch (Exception e) { Console.WriteLine("Failed to export slide {0}", i + 1); Console.WriteLine("{0}", e.Message); break; } } Console.WriteLine("Done"); }
static void Main(string[] args) { Console.WriteLine("schliesse alte Präsentationen"); KillProcessByName("POWERPNT"); List<string> AcceptedSuffixes = new List<string>(); AcceptedSuffixes.Add(".ppt"); AcceptedSuffixes.Add(".pptx"); AcceptedSuffixes.Add(".pdf"); AcceptedSuffixes.Add(".pwww"); string Path = "C:\\slides\\"; PresenterFolder Folder = new PresenterFolder(AcceptedSuffixes, Path); Console.WriteLine(Folder.ToString()); Console.Write("press any key to continue ..."); Console.ReadLine(); PresenterFile CurrentPresenterFile = Folder.GetCurrentPresenterFile(); Console.WriteLine(CurrentPresenterFile.ToString()); Console.Write("press any key to continue ..."); Console.ReadLine(); try { PowerPoint.Application oPPT; PowerPoint.Presentations objPresSet; PowerPoint.Presentation objPres; //the location of your powerpoint presentation string strPres = CurrentPresenterFile.Filename; //Create an instance of PowerPoint. oPPT = new Microsoft.Office.Interop.PowerPoint.Application(); // Show PowerPoint to the user. oPPT.Visible = Microsoft.Office.Core.MsoTriState.msoTrue; objPresSet = oPPT.Presentations; //open the presentation objPres = objPresSet.Open(strPres, MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue); objPres.SlideShowSettings.LoopUntilStopped = MsoTriState.msoTrue; foreach (PowerPoint.Slide slide in objPres.Slides) { Console.WriteLine(slide.SlideShowTransition.AdvanceTime); slide.SlideShowTransition.AdvanceOnTime = MsoTriState.msoTrue; slide.SlideShowTransition.AdvanceTime = 1; } //Console.ReadLine(); //TextReader tr = new StreamReader(folder + "zusatz_info\\an.txt"); //if (tr.ReadLine() == "voll") //{ // foreach (Microsoft.Office.Interop.PowerPoint.Slide s in objPres.Slides) // { // s.Shapes.AddPicture(folder + "zusatz_info\\das_haus_ist_voll.gif", MsoTriState.msoTrue, MsoTriState.msoFalse, 0, 500, 720, 40); // } //} objPres.SlideShowSettings.Run(); } catch (Exception Ex) { Console.WriteLine("Die gewählte Datei kann nicht abgespielt werden."); Console.WriteLine(Ex.Message); } }
/* * http://mantascode.com/c-get-text-content-from-microsoft-powerpoint-file/ */ // under construction - still buggy on: shape.Chart to string public void readPPTText(string pptfile) { Microsoft.Office.Interop.PowerPoint.Application PowerPoint_App = new Microsoft.Office.Interop.PowerPoint.Application(); Microsoft.Office.Interop.PowerPoint.Presentations multi_presentations = PowerPoint_App.Presentations; Microsoft.Office.Interop.PowerPoint.Presentation presentation = multi_presentations.Open(pptfile, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse); /* MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse * required to not open the file in a separate process. */ string presentation_text = ""; string fulltext = ""; for (int i = 0; i < presentation.Slides.Count; i++) { //fulltext += "\n\n"; //fulltext += "Slide:" + (i + 1) + " || "; Console.WriteLine("______Slide # " + (i + 1) + "________"); foreach (var item in presentation.Slides[i + 1].Shapes) { var shape = (Microsoft.Office.Interop.PowerPoint.Shape)item; /* if shape object is a group of shapes * http://www.pptfaq.com/FAQ00600_Changing_shapes_within_groups_-without_ungrouping-.htm */ if (shape.Type == MsoShapeType.msoGroup) { Console.WriteLine(shape.GroupItems.Count); for (int j = 1; j <= shape.GroupItems.Count; ++j) { string temp = getShapeText((Microsoft.Office.Interop.PowerPoint.Shape)shape.GroupItems[j]); fulltext += temp; presentation_text += temp; } } /* else if shape object is NOT group of shapes and just a Shape*/ else { string temp = getShapeText(shape); fulltext += temp; presentation_text += temp; } } presentation_text = presentation_text.Replace("\"", " ").Replace("\'", " ").Replace("\n", " ").Replace("\r", " "); //presentation_text= presentation_text.Replace("\'", " "); //Console.WriteLine("insert into weekly (filename, hashtext, imgthumb, imglarge) values ('" + pptfile + "', '" + presentation_text + "', '/img/weekly/" + pptfile + "thumb_slide" + (i + 1) + ".png', '/img/weekly/" + pptfile + "slide" + (i + 1) + ".png') "); //db.Insert("insert into weekly (filename, hashtext, imgthumb, imglarge) values ('" + pptfile + "', '" + presentation_text + "', '/img/weekly/" + pptfile + "_slide" + (i + 1) + ".png', '/img/weekly/" + pptfile + "_slide" + (i + 1) + ".png') "); Console.Write("Slide:" + (i + 1) + ":\n" + presentation_text); Console.Write("\n "); Console.ReadKey(); presentation_text = ""; } //System.IO.File.WriteAllText("G:\\text.txt",fulltext); System.IO.File.WriteAllText("text.txt", fulltext); PowerPoint_App.Quit(); Console.WriteLine(presentation_text); Console.ReadLine(); }
/* Version not working accurately [DO NOT USE] * PPT to Text */ public void ppt2text(string pptfile) { Console.WriteLine("PPT File Location:" + pptfile); Microsoft.Office.Interop.PowerPoint.Application pptApplication = new Microsoft.Office.Interop.PowerPoint.Application(); Presentation pptPresentation = pptApplication.Presentations .Open(pptfile, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse); System.IO.File.WriteAllText(@".\OutText.md", "#Summary of slides:\n"); foreach (Microsoft.Office.Interop.PowerPoint.Slide slide in pptPresentation.Slides) { //if (slide.SlideNumber > 20) return; string pps = ""; string slide_title = "NOTITLE"; // slide.Shapes.Title.TextFrame.TextRange.Text; //string slide_title = slide.Shapes.Title.TextFrame.TextRange.Text; try { if (slide.Shapes.Title.HasTextFrame == Microsoft.Office.Core.MsoTriState.msoTrue) { var textFrame = slide.Shapes.Title.TextFrame; if (textFrame.HasText == Microsoft.Office.Core.MsoTriState.msoTrue) { var textRange = textFrame.TextRange; var paragraphs = textRange.Paragraphs(-1, -1); foreach (PowerPoint.TextRange paragraph in paragraphs) { var text = paragraph.Text; text = text.Replace("\r", ""); text = Regex.Replace(text, @"[^\t\r\n\u0020-\u007E]+", " "); text = Regex.Replace(text, @"[ ]{ 2,}", string.Empty); if (text.Length > 2) { slide_title = slide_title.Replace("NOTITLE", "").Replace("\v", " ").Replace("\f", " ") + text + "\n"; slide_title = Regex.Replace(slide_title, @"[^\t\r\n\u0020-\u007E]+", string.Empty); } } } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } Console.WriteLine("@" + slide_title); foreach (Microsoft.Office.Interop.PowerPoint.Shape shape in slide.Shapes) { pps += readShape(shape); } pps = Regex.Replace(pps, @"[^\t\r\n\u0020-\u007E]+", string.Empty); Console.WriteLine("Slide #" + slide.SlideNumber + "\n-----------------------\n" + pps + "\n-----------------------\n"); System.IO.File.AppendAllText(@".\OutText.md", "---\nSlide #" + slide.SlideNumber + "\n# " + slide_title); System.IO.File.AppendAllText(@".\OutText.md", "\n" + pps + "\n"); } pptPresentation.Close(); }
private void рекламаToolStripMenuItem_Click(object sender, EventArgs e) { Microsoft.Office.Interop.PowerPoint.Application ppApp = new Microsoft.Office.Interop.PowerPoint.Application(); ppApp.Visible = Microsoft.Office.Core.MsoTriState.msoTrue; Microsoft.Office.Interop.PowerPoint.Presentations oPresSet = ppApp.Presentations; Microsoft.Office.Interop.PowerPoint._Presentation oPres = oPresSet.Open(@"C:\MenshikovaLab\Commerical\Реклама.pptx", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue); }