How to Import & Export HTML Text in a PPTX Presentation inside .NET Apps
This technical tip explains how .NET developers can import and export HTML text in PPTX presentation files inside their .NET applications. This topic is also part of a series of topics about managing text paragraphs. Aspose.Slides for .NET has enhanced support for adding HTML text or saving paragraphs text to HTML. This article shows how to manage paragraphs to use HTML data and shows how developers can use this small yet powerful feature. To manage paragraph bullets using Aspose.Slides for .NET:
<br/>
<br/>
• Create an instance of the lPresentation class.
<br/>
• Access the desired slide in slide collection using the ISlide object.
<br/>
• Add an autoshape to the selected slide.
<br/>
• Add and access the ITextFrame of the added shape.
<br/>
• Remove the default paragraph in the ITextFrame.
<br/>
• Read the source HTML file in a TextReader.
<br/>
• Create the first paragraph instance using the Paragraph class.
<br/>
• Add the HTML file content in the read TextReader to the TextFrame's ParagraphCollection.
<br/>
• Save the presentation.
<br/>
//your code here...
// HTML text addition to paragraphs
//[C# Code Sample]
//Create Empty presentation instance//Create Empty presentation instance
using (Presentation pres = new Presentation())
{
//Acesss the default first slide of presentation
ISlide slide = pres.Slides[0];
//Adding the AutoShape to accomodate the HTML content
IAutoShape ashape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 10, 10, pres.SlideSize.Size.Width - 20, pres.SlideSize.Size.Height - 10);
ashape.FillFormat.FillType = FillType.NoFill;
//Adding text frame to the shape
ashape.AddTextFrame("");
//Clearing all paragraphs in added text frame
ashape.TextFrame.Paragraphs.Clear();
//Loading the HTML file using stream reader
TextReader tr = new StreamReader("file.html");
//Adding text from HTML stream reader in text frame
ashape.TextFrame.Paragraphs.AddFromHtml(tr.ReadToEnd());
//Saving Presentation
pres.Save("output.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
}
//[VB.NET Code Sample]
'Create Empty presentation instance
Using pres As New Presentation()
'Acesss the default first slide of presentation
Dim slide As ISlide = pres.Slides(0)
'Adding the AutoShape to accomodate the HTML content
Dim ashape As IAutoShape = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 10, 10, pres.SlideSize.Size.Width - 20, pres.SlideSize.Size.Height - 10)
ashape.FillFormat.FillType = FillType.NoFill
'Adding text frame to the shape
ashape.AddTextFrame("")
'Clearing all paragraphs in added text frame
ashape.TextFrame.Paragraphs.Clear()
'Loading the HTML file using stream reader
Dim tr As TextReader = New StreamReader("file.html")
'Adding text from HTML stream reader in text frame
ashape.TextFrame.Paragraphs.AddFromHtml(tr.ReadToEnd())
'Saving Presentation
pres.Save("output.pptx", Aspose.Slides.Export.SaveFormat.Pptx)
End Using
// Exporting Paragraphs Text to HTML
//[C# Code Sample]
//Load the presentation file
using (Presentation pres = new Presentation("demo.pptx"))
{
//Acesss the default first slide of presentation
ISlide slide = pres.Slides[0];
//Desired index
int index = 0;
//Accessing the added shape
IAutoShape ashape = (IAutoShape)slide.Shapes[index];
// Extracting first paragraph as HTML
StreamWriter sw = new StreamWriter("output.html", false, Encoding.UTF8);
//Writing Paragraphs data to HTML by providing paragraph starting index, total paragraphs to be copied
sw.Write(ashape.TextFrame.Paragraphs.ExportToHtml(0, ashape.TextFrame.Paragraphs.Count, null));
sw.Close();
}
//[VB.NET Code Sample]
'Load the presentation file
Using pres As New Presentation("demo.pptx")
'Acesss the default first slide of presentation
Dim slide As ISlide = pres.Slides(0)
'Desired index
Dim index As Integer = 0
'Accessing the added shape
Dim ashape As IAutoShape = CType(slide.Shapes(index), IAutoShape)
' Extracting first paragraph as HTML
Dim sw As New StreamWriter("output.html", False, Encoding.UTF8)
'Writing Paragraphs data to HTML by providing paragraph starting index, total paragraphs to be copied
sw.Write(ashape.TextFrame.Paragraphs.ExportToHtml(0, ashape.TextFrame.Paragraphs.Count, Nothing))
sw.Close()
End Using
Url: http://www.aspose.com/docs/display/slidesnet/Importing+and+Exporting+HTML+Text+in+PPTX
Language: C# | User: Sheraz Khan | Created: May 13, 2015 | Tags: Import HTML Text in Paragraphs, HTML text addition to paragraphs, Export Paragraphs Text to HTML, HTML generation from paragraph text, .NET PowerPoint API, PowerPoint .NET Component Import HTML Text in Paragraphs HTML text addition to paragraphs Export Paragraphs Text to HTML HTML generation from paragraph text .NET PowerPoint API PowerPoint .NET Component