C # Learning Note (--c#) convert ppt batch to JPG (the simplest method)

Source: Internet
Author: User

Description (2017-8-1-11:15:46):

1. Haha, I said that Microsoft must have its own way to turn ppt into pictures.

2. Mainly to introduce two Microsoft's own assembly, vs in the direct Add reference, note the version, 12.0 is office2007 it? Anyway, I used the 14.0.

Add two more references when you finish adding:

3. The rest of the code can be seen, very simple, the core code is three lines!

4. Thanks for the following resources:

http://bbs.csdn.net/topics/360019178

In addition StackOverflow is a good thing:

Https://stackoverflow.com/questions/2972263/ppt-slides-to-images

There are Bing search, do not know better than Baidu where to go, add assemblies when encountered a few problems, are in Bing search solution:

http://cn.bing.com/

Xaml:

<window x:class="ppt2jpg. MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="Http://schemas.microsoft.com/winfx/2006/xaml"Title="MainWindow"height=" -"Width="525"> <Grid> <button content="start turning into a picture"Horizontalalignment=" Left"height=" +"margin="366,181,0,0"Verticalalignment="Top"Width="103"click="Button_click_1"/> <label content="ppt Path"Horizontalalignment=" Left"height=" +"margin="46,69,0,0"Verticalalignment="Top"Width=" the"/> <textbox name="Txtboxpath"Horizontalalignment=" Left"height=" *"margin="129,66,0,0"textwrapping="Wrap"text=""Verticalalignment="Top"Width="354"/> </Grid></Window>

Code:

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Windows;usingSystem.Windows.Controls;usingSystem.Windows.Data;usingSystem.Windows.Documents;usingSystem.Windows.Input;usingSystem.Windows.Media;usingSystem.Windows.Media.Imaging;usingSystem.Windows.Navigation;usingSystem.Windows.Shapes;usingMicrosoft.Office.Core;usingMicrosoft.Office.Interop.PowerPoint;usingSystem.IO;namespaceppt2jpg{/// <summary>    ///the interactive logic of MainWindow.xaml/// </summary>     Public Partial classMainwindow:window { PublicMainWindow () {InitializeComponent (); File.delete ("Log.txt"); }        Private voidShowlog (stringlog) {File.appendalltext ("Log.txt","\ r \ n"+ DateTime.Now.ToString () +log); }        Private voidButton_Click (Objectsender, RoutedEventArgs e) {        }        //ppt turn into JPG        Private voidButton_click_1 (Objectsender, RoutedEventArgs e) {            stringPptpath =Txtboxpath.text; if(Pptpath! =""&&directory.exists (Pptpath)) {DirectoryInfo Pptinfos=NewDirectoryInfo (Pptpath); foreach(FileInfo PptinfoinchPptinfos.getfiles ("*.ppt*"))                {                    //Create a picture folder                    if(! Directory.Exists (PptInfo.FullName.Split ('.')[0]) {directory.createdirectory (PptInfo.FullName.Split ('.')[0]); }                    Else                    {                        Continue; }                    //start converting PPT                    Try{ApplicationClass Pptapp=NewApplicationClass (); Presentation Pptpres=PptApp.Presentations.Open (Pptinfo.fullname, Msotristate.msofalse, Msotristate.msofalse, Msotristate.msofalse)                        ;  for(inti =0; i < PptPres.Slides.Count; i++)                        {                            stringImgpath = PptInfo.FullName.Split ('.')[0] +@"\"+ (i +1). ToString () +". jpg"; Pptpres.slides[i+1]. Export (Imgpath,"jpg",960,720); } Console.WriteLine ("has finished converting:"+pptinfo.fullname);                    Pptpres.close (); }                    Catch(Exception) {Console.WriteLine ("Unable to convert:"+pptinfo.fullname); Showlog ("unable to generate picture:"+pptinfo.fullname); Continue; }} MessageBox.Show ("Convert picture Complete! "); }            Else{MessageBox.Show ("the path is empty or does not exist! "); }        }    }}

C # Learning Note (--c#) convert ppt batch to JPG (the simplest method)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.