public TcpChannelServer( PresentationBuilder <TContract> connectionBuilder, IPEndPoint endPoint ) : base(connectionBuilder, new TcpChanelListener(endPoint)) { EndPoint = endPoint; }
public void ReassemblePresentationWithMaster(string fileName) { var file = Path.Combine(SourceDirectory, fileName); var presentation = new PmlDocument(file); // generate presentation with all masters var onlyMaster = PresentationBuilder.BuildPresentation( new List <SlideSource> { new SlideSource(presentation, 0, 0, true) }); // publish slides with one-layout masters var slides = PresentationBuilder.PublishSlides(presentation); // compose them together using only master as the first source var sources = new List <SlideSource> { new SlideSource(onlyMaster, true) }; sources.AddRange(slides.Select(x => new SlideSource(x, false))); var newDocument = PresentationBuilder.BuildPresentation(sources); newDocument.FileName = fileName.Replace(".pptx", "_reassembledWithMaster.pptx"); newDocument.SaveAs(Path.Combine(TargetDirectory, newDocument.FileName)); var baseSize = slides.Sum(x => x.DocumentByteArray.Length) + onlyMaster.DocumentByteArray.Length; Assert.InRange(newDocument.DocumentByteArray.Length, 0.85 * baseSize, 1.1 * baseSize); }
public void ExtractMasters(string fileName) { var source = new PmlDocument(Path.Combine(SourceDirectory, fileName)); int numberOfMasters; using (var stream = new OpenXmlMemoryStreamDocument(source)) { using var doc1 = stream.GetPresentationDocument(); numberOfMasters = doc1.PresentationPart.SlideMasterParts.Count(); } var onlyMaster = PresentationBuilder.BuildPresentation( new List <SlideSource> { new SlideSource(source, 0, 0, true) }); onlyMaster.FileName = fileName.Replace(".pptx", "_masterOnly.pptx"); onlyMaster.SaveAs(Path.Combine(TargetDirectory, onlyMaster.FileName)); using var streamDoc = new OpenXmlMemoryStreamDocument(onlyMaster); using var resDoc = streamDoc.GetPresentationDocument(); Assert.Empty(resDoc.PresentationPart.SlideParts); Assert.Equal(numberOfMasters, resDoc.PresentationPart.SlideMasterParts.Count()); }
static void Main(string[] args) { var n = DateTime.Now; var tempDi = new DirectoryInfo(string.Format("ExampleOutput-{0:00}-{1:00}-{2:00}-{3:00}{4:00}{5:00}", n.Year - 2000, n.Month, n.Day, n.Hour, n.Minute, n.Second)); tempDi.Create(); string source1 = "../../Contoso.pptx"; string source2 = "../../Companies.pptx"; string source3 = "../../Customer Content.pptx"; string source4 = "../../Presentation One.pptx"; string source5 = "../../Presentation Two.pptx"; string source6 = "../../Presentation Three.pptx"; string contoso1 = "../../Contoso One.pptx"; string contoso2 = "../../Contoso Two.pptx"; string contoso3 = "../../Contoso Three.pptx"; List <SlideSource> sources = null; var sourceDoc = new PmlDocument(source1); sources = new List <SlideSource>() { new SlideSource(sourceDoc, 0, 1, false), // Title new SlideSource(sourceDoc, 1, 1, false), // First intro (of 3) new SlideSource(sourceDoc, 4, 2, false), // Sales bios new SlideSource(sourceDoc, 9, 3, false), // Content slides new SlideSource(sourceDoc, 13, 1, false), // Closing summary }; PresentationBuilder.BuildPresentation(sources).SaveAs(Path.Combine(tempDi.FullName, "Out1.pptx")); sources = new List <SlideSource>() { new SlideSource(new PmlDocument(source2), 2, 1, true), // Choose company new SlideSource(new PmlDocument(source3), false), // Content }; PresentationBuilder.BuildPresentation(sources).SaveAs(Path.Combine(tempDi.FullName, "Out2.pptx")); sources = new List <SlideSource>() { new SlideSource(new PmlDocument(source4), true), new SlideSource(new PmlDocument(source5), true), new SlideSource(new PmlDocument(source6), true), }; PresentationBuilder.BuildPresentation(sources).SaveAs(Path.Combine(tempDi.FullName, "Out3.pptx")); sources = new List <SlideSource>() { new SlideSource(new PmlDocument(contoso1), true), new SlideSource(new PmlDocument(contoso2), true), new SlideSource(new PmlDocument(contoso3), true), }; PresentationBuilder.BuildPresentation(sources).SaveAs(Path.Combine(tempDi.FullName, "Out4.pptx")); }
public MockConnectionPair(PresentationBuilder <TOriginContractInterface> originBuilder, PresentationBuilder <TProxyContractInterface> proxyBuider, bool connect = true) { ClientChannel = new TestChannel(); Server = new TestChannelServer <TOriginContractInterface>(originBuilder); ProxyConnection = proxyBuider.UseChannel(ClientChannel).Build(); if (connect) { Connect(); } }
public static IConnection <TContract, TcpChannel> CreateTcpClientConnection <TContract>( this PresentationBuilder <TContract> builder, IPEndPoint endPoint) where TContract : class { return(builder.UseChannel(() => { var channel = new TcpChannel(); channel.Connect(endPoint); return channel; }).Build()); }
public void ExtractOneSlide(string fileName, int slideNumber) { var file = Path.Combine(SourceDirectory, fileName); var document = new PmlDocument(file); var source = new SlideSource(document, slideNumber - 1, 1, true); var slide = PresentationBuilder.BuildPresentation(new List <SlideSource> { source }); slide.FileName = document.FileName.Replace(".pptx", $"_{slideNumber:000}.pptx"); slide.SaveAs(Path.Combine(TargetDirectory, Path.GetFileName(slide.FileName))); }
public void PB002_Formatting() { var name2 = "PB001-Input2.pptx"; var sourceDir = new DirectoryInfo("../../../../TestFiles/"); var source2Pptx = new FileInfo(Path.Combine(sourceDir.FullName, name2)); var sources = new List <SlideSource>() { new SlideSource(new PmlDocument(source2Pptx.FullName), 0, true), }; var processedDestPptx = new FileInfo(Path.Combine(TestUtil.TempDir.FullName, "PB002-Formatting.pptx")); PresentationBuilder.BuildPresentation(sources, processedDestPptx.FullName); }
public TcpConnectionPair(PresentationBuilder <TOriginContractInterface> originBuilder, PresentationBuilder <TProxyContractInterface> proxyBuider, bool connect = true) { Server = originBuilder.CreateTcpServer(IPAddress.Loopback, 12345); ClientChannel = new TcpChannel(); ProxyConnection = proxyBuider.UseChannel(ClientChannel).Build(); _eventAwaiter = new EventAwaiter <IConnection <TOriginContractInterface, TcpChannel> >(); Server.AfterConnect += _eventAwaiter.EventRaised; if (connect) { Connect(); } }
public void PB002_Formatting() { string name2 = "PB001-Input2.pptx"; FileInfo source2Pptx = new FileInfo(Path.Combine(TestUtil.SourceDir.FullName, name2)); List <SlideSource> sources = null; sources = new List <SlideSource>() { new SlideSource(new PmlDocument(source2Pptx.FullName), 0, true), }; var processedDestPptx = new FileInfo(Path.Combine(TestUtil.TempDir.FullName, "PB002-Formatting.pptx")); PresentationBuilder.BuildPresentation(sources, processedDestPptx.FullName); }
static void Main(string[] args) { string source1 = "../../Contoso.pptx"; string source2 = "../../Companies.pptx"; string source3 = "../../Customer Content.pptx"; string source4 = "../../Presentation One.pptx"; string source5 = "../../Presentation Two.pptx"; string source6 = "../../Presentation Three.pptx"; string contoso1 = "../../Contoso One.pptx"; string contoso2 = "../../Contoso Two.pptx"; string contoso3 = "../../Contoso Three.pptx"; List <SlideSource> sources = null; var sourceDoc = new PmlDocument(source1); sources = new List <SlideSource>() { new SlideSource(sourceDoc, 0, 1, false), // Title new SlideSource(sourceDoc, 1, 1, false), // First intro (of 3) new SlideSource(sourceDoc, 4, 2, false), // Sales bios new SlideSource(sourceDoc, 9, 3, false), // Content slides new SlideSource(sourceDoc, 13, 1, false), // Closing summary }; PresentationBuilder.BuildPresentation(sources, "Out1.pptx"); sources = new List <SlideSource>() { new SlideSource(new PmlDocument(source2), 2, 1, true), // Choose company new SlideSource(new PmlDocument(source3), false), // Content }; PresentationBuilder.BuildPresentation(sources, "Out2.pptx"); sources = new List <SlideSource>() { new SlideSource(new PmlDocument(source4), true), new SlideSource(new PmlDocument(source5), true), new SlideSource(new PmlDocument(source6), true), }; PresentationBuilder.BuildPresentation(sources, "Out3.pptx"); sources = new List <SlideSource>() { new SlideSource(new PmlDocument(contoso1), true), new SlideSource(new PmlDocument(contoso2), true), new SlideSource(new PmlDocument(contoso3), true), }; PresentationBuilder.BuildPresentation(sources, "Out4.pptx"); }
public void Sample1() { var source1 = GetFilePath("Sample1/Contoso.pptx"); var source2 = GetFilePath("Sample1/Companies.pptx"); var source3 = GetFilePath("Sample1/Customer Content.pptx"); var source4 = GetFilePath("Sample1/Presentation One.pptx"); var source5 = GetFilePath("Sample1/Presentation Two.pptx"); var source6 = GetFilePath("Sample1/Presentation Three.pptx"); var contoso1 = GetFilePath("Sample1/Contoso One.pptx"); var contoso2 = GetFilePath("Sample1/Contoso Two.pptx"); var contoso3 = GetFilePath("Sample1/Contoso Three.pptx"); var sourceDoc = new PmlDocument(source1); var sources = new List <SlideSource> { new(sourceDoc, 0, 1, false), // Title new(sourceDoc, 1, 1, false), // First intro (of 3) new(sourceDoc, 4, 2, false), // Sales bios new(sourceDoc, 9, 3, false), // Content slides new(sourceDoc, 13, 1, false), // Closing summary }; PresentationBuilder.BuildPresentation(sources).SaveAs(Path.Combine(TempDir, "Out1.pptx")); sources = new List <SlideSource> { new(new PmlDocument(source2), 2, 1, true), // Choose company new(new PmlDocument(source3), false), // Content }; PresentationBuilder.BuildPresentation(sources).SaveAs(Path.Combine(TempDir, "Out2.pptx")); sources = new List <SlideSource> { new(new PmlDocument(source4), true), new(new PmlDocument(source5), true), new(new PmlDocument(source6), true), }; PresentationBuilder.BuildPresentation(sources).SaveAs(Path.Combine(TempDir, "Out3.pptx")); sources = new List <SlideSource> { new(new PmlDocument(contoso1), true), new(new PmlDocument(contoso2), true), new(new PmlDocument(contoso3), true), }; PresentationBuilder.BuildPresentation(sources).SaveAs(Path.Combine(TempDir, "Out4.pptx")); }
public void ReassemblePresentation(string fileName) { var file = Path.Combine(SourceDirectory, fileName); var document = new PmlDocument(file); var slides = PresentationBuilder.PublishSlides(document); var sources = slides.Select(x => new SlideSource(x, true)).ToList(); var newDocument = PresentationBuilder.BuildPresentation(sources); newDocument.FileName = fileName.Replace(".pptx", "_reassembled.pptx"); newDocument.SaveAs(Path.Combine(TargetDirectory, newDocument.FileName)); var baseSize = slides.Sum(x => x.DocumentByteArray.Length); Assert.InRange(newDocument.DocumentByteArray.Length, 0.9 * baseSize, 1.1 * baseSize); }
public void PB004_Formatting() { var name1 = "PB001-Input1.pptx"; var name2 = "PB001-Input3.pptx"; var sourceDir = new DirectoryInfo("../../../../TestFiles/"); var source1Pptx = new FileInfo(Path.Combine(sourceDir.FullName, name1)); var source2Pptx = new FileInfo(Path.Combine(sourceDir.FullName, name2)); var sources = new List <SlideSource> { new(new PmlDocument(source2Pptx.FullName), 0, true), new(new PmlDocument(source1Pptx.FullName), 1, true), }; var processedDestPptx = new FileInfo(Path.Combine(TempDir, "PB004-Formatting.pptx")); PresentationBuilder.BuildPresentation(sources).SaveAs(processedDestPptx.FullName); }
public void PB004_Formatting() { string name1 = "PB001-Input1.pptx"; string name2 = "PB001-Input3.pptx"; DirectoryInfo sourceDir = new DirectoryInfo("../../../../TestFiles/"); FileInfo source1Pptx = new FileInfo(Path.Combine(sourceDir.FullName, name1)); FileInfo source2Pptx = new FileInfo(Path.Combine(sourceDir.FullName, name2)); List <SlideSource> sources = null; sources = new List <SlideSource>() { new SlideSource(new PmlDocument(source2Pptx.FullName), 0, true), new SlideSource(new PmlDocument(source1Pptx.FullName), 1, true), }; var processedDestPptx = new FileInfo(Path.Combine(TestUtil.TempDir.FullName, "PB004-Formatting.pptx")); PresentationBuilder.BuildPresentation(sources, processedDestPptx.FullName); }
public void PB006_VideoFormats() { // This presentation contains videos with content types video/mp4, video/quicktime, video/unknown, video/x-ms-asf, and video/x-msvideo. var sourceDir = new DirectoryInfo("../../../../TestFiles/"); var sourcePptx = new FileInfo(Path.Combine(sourceDir.FullName, "PP006-Videos.pptx")); var oldMediaDataContentTypes = GetMediaDataContentTypes(sourcePptx); var sources = new List <SlideSource>() { new SlideSource(new PmlDocument(sourcePptx.FullName), true), }; var processedDestPptx = new FileInfo(Path.Combine(TestUtil.TempDir.FullName, "PB006-Videos.pptx")); PresentationBuilder.BuildPresentation(sources, processedDestPptx.FullName); var newMediaDataContentTypes = GetMediaDataContentTypes(processedDestPptx); Assert.Equal(oldMediaDataContentTypes, newMediaDataContentTypes); }
public override IValuePresentation PresentValue(IValueRole <TValue> valueRole, IMetadataTypeLite instanceType, IPresentationOptions options, IUserDataHolder dataHolder, CancellationToken token) { var extraDetail = (ExtraDetailValueReferenceDecorator <TValue>)valueRole.ValueReference; var presentation = extraDetail.UnderlyingValueReference.ToValue(ValueServices).GetValuePresentation(options, token); if (presentation.ResultKind == ValueResultKind.Success) { var presentationBuilder = PresentationBuilder.New(presentation.Value.ToArray()) .Add(ValuePresentationPart.Space) .SpecialSymbol("(").Default(extraDetail.ExtraDetail).SpecialSymbol(")"); return(SimplePresentation.CreateSuccess(presentationBuilder.Result(), presentation.Flags, presentation.Type, presentation.PrimitiveValue)); } return(presentation); }
public void PublishUsingPublishSlides(string sourcePath) { var targetDir = Path.Combine(TargetDirectory, Path.GetFileNameWithoutExtension(sourcePath)); if (Directory.Exists(targetDir)) { Directory.Delete(targetDir, true); } Directory.CreateDirectory(targetDir); var document = new PmlDocument(sourcePath); string title; DateTime?modified; using (var streamDoc = new OpenXmlMemoryStreamDocument(document)) { using var srcDoc = streamDoc.GetPresentationDocument(new OpenSettings { AutoSave = false }); title = srcDoc.PackageProperties.Title; modified = srcDoc.PackageProperties.Modified; } var sameTitle = 0; foreach (var slide in PresentationBuilder.PublishSlides(document)) { slide.SaveAs(Path.Combine(targetDir, Path.GetFileName(slide.FileName))); using var streamDoc = new OpenXmlMemoryStreamDocument(slide); using var slideDoc = streamDoc.GetPresentationDocument(new OpenSettings { AutoSave = false }); Assert.Equal(modified, slideDoc.PackageProperties.Modified); if (title.Equals(slideDoc.PackageProperties.Title)) { sameTitle++; } } Assert.InRange(sameTitle, 0, 4); }
static void Main(string[] args) { string currentdirectory = Directory.GetCurrentDirectory(); string[] listofppt = Directory.GetFiles(currentdirectory, "*.pptx"); NumericComparer ns = new NumericComparer(); Array.Sort(listofppt, ns); Console.WriteLine("The current directory is {0}", currentdirectory); string savename = "COMBINED.pptx"; List <SlideSource> sources = new List <SlideSource>(); if (listofppt.Length > 0) { for (int i = 0; i < listofppt.Count(); i++) { sources.Add(new SlideSource(new PmlDocument(listofppt[i]), true)); } PresentationBuilder.BuildPresentation(sources, savename); } }
public void PublishUsingPublishSlides(string sourcePath) { var targetDir = Path.Combine(TargetDirectory, Path.GetFileNameWithoutExtension(sourcePath)); if (Directory.Exists(targetDir)) { Directory.Delete(targetDir, true); } Directory.CreateDirectory(targetDir); using var srcStream = File.Open(sourcePath, FileMode.Open); var openSettings = new OpenSettings { AutoSave = false }; using var srcDoc = OpenXmlExtensions.OpenPresentation(srcStream, false, openSettings); var title = srcDoc.PackageProperties.Title ?? string.Empty; var modified = srcDoc.PackageProperties.Modified; var sameTitle = 0; foreach (var slide in PresentationBuilder.PublishSlides(srcDoc, sourcePath)) { slide.SaveAs(Path.Combine(targetDir, Path.GetFileName(slide.FileName))); using var streamDoc = new OpenXmlMemoryStreamDocument(slide); using var slideDoc = streamDoc.GetPresentationDocument(new OpenSettings { AutoSave = false }); Assert.Equal(modified, slideDoc.PackageProperties.Modified); if (title.Equals(slideDoc.PackageProperties.Title)) { sameTitle++; } } Assert.InRange(sameTitle, 0, 4); }
public void Sample2() { var presentation = GetFilePath("Sample2/Presentation1.pptx"); var hiddenPresentation = GetFilePath("Sample2/HiddenPresentation.pptx"); // First, load both presentations into byte arrays, simulating retrieving presentations from some source // such as a SharePoint server var baPresentation = File.ReadAllBytes(presentation); var baHiddenPresentation = File.ReadAllBytes(hiddenPresentation); // Next, replace "thee" with "the" in the main presentation var pmlMainPresentation = new PmlDocument("Main.pptx", baPresentation); PmlDocument modifiedMainPresentation; using (var streamDoc = new OpenXmlMemoryStreamDocument(pmlMainPresentation)) { using (var document = streamDoc.GetPresentationDocument()) { var pXDoc = document.PresentationPart.GetXDocument(); foreach (var slideId in pXDoc.Root.Elements(P.sldIdLst).Elements(P.sldId)) { var slideRelId = (string)slideId.Attribute(R.id); var slidePart = document.PresentationPart.GetPartById(slideRelId); var slideXDoc = slidePart.GetXDocument(); var paragraphs = slideXDoc.Descendants(A.p).ToList(); OpenXmlRegex.Replace(paragraphs, new Regex("thee"), "the", null); slidePart.PutXDocument(); } } modifiedMainPresentation = streamDoc.GetModifiedPmlDocument(); } // Combine the two presentations into a single presentation var slideSources = new List <SlideSource> { new(modifiedMainPresentation, 0, 1, true), new(new PmlDocument("Hidden.pptx", baHiddenPresentation), true), new(modifiedMainPresentation, 1, true), }; var combinedPresentation = PresentationBuilder.BuildPresentation(slideSources); // Replace <# TRADEMARK #> with AdventureWorks (c) PmlDocument modifiedCombinedPresentation; using (var streamDoc = new OpenXmlMemoryStreamDocument(combinedPresentation)) { using (var document = streamDoc.GetPresentationDocument()) { var pXDoc = document.PresentationPart.GetXDocument(); foreach (var slideId in pXDoc.Root.Elements(P.sldIdLst).Elements(P.sldId).Skip(1).Take(1)) { var slideRelId = (string)slideId.Attribute(R.id); var slidePart = document.PresentationPart.GetPartById(slideRelId); var slideXDoc = slidePart.GetXDocument(); var paragraphs = slideXDoc.Descendants(A.p).ToList(); OpenXmlRegex.Replace(paragraphs, new Regex("<# TRADEMARK #>"), "AdventureWorks (c)", null); slidePart.PutXDocument(); } } modifiedCombinedPresentation = streamDoc.GetModifiedPmlDocument(); } // we now have a PmlDocument (which is essentially a byte array) that can be saved as necessary. modifiedCombinedPresentation.SaveAs(Path.Combine(TempDir, "ModifiedCombinedPresentation.pptx")); }
public TestChannelServer(PresentationBuilder <TContract> channelBuilder) : base(channelBuilder, new TestChannelListener()) { TestListener = this.Listener as TestChannelListener; }
/// <summary> /// Connect to remote tcp point /// </summary> /// <exception cref="SocketException">Connection failed</exception> public static IConnection <TContract, TcpChannel> CreateTcpClientConnection <TContract>( this PresentationBuilder <TContract> builder, IPAddress ip, int port) where TContract : class { return(CreateTcpClientConnection(builder, new IPEndPoint(ip, port))); }
public static TcpChannelServer <TContract> CreateTcpServer <TContract>(this PresentationBuilder <TContract> builder, IPAddress ip, int port) where TContract : class { return(new TcpChannelServer <TContract>(builder, new IPEndPoint(ip, port))); }
public IValuePresentation GetValuePresentation(IPresentationOptions options, CancellationToken token = new CancellationToken()) { return(SimplePresentation.Create(PresentationBuilder.New().Error(myMessage), myResultKind, ValueFlags.NoChildren, DeclaredType)); }
public override IValuePresentation PresentValue(IObjectValueRole <TValue> valueRole, IMetadataTypeLite instanceType, IPresentationOptions options, IUserDataHolder dataHolder, CancellationToken token) { var showName = (valueRole.ValueReference as CalculatedValueReferenceDecorator <TValue>)?.AllowNameInValue ?? true; var showTypeName = (valueRole.ValueReference as CalculatedValueReferenceDecorator <TValue>) ?.AllowDefaultTypePresentation ?? true; var nameValuePresentation = valueRole.GetInstancePropertyReference("name")?.ToValue(ValueServices) ?.GetValuePresentation(options); var propertyTypeReference = valueRole.GetInstancePropertyReference("propertyType"); var propertyTypeValuePresentation = propertyTypeReference?.ToValue(ValueServices)?.GetValuePresentation(options); var propertyTypeEnumValueObject = propertyTypeReference?.AsObjectSafe(options)?.GetEnumValue(options); var propertyType = (SerializedPropertyKind)Enum.ToObject(typeof(SerializedPropertyKind), propertyTypeEnumValueObject ?? SerializedPropertyKind.Generic); int? arraySize = null; string arrayElementType = null; string genericType = null; if (propertyType == SerializedPropertyKind.Generic) { if (Util.TryEvaluatePrimitiveProperty(valueRole, "isArray", options, out bool isArray) && isArray) { arraySize = valueRole.GetInstancePropertyReference("arraySize")?.AsPrimitiveSafe(options) ?.GetPrimitive <int>(); arrayElementType = valueRole.GetInstancePropertyReference("arrayElementType")?.AsStringSafe(options)?.GetString(); } else if (Util.TryEvaluatePrimitiveProperty(valueRole, "isFixedBuffer", options, out bool isFixedBuffer) && isFixedBuffer) { arraySize = valueRole.GetInstancePropertyReference("fixedBufferSize")?.AsPrimitiveSafe(options) ?.GetPrimitive <int>(); arrayElementType = valueRole.GetInstancePropertyReference("arrayElementType")?.AsStringSafe(options)?.GetString(); } else { genericType = valueRole.GetInstancePropertyReference("type")?.AsStringSafe(options)?.GetString(); } } var valuePresentation = GetValuePresentation(valueRole, propertyType, options, out var extraDetail); var parts = PresentationBuilder.New(); parts.OpenBrace(); if (showName && nameValuePresentation != null) { parts.Comment("name: ").Add(nameValuePresentation.Value.ToArray()) .Add(ValuePresentationPart.Space); } parts.Comment("propertyType: "); if (propertyType == SerializedPropertyKind.Generic && arraySize != null && arrayElementType != null) { parts.Default($"{arrayElementType}[{arraySize}]"); } else if (genericType != null) { parts.Default(genericType); } else if (propertyTypeValuePresentation != null) { parts.Add(propertyTypeValuePresentation.Value.ToArray()); } else { parts.Comment("(Unknown)"); } if (valuePresentation != null) { parts.Add(ValuePresentationPart.Space) .Comment("value: ").Add(valuePresentation.Value.ToArray()); if (!string.IsNullOrEmpty(extraDetail)) { parts.Add(ValuePresentationPart.Space).SpecialSymbol("(").Default(extraDetail).SpecialSymbol(")"); } } parts.ClosedBrace(); // Hide the default type presentation if we've been asked to var flags = !showTypeName ? ValueFlags.IsDefaultTypePresentation : 0; return(SimplePresentation.Create(parts.Result(), ValueResultKind.Success, ValueFlags.None | flags, instanceType)); }
static void Main(string[] args) { var n = DateTime.Now; var tempDi = new DirectoryInfo(string.Format("ExampleOutput-{0:00}-{1:00}-{2:00}-{3:00}{4:00}{5:00}", n.Year - 2000, n.Month, n.Day, n.Hour, n.Minute, n.Second)); tempDi.Create(); string presentation = "../../Presentation1.pptx"; string hiddenPresentation = "../../HiddenPresentation.pptx"; // First, load both presentations into byte arrays, simulating retrieving presentations from some source // such as a SharePoint server var baPresentation = File.ReadAllBytes(presentation); var baHiddenPresentation = File.ReadAllBytes(hiddenPresentation); // Next, replace "thee" with "the" in the main presentation var pmlMainPresentation = new PmlDocument("Main.pptx", baPresentation); PmlDocument modifiedMainPresentation = null; using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(pmlMainPresentation)) { using (PresentationDocument document = streamDoc.GetPresentationDocument()) { var pXDoc = document.PresentationPart.GetXDocument(); foreach (var slideId in pXDoc.Root.Elements(P.sldIdLst).Elements(P.sldId)) { var slideRelId = (string)slideId.Attribute(R.id); var slidePart = document.PresentationPart.GetPartById(slideRelId); var slideXDoc = slidePart.GetXDocument(); var paragraphs = slideXDoc.Descendants(A.p).ToList(); OpenXmlRegex.Replace(paragraphs, new Regex("thee"), "the", null); slidePart.PutXDocument(); } } modifiedMainPresentation = streamDoc.GetModifiedPmlDocument(); } // Combine the two presentations into a single presentation var slideSources = new List <SlideSource>() { new SlideSource(modifiedMainPresentation, 0, 1, true), new SlideSource(new PmlDocument("Hidden.pptx", baHiddenPresentation), true), new SlideSource(modifiedMainPresentation, 1, true), }; PmlDocument combinedPresentation = PresentationBuilder.BuildPresentation(slideSources); // Replace <# TRADEMARK #> with AdventureWorks (c) PmlDocument modifiedCombinedPresentation = null; using (OpenXmlMemoryStreamDocument streamDoc = new OpenXmlMemoryStreamDocument(combinedPresentation)) { using (PresentationDocument document = streamDoc.GetPresentationDocument()) { var pXDoc = document.PresentationPart.GetXDocument(); foreach (var slideId in pXDoc.Root.Elements(P.sldIdLst).Elements(P.sldId).Skip(1).Take(1)) { var slideRelId = (string)slideId.Attribute(R.id); var slidePart = document.PresentationPart.GetPartById(slideRelId); var slideXDoc = slidePart.GetXDocument(); var paragraphs = slideXDoc.Descendants(A.p).ToList(); OpenXmlRegex.Replace(paragraphs, new Regex("<# TRADEMARK #>"), "AdventureWorks (c)", null); slidePart.PutXDocument(); } } modifiedCombinedPresentation = streamDoc.GetModifiedPmlDocument(); } // we now have a PmlDocument (which is essentially a byte array) that can be saved as necessary. modifiedCombinedPresentation.SaveAs(Path.Combine(tempDi.FullName, "Modified.pptx")); }