Convert PUB Files | Aspose.PUB for C++

Overview to .pub conversion functionality via 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.

Converting PUB files offers an alternative solution when you need to open or edit Microsoft Publisher files using different software. Let’s explore additional reasons to convert PUB files:

You have several options for converting PUB files into different formats, including PDF, DOCX (Microsoft Word), HTML (web page format), or different image formats. The choice of format depends on your specific needs and the software or platform you plan to use. Here you can find information on how to convert .pub files with C++ APIs but if you’d better use an online solution without the need for coding, you can use cross-platform converters.

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. 

The following steps and code snippet show how to convert PUB to PDF using C++.

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:

  1. Create an instance of the Aspose::Pub::License class named license using the System::MakeObject method.

  2. 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.

  3. Declare two System::String variables named filePub and filePdf, representing the paths to the .pub file and the desired output PDF file, respectively. To create the path use the dataDir() function.

  4. Create a shared pointer (System::SharedPtr) named parser of type IPubParser using the PubFactory::CreateParser() method, passing filePub as a parameter.

  5. 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 .pub file, storing it in the document object for further processing.

  6. 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 .pub document to .pdf and saves it to the specified output file.

C++ code example PUB to PDF conversion
Input file
Upload a file you want to convert
Output format
Select the target format

                    

Go to the product page to fully discover PUB to PDF conversion via C++

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.