Why to Convert XPS to DOCM?
XPS (XML Paper Specification) is a document format developed by Microsoft which is used to store documents in a fixed layout. It is similar to PDF format but is not as widely used. DOCM is a Microsoft Word document format which is used to store documents with macros enabled. It is a more secure format than DOC and is used to store documents with macros. Therefore, it is necessary to convert XPS to DOCM in order to secure the documents with macros.
How Aspose.Total Helps for XPS to DOCM Conversion?
Aspose.Total for C++ is a suite of file format automation libraries which allows C++ developers to easily convert XPS to DOCM. It consists of two APIs, Aspose.PDF for C++ and Aspose.Words for C++. Aspose.PDF for C++ is a powerful PDF processing API which can be used to convert XPS to DOC. Aspose.Words for C++ is an advanced Word Document Processing API which can be used to export DOC to DOCM.
The conversion process is quite simple and can be done in two steps. Firstly, the XPS file can be converted to DOC using Aspose.PDF for C++. Secondly, the DOC file can be exported to DOCM using Aspose.Words for C++. This process is quite efficient and can be done in a few lines of code. Moreover, Aspose.Total for C++ also provides a wide range of features which can be used to manipulate the documents in various ways. It also provides support for a wide range of file formats which makes it a great choice for file format automation.
C++ API to Render XPS to DOCM
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 XPS file with an instance of Document class reference
auto doc = MakeObject<Document>(u"sourceFile.xps");
// save XPS as a DOC
doc->Save(u"DocOutput.doc", SaveFormat::Doc);
// load DOC with an instance of Document
System::SharedPtr<Document> wordDoc = System::MakeObject<Document>(u"DocOutput.doc");
// save document as Docm
wordDoc->Save(u"output.Docm");
Change Password of XPS Document via C++
In the process of rendering XPS to DOCM, you can open a password protected XPS and also change its password. In order to change the password of a XPS 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 XPS Document
auto doc = MakeObject<Document>(L"input.xps", L"owner");
// change password of XPS Document
doc->ChangePasswords(L"owner", L"newuser", L"newuser");
// save the document
doc->Save(L"output.Doc");
Restrict DOCM File Editing via C++
You can also restrict DOCM file editing using using Aspose.Words for C++ API. Sometimes you may need to limit the ability to edit a document and only allow certain actions with it. API enables you to control the way you restrict the content using the ProtectionType enumeration parameter. The following code example demonstrates how to restrict editing in a document so only editing in form fields is possible.
// load Doc with an instance of Document
auto doc = System::MakeObject<Document>("input.doc");
// document protection only works when document protection is turned and only editing in form fields is allowed.
doc->Protect(ProtectionType::AllowOnlyFormFields, u"password");
// save the protected document.
doc->Save(u"Protected.Docm");