PUB to PDF | Aspose.PUB for Java
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
Portable Document Format (PDF) was introduced by Adobe to represent documents that can be read on digital devices. PUB files require Microsoft Publisher to be installed on the computer in order to open these files. Aspose.PUB for Java lets you convert PUB files to PDF that 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 in your Java applications.
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.