Why to Convert
Are you a C++ developer looking to add a feature to integrate MHTML to XAML conversion inside your C++ applications? MHTML is a web page archive format that is used to save webpages for offline viewing. XAML is a markup language used to create user interfaces for Windows applications. Converting MHTML to XAML can be useful for developers who want to create a Windows application with a web page interface.
How Aspose.Total Helps for MHTML to XAML Conversion
Converting MHTML to XAML can be done in two simple steps with the help of Aspose.Total for C++. Aspose.Total is a suite of APIs that provides developers with a comprehensive set of tools for creating, editing, and converting documents. The first step is to export MHTML to PPTX by using Aspose.PDF for C++. Aspose.PDF for C++ is a powerful library that enables developers to create, edit, and convert PDF documents. The second step is to convert PPTX to XAML by using Aspose.Slides for C++. Aspose.Slides for C++ is a library that enables developers to create, edit, and convert presentations. Both APIs come under the Aspose.Total for C++ package. With the help of Aspose.Total for C++, developers can easily convert MHTML to XAML in two simple steps.
C++ API to Export MHTML to XAML
- Open MHTML file using Document class reference
- Convert MHTML to PPTX by using Save method function
- Load PPTX document by using Presentation class reference
- Save the document to XAML format using
Save
member function and set
Xaml
as SaveFormat
Get Started with C++ File Automation APIs
Install from command line as nuget install Aspose.Total.Cpp
or via Package Manager Console of Visual Studio with Install-Package Aspose.Total.Cpp
.
Alternatively, get the offline MSI installer or DLLs in a ZIP file from downloads .
// load MHTML file with an instance of Document class
auto doc = MakeObject<Document>(u"template.mhtml");
// save MHTML as PPTX format
doc->Save(u"PptxOutput.pptx", SaveFormat::Pptx);
// instantiate a Presentation object that represents a PPTX file
SharedPtr<Presentation> prs = MakeObject<Presentation>(u"PptxOutput.pptx");
// save the presentation as Xaml format
prs->Save(u"output.xaml", Aspose::Slides::Export::SaveFormat::Xaml);
Change Password of MHTML Document via C++
In the process of rendering MHTML to XAML, you can open a password protected MHTML and also change its password. In order to change the password of a MHTML file, you must know the owner password of that document. You can load password protected PDF document with Aspose.PDF for C++ by specifying its owner password and use ChangePasswords method to change the password.
// load an existing MHTML Document
auto doc = MakeObject<Document>(L"input.mhtml", L"owner");
// change password of MHTML Document
doc->ChangePasswords(L"owner", L"newuser", L"newuser");
// save the document
doc->Save(L"output.Doc");
Add Images From Web in XAML File via C++
After converting MHTML to XAML, you can also add images from web to your output document. Aspose.Slides for C++ supports operations with images in these popular formats: JPEG, PNG, BMP, GIF, and others. You can add one or several images on your computer onto a slide in a presentation. This sample code in C++ shows you how to add an image to a XAML file
// instantiate a Presentation object that represents a XAML file
auto pres = System::MakeObject<Presentation>("output.xaml");
// get slide
auto slide = pres->get_Slides()->idx_get(0);
// initialize Web Client
auto webClient = System::MakeObject<WebClient>();
// get image data
auto imageData = webClient->DownloadData(System::MakeObject<Uri>(u"[REPLACE WITH URL]"));
// add image
auto image = pres->get_Images()->AddImage(imageData);
// add picture frame
slide->get_Shapes()->AddPictureFrame(ShapeType::Rectangle, 10.0f, 10.0f, 100.0f, 100.0f, image);
// save updated file
pres->Save(u"updated.xaml", SaveFormat::Xaml);