PUB to PDF | Library for C++
This article shows how to convert PUB files to PDF in C++. It can be used to write C++ converter applications for PUB to PDF. Large Content Management Systems (CMS) convert editable files into read-only PDF documents using bulk operations that makes utilization of such convert applications.
At present, the API doesn’t support the conversion of images in a PUB file to output PDF.
PUB to PDF in C++
Aspose.PUB for C++ lets you convert PUB to PDF in your C++ applications. PDF is a platform-independent document format, introduced by Adobe Acrobat, and can be opened on almost all computers without the need for Microsoft Publisher being installed.
Aspose.PUB for C++ supports converting multi-page PUB documents to PDF using the same lines of code given in this article.
The code snippet below demonstrates the usage of Aspose.PUB library for C++ to convert a Microsoft Publisher file to PDF format. Additionally, it initializes the library’s license object and sets the appropriate license for usage.
Create an instance of the Aspose::Pub::License class named license using the System::MakeObject method.
Set the license by calling the SetLicense method on the license object, passing the path to the license file (dataDir() + u"License\Aspose.PUB.C++.lic") as a parameter. This ensures that the library is properly licensed for usage.
Declare two System::String variables named filePub and filePdf, representing the paths to the
.pubfile and the desired output PDF file, respectively. To create the path use the dataDir() function.
Create a shared pointer (System::SharedPtr) named parser of type IPubParser using the PubFactory::CreateParser() method, passing filePub as a parameter.
Create a shared pointer (System::SharedPtr) named document of type Document by calling the Parse() method on the parser object. The method reads and extracts the content of the
.pubfile, storing it in the document object for further processing.
Use PubFactory::CreatePdfConverter() to create a PDF converter object, and then call the ConvertToPdf() method on the converter object, passing the document object and filePdf as parameters. This method converts the parsed
To see how the functionality can be implemented into a cross-platform application learn our online PUB Converter.