Microsoft Publisher (PUB)) files are used to create professional documents and marketing materials such as brochures, newsletters, and posters. There might be scenarios where you need to convert the PUB file to a Word document in DOC and DOCX format. For such cases, this article will teach you how to convert PUB files to Word format using C++.
C++ APIs for Converting PUB Files to Word Format
We will perform this conversion using the Aspose.PUB for C++ and Aspose.PDF for C++ APIs. The former is an API for working with Microsoft Publisher (PUB) files, whereas the latter is an API for creating, reading, and updating PDF files. We will use the Aspose.PUB for C++ API to convert PUB files to PDF format and Aspose.PDF for C++ API to convert the generated PDF files to Word files. You can either install the APIs through NuGet or download them directly from the Downloads section.
PM> Install-Package Aspose.PUB.Cpp PM> Install-Package Aspose.PDF.Cpp
Convert PUB Files to Word DOC/DOCX Files using C++
The following are the steps to convert PUB files to Word documents in DOC or DOCX format.
- Load the PUB file using the PubFactory::CreateParser(System::String fileName) method.
- Convert the PUB file to PDF format using the ConvertToPdf(System::SharedPtr<Document> doc, System::String fileName) method.
- Load the generated PDF file using the Document class.
- Create an instance of the DocSaveOptions class.
- Set the format to DocFormat::DocX using the DocSaveOptions->set_Format(DocSaveOptions::DocFormat value) method.
- Save the Word file using the Document->Save(System::String outputFileName, System::SharedPtr<SaveOptions> options) method.
The following sample code shows how to convert a PUB file to a Word document using C++.
Get a Free License
You can try the API without evaluation limitations by requesting a free temporary license.
In this article, you have learned how to convert PUB files to Word format using C++. To achieve this, we used the Aspose.PUB for C++ and Aspose.PDF for C++ APIs. You can learn more about these APIs by exploring their official documentation. In case of any queries, please feel free to reach us at our free support forum.