Aspose.Total for C++ consists of powerful file automation APIs that allows to automate TXT to PPT conversion while using two of it’s APIs. Load your TXT using Aspose.Words for C++ and convert it to HTML, then load the HTML via PowerPoint manipulation C++ API Aspose.Slides for C++ to create a new presentation, and save it as PPT.
TXT to PPT Conversion on C++
- Open TXT file using Document class reference
- Convert TXT to HTML by using Save member function
- Initialize a new Presentation object
- Add an AutoShape in your slide, and add AddTextFrame in it
- Load the HTML content and write it in your Presentation file
- Save the document to PPT format using Save method and set Ppt as SaveFormat
Get Started with C++ File Format APIs
Install from command line as
nuget install Aspose.Total.Cpp or via Package Manager Console of Visual Studio with
Alternatively, get the offline MSI installer or DLLs in a ZIP file from downloads .
// load TXT file with an instance of Document Document document = new Document("template.txt"); System::SharedPtr<Document> doc = System::MakeObject<Document>(u"sourceFile.txt"); // save the document in HTML file format doc->Save(u"HtmlOutput.HTML"); // load the desired the presentation SharedPtr<Presentation> pres = MakeObject<Presentation>(); // access first slide SharedPtr<ISlide> sld = pres->get_Slides()->idx_get(0); // add an AutoShape of Rectangle type SharedPtr<IAutoShape> ashp = sld->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 10, 10, 700, 500); // reset default fill color ashp->get_FillFormat()->set_FillType(FillType::NoFill); // add TextFrame to the Rectangle ashp->AddTextFrame(u" "); // access the text frame SharedPtr<ITextFrame> txtFrame = ashp->get_TextFrame(); // get Paragraphs collection SharedPtr<Aspose::Slides::IParagraphCollection>ParaCollection = txtFrame->get_Paragraphs(); // clear all paragraphs in added text frame ParaCollection->Clear(); // load the HTML file using stream reader SharedPtr<System::IO::StreamReader> tr = MakeObject<System::IO::StreamReader>(HtmlOutput.HTML); // add text from HTML stream reader in text frame ParaCollection->AddFromHtml(tr->ReadToEnd()); // save presentation as Ppt pres->Save(output.ppt, Aspose::Slides::Export::SaveFormat::Ppt);
Load Password Protected TXT Document via C++
Apart from document conversion, Aspose.Words for C++ API allows tons of document manipulation features for C++ developers. In case your Microsoft Word TXT file format is password protected, you can still open it using the API. In order to load the encrypted document, you can use a special constructor overload, which accepts a LoadOptions object. This object contains the Password property, which specifies the password string.
// when loading password protected document, the password is passed to the document's constructor using a LoadOptions object. auto options = MakeObject<LoadOptions>(u"docPassword"); // load the document from the local file system by filename: SharedPtr<Document> doc = MakeObject<Document>(u"Encrypted.txt", options);
Add Comments in PPT Document via C++
While saving TXT as PPT, you can also use Aspose.Slides for C++ to add further features in your PPT document. For instance, you can add comments in your presentation. The presentation slide comment are associated with a particular author. The Presentation class holds the collection of authors in ICommentAuthorCollection that are responsible for adding slide comments. For each author, there is a collection of comments in ICommentCollection.
// instantiate Presentation class SharedPtr<Presentation>pres = MakeObject<Presentation>(); // access first slide SharedPtr<ILayoutSlide>layout = pres->get_LayoutSlides()->idx_get(0); // add empty slide pres->get_Slides()->AddEmptySlide(layout); // adding Author SharedPtr<ICommentAuthor> author = pres->get_CommentAuthors()->AddAuthor(u"John Doe", u"MF"); // set position of comments System::Drawing::PointF point = System::Drawing::PointF(0.2f, 0.2f); // add slide comment for an author on slide 1 author->get_Comments()->AddComment(u"Hello John, this is a slide comment", pres->get_Slides()->idx_get(1), point, DateTime::get_Now()); // access ISlide 1 SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0); // save presentation as Ppt pres->Save(output.ppt, Aspose::Slides::Export::SaveFormat::Ppt);
Other Conversion Options
TXT What is TXT File Format?
A file with .TXT extension represents a text document that contains plain text in the form of lines. Paragraphs in a text document are recognized by carriage returns and are used for better arrangement of file contents. A standard text document can be opened in any text editor or word processing application on different operating systems. All the text contained in such a file is in human-readable format and represented by sequence of characters.Read More
PPT What is PPT File Format?
A file with PPT extension represents PowerPoint file that consists of a collection of slides for displaying as SlideShow. It specifies the Binary File Format used by Microsoft PowerPoint 97-2003. A PPT file can contain several different types of information such as text, bulleted points, images, multimedia and other embedded OLE objects. Microsoft came up with newer file format for PowerPoint, known as PPTX, from 2007 onwards that is based on Office OpenXML and is different from this binary file format. Several other application programs such as OpenOffice Impress and Apple Keynote can also create PPT files.Read More