Convert PUB Files with Java APIs
Overview to .pub conversion functionality via Java
Converting MS Publisher files provides an alternative when you wish to open or edit Microsoft Publisher files using different software. Let’s explore additional reasons for converting PUB files:
- Some software and devices do not support the PUB file format, making conversion necessary to access and view files on various platforms.
- Collaborating with individuals who lack Microsoft Publisher becomes easier by converting PUB files to a universal format, enabling everyone to access and work on the files.
- Converting PUB files to formats like PDF or XPS eliminates potential printing issues.
- By converting PUB files to a more standardized format, their long-term accessibility is ensured. This means that you can still access your documents in the future, even if Microsoft Publisher becomes outdated.
You have several options for converting PUB files into different formats, including PDF, DOCX (Microsoft Word), RTF (Rich Text Format), or HTML (web page format). The choice of format depends on your specific needs and the software or platform you intend to use. If you prefer an online solution without the need for coding in Java, you can utilize cross-platform converters.
Aspose.PUB for Java can read and convert publication files (.pub) to PDF. The PubFactory class creates content from a .pub file for further processing by the Document class of the API.
At present, the API doesn’t support the conversion of images in a PUB file to output PDF.
PUB to PDF Conversion using Java
Adobe introduced the Portable Document Format (PDF) to facilitate document viewing on digital devices. PUB files, on the other hand, necessitate Microsoft Publisher for access. With Aspose.PUB for Java, you can effortlessly convert PUB files to PDF, making them accessible on virtually any computer without requiring Microsoft Publisher installation.
Aspose.PUB for Java supports converting multi-page PUB documents to PDF using the same lines of code given in this article.
Create a Java console or WinForms project
Specify an IPubParser object named parser and assign it the result of calling the createParser method from the PubFactory class, passing the fileName as a parameter. The createParser method is responsible for creating a parser object to parse the
.pub
file specified by the fileName.Declare a Document object named doc and assign it the result of calling the Parse method on the Parser object. This method parses the
.pub
file using the previously created parser and returns a Document object representing the contents of the file.Use the createPdfConverter method from the PubFactory class to create a PDF converter object.
Use the convertToPdf method on the PDF converter object to pass the doc object (the parsed .pub document) and the output file path as parameters. This method converts the parsed
.pub
document into a PDF format and saves it to the specified output file path.
1// For complete examples and data files, please go to https://github.com/aspose-pub/Aspose.PUB-for-Java
2
3IPubParser parser = PubFactory.createParser(fileName);
4
5Document doc = parser.parse();
6
7com.aspose.pub.PubFactory.createPdfConverter().convertToPdf(doc, "/users/kashifiqbal/documents/result_out.pdf");
To see how the functionality can be implemented into a cross-platform application learn our online PUB Converter. Go to the product page to fully discover PUB to PDF conversion via Java