Skip to content

Commit 45cf5f7

Browse files
Merge pull request #3287 from syncfusion-content/1031944-Modify-Markdown-conversion-UG-Page-dev
Documentation(1031944) : Update Markdown Conversion page in DocIO and PowerPoint UG
2 parents 1e70b47 + 9dde49a commit 45cf5f7

3 files changed

Lines changed: 408 additions & 91 deletions

File tree

Document-Processing/PowerPoint/Conversions/markdown-to-powerpoint.md

Lines changed: 264 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,13 @@ N> Refer to the appropriate tabs in the code snippets section: ***C# [Cross-plat
2828

2929
{% tabs %}
3030

31-
{% highlight c# tabtitle="C# [Cross-platform]" playgroundButtonLink="https://raw.githubusercontent.com/SyncfusionExamples/PowerPoint-Examples/main/Markdown-to-PowerPoint-conversion/Convert-Markdown-to-PowerPoint/.NET/Convert-Markdown-to-PowerPoint/Program.cs" %}
32-
//Open the file as a Stream.
33-
using (FileStream fileStream = new FileStream("Input.md", FileMode.Open, FileAccess.Read))
34-
{
35-
//Load the file stream.
36-
using (IPresentation presentation = Presentation.Open(fileStream))
37-
{
38-
//Save as a Markdown document into the PPTX FileStream.
39-
using (FileStream outputStream = new FileStream("MarkdownToPPTX.pptx", FileMode.Create))
40-
{
41-
presentation.Save(outputStream);
42-
}
43-
}
44-
}
31+
{% highlight c# tabtitle="C# [Cross-platform]" %}
32+
// Open an existing Markdown file.
33+
using (IPresentation presentation = Presentation.Open("Input.md"))
34+
{
35+
//Save as a PowerPoint document.
36+
presentation.Save("MarkdownToPPTX.pptx");
37+
}
4538
{% endhighlight %}
4639

4740
{% highlight c# tabtitle="C# [Windows-specific]" %}
@@ -65,7 +58,263 @@ End Using
6558

6659
T> You can also save the markdown file as [HTML](https://help.syncfusion.com/document-processing/word/word-library/net/html), [PDF](https://help.syncfusion.com/document-processing/word/conversions/word-to-pdf/net/word-to-pdf), [Image](https://help.syncfusion.com/document-processing/word/conversions/word-to-image/net/word-to-image), and [Word](https://help.syncfusion.com/document-processing/word/conversions/markdown-to-word-conversion)
6760

68-
N> 1. In Markdown to PowerPoint Presentation conversion, invalid images are replaced with a red "X" image instead of the original image.
61+
N> 1. Hook the event handler before opening a PowerPoint presentation as per the below code example.
62+
N> 2. In Markdown to PowerPoint Presentation conversion, invalid images are replaced with a red "X" image instead of the original image.
63+
64+
## Load Options
65+
66+
When opening an existing Markdown document, the .NET PowerPoint library provides custom import settings through the **LoadOptions** class. This allows you to customize how the Markdown content is parsed and imported into a PowerPoint Presentation.
67+
68+
### Customize image data
69+
70+
The .NET PowerPoint library provides an `ImageNodeVisited` event, which customizes image data while importing a Markdown file. Implement the logic to customize the image data by using this `ImageNodeVisited` event.
71+
72+
The following code example shows how to load image data based on the image source path when importing the Markdown files.
73+
74+
{% tabs %}
75+
76+
{% highlight c# tabtitle="C# [Cross-platform]" %}
77+
// Create load options.
78+
LoadOptions loadOptions = new LoadOptions();
79+
// Specify the format type as Markdown.
80+
loadOptions.FormatType = FormatType.Markdown;
81+
// Initialize Markdown import settings for the LoadOptions instance.
82+
loadOptions.MdImportSettings = new Syncfusion.Office.Markdown.MdImportSettings();
83+
// Hook the event to customize the image while importing Markdown document.
84+
loadOptions.MdImportSettings.ImageNodeVisited += MdImportSettings_ImageNodeVisited;
85+
// Open the Markdown file with load options.
86+
using (IPresentation presentation = Presentation.Open(Path.GetFullPath("Data/Input.md"), loadOptions))
87+
{
88+
// Save as a PowerPoint document.
89+
presentation.Save(Path.GetFullPath(@"Output/Output.pptx"));
90+
}
91+
{% endhighlight %}
92+
93+
{% highlight c# tabtitle="C# [Windows-specific]" %}
94+
// Create load options.
95+
LoadOptions loadOptions = new LoadOptions();
96+
// Specify the format type as Markdown.
97+
loadOptions.FormatType = FormatType.Markdown;
98+
// Initialize Markdown import settings for the LoadOptions instance.
99+
loadOptions.MdImportSettings = new Syncfusion.Office.Markdown.MdImportSettings();
100+
// Hook the event to customize the image while importing Markdown document.
101+
loadOptions.MdImportSettings.ImageNodeVisited += MdImportSettings_ImageNodeVisited;
102+
// Open the Markdown file with load options.
103+
using (IPresentation presentation = Presentation.Open("Input.md", loadOptions))
104+
{
105+
// Save as a PowerPoint document.
106+
presentation.Save("MarkdownToPPTX.pptx");
107+
}
108+
{% endhighlight %}
109+
110+
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
111+
' Create load options.
112+
Dim loadOptions As New LoadOptions()
113+
' Specify the format type as Markdown.
114+
loadOptions.FormatType = FormatType.Markdown
115+
' Initialize Markdown import settings for the LoadOptions instance.
116+
loadOptions.MdImportSettings = New Syncfusion.Office.Markdown.MdImportSettings()
117+
' Hook the event to customize the image while importing Markdown document.
118+
AddHandler loadOptions.MdImportSettings.ImageNodeVisited, AddressOf MdImportSettings_ImageNodeVisited
119+
'Open the Markdown file with load options.
120+
Using presentation As IPresentation = Presentation.Open("Input.md", loadOptions)
121+
'Save as a PowerPoint document.
122+
presentation.Save("MarkdownToPPTX.pptx")
123+
End Using
124+
{% endhighlight %}
125+
126+
{% endtabs %}
127+
128+
The following code examples show the event handler to customize the image based on the source path.
129+
130+
{% tabs %}
131+
132+
{% highlight c# tabtitle="C# [Cross-platform]" %}
133+
private static void MdImportSettings_ImageNodeVisited(object sender, Syncfusion.Office.Markdown.MdImageNodeVisitedEventArgs args)
134+
{
135+
//Set the image stream based on the image name from the input Markdown.
136+
if (args.Uri == "Image_1.png")
137+
args.ImageStream = new FileStream("Image_1.png", FileMode.Open);
138+
else if (args.Uri == "Image_2.png")
139+
args.ImageStream = new FileStream("Image_2.png", FileMode.Open);
140+
//Retrieve the image from the website and use it.
141+
else if (args.Uri.StartsWith("https://"))
142+
{
143+
WebClient client = new WebClient();
144+
//Download the image as a stream.
145+
byte[] image = client.DownloadData(args.Uri);
146+
Stream stream = new MemoryStream(image);
147+
//Set the retrieved image from the input Markdown.
148+
args.ImageStream = stream;
149+
}
150+
}
151+
{% endhighlight %}
152+
153+
{% highlight c# tabtitle="C# [Windows-specific]" %}
154+
private static void MdImportSettings_ImageNodeVisited(object sender, Syncfusion.Office.Markdown.MdImageNodeVisitedEventArgs args)
155+
{
156+
//Set the image stream based on the image name from the input Markdown.
157+
if (args.Uri == "Image_1.png")
158+
args.ImageStream = new FileStream("Image_1.png", FileMode.Open);
159+
else if (args.Uri == "Image_2.png")
160+
args.ImageStream = new FileStream("Image_2.png", FileMode.Open);
161+
//Retrieve the image from the website and use it.
162+
else if (args.Uri.StartsWith("https://"))
163+
{
164+
WebClient client = new WebClient();
165+
//Download the image as a stream.
166+
byte[] image = client.DownloadData(args.Uri);
167+
Stream stream = new MemoryStream(image);
168+
//Set the retrieved image from the input Markdown.
169+
args.ImageStream = stream;
170+
}
171+
}
172+
{% endhighlight %}
173+
174+
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
175+
Private Shared Sub MdImportSettings_ImageNodeVisited(ByVal sender As Object, ByVal args As Syncfusion.Office.Markdown.MdImageNodeVisitedEventArgs)
176+
'Set the image stream based on the image name from the input Markdown.
177+
If args.Uri Is "Image_1.png" Then
178+
args.ImageStream = New FileStream("Image_1.png", FileMode.Open)
179+
ElseIf args.Uri Is "Image_2.png" Then
180+
args.ImageStream = New FileStream("Image_2.png", FileMode.Open)
181+
'Retrieve the image from the website and use it.
182+
ElseIf args.Uri.StartsWith("https://") Then
183+
Dim client As WebClient = New WebClient()
184+
'Download the image as a stream.
185+
Dim image As Byte() = client.DownloadData(args.Uri)
186+
Dim stream As Stream = New MemoryStream(image)
187+
'Set the retrieved image from the input Markdown.
188+
args.ImageStream = stream
189+
End If
190+
End Sub
191+
{% endhighlight %}
192+
193+
{% endtabs %}
194+
195+
N> Hook the event handler before opening a PowerPoint Presentation as per the above code example.
196+
197+
### Encoding
198+
199+
The .NET PowerPoint library provides an `Encoding` property to specify the character encoding to use when opening a Markdown file. This property is useful when you need to open Markdown files that are saved with specific character encodings such as UTF-8, UTF-16, ASCII, or other encodings.
200+
201+
The following code example shows how to open a Markdown file with a specific encoding.
202+
203+
{% tabs %}
204+
205+
{% highlight c# tabtitle="C# [Cross-platform]" %}
206+
// Create load options.
207+
LoadOptions loadOptions = new LoadOptions();
208+
// Specify the format type as Markdown.
209+
loadOptions.FormatType = FormatType.Markdown;
210+
// Initialize Markdown import settings for the LoadOptions instance.
211+
loadOptions.MdImportSettings = new Syncfusion.Office.Markdown.MdImportSettings();
212+
//Set the encoding for the Markdown file.
213+
loadOptions.MdImportSettings.Encoding = Encoding.UTF8;
214+
// Open the Markdown file with load options.
215+
using (IPresentation presentation = Presentation.Open("Input.md", loadOptions))
216+
{
217+
//Save as a PowerPoint document.
218+
presentation.Save("MarkdownToPPTX.pptx");
219+
}
220+
{% endhighlight %}
221+
222+
{% highlight c# tabtitle="C# [Windows-specific]" %}
223+
// Create load options.
224+
LoadOptions loadOptions = new LoadOptions();
225+
// Specify the format type as Markdown.
226+
loadOptions.FormatType = FormatType.Markdown;
227+
// Initialize Markdown import settings for the LoadOptions instance.
228+
loadOptions.MdImportSettings = new Syncfusion.Office.Markdown.MdImportSettings();
229+
// Set the encoding for the Markdown file.
230+
loadOptions.MdImportSettings.Encoding = Encoding.UTF8;
231+
// Open the Markdown file with load options.
232+
using (IPresentation presentation = Presentation.Open("Input.md", loadOptions))
233+
{
234+
//Save as a PowerPoint document.
235+
presentation.Save("MarkdownToPPTX.pptx");
236+
}
237+
{% endhighlight %}
238+
239+
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
240+
'Create load options.
241+
Dim loadOptions As New LoadOptions()
242+
'Specify the format type as Markdown.
243+
loadOptions.FormatType = FormatType.Markdown
244+
' Initialize Markdown import settings for the LoadOptions instance.
245+
loadOptions.MdImportSettings = New Syncfusion.Office.Markdown.MdImportSettings()
246+
'Set the encoding for the Markdown file.
247+
loadOptions.MdImportSettings.Encoding = Encoding.UTF8
248+
' Open the Markdown file with load options.
249+
Using presentation As IPresentation = Presentation.Open("Input.md", loadOptions)
250+
'Save as a PowerPoint document.
251+
presentation.Save("MarkdownToPPTX.pptx")
252+
End Using
253+
{% endhighlight %}
254+
255+
{% endtabs %}
256+
257+
N> Provide the encoding values before opening a PowerPoint Presentation as per the above code example.
258+
259+
### Use Thematic Break As ContentBreak
260+
261+
The .NET PowerPoint library provides a `UseThematicBreakAsContentBreak` property to control how thematic breaks (horizontal lines) in Markdown are handled during conversion. When set to `true`, each thematic break is treated as a content boundary that splits the Markdown content into separate slides in the PowerPoint Presentation.
262+
263+
The following code example shows how to use thematic breaks to split content into multiple slides.
264+
265+
{% tabs %}
266+
267+
{% highlight c# tabtitle="C# [Cross-platform]" %}
268+
// Create load options.
269+
LoadOptions loadOptions = new LoadOptions();
270+
// Specify the format type as Markdown.
271+
loadOptions.FormatType = FormatType.Markdown;
272+
// Initialize Markdown import settings for the LoadOptions instance.
273+
loadOptions.MdImportSettings = new Syncfusion.Office.Markdown.MdImportSettings();
274+
// Set UseThematicBreakAsContentBreak to split slides based on thematic breaks.
275+
loadOptions.MdImportSettings.UseThematicBreakAsContentBreak = true;
276+
// Open the Markdown file with load options.
277+
using (IPresentation presentation = Presentation.Open(Path.GetFullPath("Data/Input.md"), loadOptions))
278+
{
279+
// Save as a PowerPoint document.
280+
presentation.Save(Path.GetFullPath("Output/MarkdownToPPTX.pptx"));
281+
}
282+
{% endhighlight %}
283+
284+
{% highlight c# tabtitle="C# [Windows-specific]" %}
285+
// Create load options.
286+
LoadOptions loadOptions = new LoadOptions();
287+
// Specify the format type as Markdown.
288+
loadOptions.FormatType = FormatType.Markdown;
289+
// Initialize Markdown import settings for the LoadOptions instance.
290+
loadOptions.MdImportSettings = new Syncfusion.Office.Markdown.MdImportSettings();
291+
// Set UseThematicBreakAsContentBreak to split slides based on thematic breaks.
292+
loadOptions.MdImportSettings.UseThematicBreakAsContentBreak = true;
293+
// Open the Markdown file with load options.
294+
using (IPresentation presentation = Presentation.Open("Input.md", loadOptions))
295+
{
296+
// Save as a PowerPoint document.
297+
presentation.Save("MarkdownToPPTX.pptx");
298+
}
299+
{% endhighlight %}
300+
301+
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
302+
' Create load options.
303+
Dim loadOptions As New LoadOptions()
304+
'Specify the format type as Markdown.
305+
loadOptions.FormatType = FormatType.Markdown
306+
' Initialize Markdown import settings for the LoadOptions instance.
307+
loadOptions.MdImportSettings = New Syncfusion.Office.Markdown.MdImportSettings()
308+
' Set UseThematicBreakAsContentBreak to split slides based on thematic breaks.
309+
loadOptions.MdImportSettings.UseThematicBreakAsContentBreak = True
310+
' Open the Markdown file with load options.
311+
Using presentation As IPresentation = Presentation.Open("Input.md", loadOptions)
312+
' Save as a PowerPoint document.
313+
presentation.Save("MarkdownToPPTX.pptx")
314+
End Using
315+
{% endhighlight %}
316+
317+
{% endtabs %}
69318

70319
## Supported Markdown Syntax
71320

0 commit comments

Comments
 (0)