Skip to content

Commit

Permalink
Quick'n dirty : got ordered slides, images, titles and text
Browse files Browse the repository at this point in the history
  • Loading branch information
timdams committed Sep 25, 2013
1 parent e38b98c commit d075257
Show file tree
Hide file tree
Showing 5 changed files with 275 additions and 0 deletions.
20 changes: 20 additions & 0 deletions PPT_To_Latex.sln
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PPT_To_Latex", "PPT_To_Latex\PPT_To_Latex.csproj", "{F44BEBCA-A0EC-45D6-A810-8A5532FD8E8F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F44BEBCA-A0EC-45D6-A810-8A5532FD8E8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F44BEBCA-A0EC-45D6-A810-8A5532FD8E8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F44BEBCA-A0EC-45D6-A810-8A5532FD8E8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F44BEBCA-A0EC-45D6-A810-8A5532FD8E8F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions PPT_To_Latex/App.config
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
60 changes: 60 additions & 0 deletions PPT_To_Latex/PPT_To_Latex.csproj
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{F44BEBCA-A0EC-45D6-A810-8A5532FD8E8F}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PPT_To_Latex</RootNamespace>
<AssemblyName>PPT_To_Latex</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="DocumentFormat.OpenXml, Version=2.0.5022.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
153 changes: 153 additions & 0 deletions PPT_To_Latex/Program.cs
@@ -0,0 +1,153 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DocumentFormat.OpenXml.Office.Drawing;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Presentation;
using Shape = DocumentFormat.OpenXml.Presentation.Shape;

namespace PPT_To_Latex
{
class Program
{
static void Main(string[] args)
{
// http://stackoverflow.com/questions/7070074/how-can-i-retrieve-images-from-a-pptx-file-using-ms-open-xml-sdk

// http://msdn.microsoft.com/en-us/library/bb448854.aspx
bool includeHidden = false;


using (PresentationDocument presentationDocument = PresentationDocument.Open("test.pptx", false))
{
PresentationPart presentationPart = presentationDocument.PresentationPart;

//Count slides
int slidesCount = 0;
if (includeHidden)
{
slidesCount = presentationPart.SlideParts.Count();
}
else
{
var slides = presentationPart.SlideParts.Where((s) => (s.Slide != null) && ((s.Slide.Show == null) || (s.Slide.Show.HasValue && s.Slide.Show.Value)));
slidesCount = slides.Count();
}
Console.WriteLine("Slides counts={0}", slidesCount);

Presentation presentation = presentationPart.Presentation;









foreach (SlideId slideId in presentation.SlideIdList)

// foreach (var slide in presentationPart.SlideParts)
{

String relId = slideId.RelationshipId.Value;

SlidePart slide = (SlidePart)presentation.PresentationPart.GetPartById(relId);
// Perform actions on SlidePart.


Console.WriteLine("\n\n\n********************************");
//Get title
var shapes = from shape in slide.Slide.Descendants<Shape>()
where IsTitleShape(shape)
select shape;
StringBuilder paragraphTexttit = new StringBuilder();
string paragraphSeparator = null;
foreach (var shape in shapes)
{
// Get the text in each paragraph in this shape.
foreach (var paragraph in shape.TextBody.Descendants<DocumentFormat.OpenXml.Drawing.Paragraph>())
{
// Add a line break.
paragraphTexttit.Append(paragraphSeparator);

foreach (var text in paragraph.Descendants<DocumentFormat.OpenXml.Drawing.Text>())
{
paragraphTexttit.Append(text.Text);
}

paragraphSeparator = "\n";
}
}
Console.WriteLine("\t\t" + paragraphTexttit.ToString());
Console.WriteLine("----------------------");

//GEt all text

foreach (var paragraph in slide.Slide.Descendants<DocumentFormat.OpenXml.Drawing.Paragraph>())
{
// Create a new string builder.
StringBuilder paragraphText = new StringBuilder();

// Iterate through the lines of the paragraph.
foreach (var text in paragraph.Descendants<DocumentFormat.OpenXml.Drawing.Text>())
{
// Append each line to the previous lines.
paragraphText.Append(text.Text);
}

if (paragraphText.Length > 0)
{
// Add each paragraph to the linked list.
Console.WriteLine(paragraphText.ToString());
}
}

//Get all images
foreach (var pic in slide.Slide.Descendants<Picture>())
{
// First, get relationship id of image
string rId = pic.BlipFill.Blip.Embed.Value;

ImagePart imagePart = (ImagePart)slide.GetPartById(rId);

// Get the original file name.
Console.Out.WriteLine("$$Image:" + imagePart.Uri.OriginalString);
// Get the content type (e.g. image/jpeg).
// Console.Out.WriteLine("content-type: {0}", imagePart.ContentType);

// GetStream() returns the image data
// System.Drawing.Image img = System.Drawing.Image.FromStream(imagePart.GetStream());

// You could save the image to disk using the System.Drawing.Image class
// img.Save(@"c:\temp\temp.jpg");
}

}
}
}
// Determines whether the shape is a title shape.
private static bool IsTitleShape(Shape shape)
{
var placeholderShape = shape.NonVisualShapeProperties.ApplicationNonVisualDrawingProperties.GetFirstChild<PlaceholderShape>();
if (placeholderShape != null && placeholderShape.Type != null && placeholderShape.Type.HasValue)
{
switch ((PlaceholderValues)placeholderShape.Type)
{
// Any title shape.
case PlaceholderValues.Title:

// A centered title.
case PlaceholderValues.CenteredTitle:
return true;

default:
return false;
}
}
return false;
}
}
}
36 changes: 36 additions & 0 deletions PPT_To_Latex/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("PPT_To_Latex")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PPT_To_Latex")]
[assembly: AssemblyCopyright("Copyright © 2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("3430f12b-bd51-4b39-9ed3-80a968edb032")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

0 comments on commit d075257

Please sign in to comment.