Convert Publisher to JPG in Java | PUB to JPG/JPEG Converter

Microsoft Publisher is a popular desktop publishing software that uses PUB files. A PUB file contains page layout, text, images, and other design elements. However, PUB files are not as widely supported as other image formats like JPG, which is why we need to convert them. Converting PUB files to JPG offers several advantages. Firstly, JPG is a more universal format, making it easier to share and view across different platforms. Secondly, JPG files are generally smaller in size, making them ideal for web use. Lastly, many image editing software and libraries support JPG, making it a more versatile format. In this article, we will learn how to convert PUB to JPG in Java.

This article covers the following topics:

  1. Java API to Convert Publisher to JPG
  2. Steps to Convert a PUB File to a JPG
  3. Convert PUB to JPG in Java
  4. Convert PUB to JPG Online
  5. Free Resources

Java API to Convert Publisher to JPG

Converting a Publisher PUB file to JPG involves a two-step process. First, we will load and render the PUB file into PDF format using the Aspose.PUB for Java API. Then, we will employ the Aspose.PDF for Java API to convert the pages of the PDF file into JPG images.

Aspose.PUB for Java empowers developers to effortlessly integrate Microsoft Publisher files (PUB) into their Java applications, offering a robust set of features for reading, writing, converting, and manipulating PUB files. Meanwhile, Aspose.PDF for Java is a multifaceted tool that enables developers to perform a broad spectrum of tasks related to PDF files, from simple edits to complex document management.

Please download the JAR files for Aspose.PUB for Java and Aspose.PDF for Java API, or specify the following configurations to download the APIs from the Maven repository:

<repositories>
    <repository>
        <id>AsposeJavaAPI</id>
        <name>Aspose Java API</name>
        <url>http://repository.aspose.com/repo/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-pub</artifactId>
        <version>22.8</version>
    </dependency>

    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-pdf</artifactId>
        <version>24.5</version>
    </dependency>
</dependencies>

How to Convert Publisher PUB File to JPG

We can easily convert a PUB file to a JPG image by following the steps below:

  1. Create a PUB parser and parse the PUB file.
  2. Convert a PUB to a PDF file stream.
  3. Loop through all the pages of the PDF document.
  4. Create a Jpeg device and process pages to save as JPG images.

Now, let’s see how to perform these steps in Java to convert a Publisher PUB file to a JPG.

Convert PUB to JPG in Java

Please follow the steps below to programmatically convert the Publisher PUB file to a JPG image in Java:

  1. Create a PUB parser using the createParser() method of the PubFactory class.
  2. Parse the loaded PUB file using the parse() method.
  3. Initialize the MemoryStream object to hold the PDF file.
  4. Convert PUB to PDF using the convertToPdf() method.
  5. Create an instance of the Document class with the PDF stream.
  6. Get file information using the PdfFileInfo class object.
  7. Loop through pages of the PDF document and get height, width, and set resolution.
  8. After that, create an instance of the JpegDevice with height, width, and resolution for the page.
  9. Finally, call the process() method to save as JPG. It takes the page and output image file path as arguments.

The following code sample shows how to convert a Publisher PUB file to JPG in Java.

Convert PUB to JPG in Java

Convert PUB to JPG in Java.

Get a Free License

You can get a free temporary license to try the libraries without evaluation limitations.

PUB to JPG Converter - Free Online

In addition, you can also use this free online PUB to JPG Converter web app to convert publisher files to JPG images without installing any software or plugin.

PUB to JPG – Free Resources

Besides converting Publisher PUB files into JPG format in Java, you may also explore various other features of the APIs using the following resources:

Conclusion

In this blog post, we have shown you how to convert Publisher to JPG in Java. We have provided a step-by-step guide and code snippets to help you get started. Converting Publisher files to JPG is a relatively simple task, and the code snippets provided in this blog post can be used as a starting point for developing your own Publisher to JPG converter application. In case of any ambiguity, please feel free to contact us on our free support forum.

See Also