Many organizations keep years of newsletters, product catalogs, and event flyers as Microsoft Publisher files. These publications were designed for paper, and few devices can open them today. If your audience reads on Kobo devices, Apple Books, or Calibre, the EPUB format brings that content to them.

This guide explains how to convert PUB to EPUB in Java step by step. You’ll start with a basic conversion and then create a fixed-layout e-book that keeps the design of a flyer. After that, you’ll convert data in memory for web applications, process a whole folder of PUB files, and add an author name to the e-book. All examples are plain Java, so they run on Windows, Linux, and macOS without Microsoft Publisher.

How PUB and EPUB Differ

A PUB file is built for printing, while an EPUB file is built for reading on screens. Here is a quick comparison:

FeaturePUBEPUB
Created byMicrosoft PublisherAny e-book tool (W3C standard)
Main usePrinted flyers, brochures, and newslettersE-books and digital publications
Page designExact print positionsText that reflows, or pages with a fixed design
File contentsProprietary binary dataA ZIP archive with XHTML, CSS, fonts, and images
Supported byVery few applicationsAlmost every e-reader and reading app

Java developers usually need this conversion for one of these reasons:

  • Digital distribution. A content platform can turn uploaded Publisher files into e-books that subscribers read on any device.
  • Publisher retirement. Support for Microsoft Publisher ended in October 2026, which makes PUB files a poor choice for content you still need.
  • Long-term storage. An open format such as EPUB keeps archived publications readable for years.

Set Up Aspose.PUB and Aspose.PDF for Java

Java developers combine two Aspose libraries for this task:

The intermediate PDF lives in a byte array, so nothing extra is written to disk.

Register the Aspose Maven repository and declare both libraries in pom.xml:

<repositories>
    <repository>
        <id>AsposeJavaAPI</id>
        <name>Aspose Java API</name>
        <url>https://releases.aspose.com/java/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>26.10</version>
    </dependency>
</dependencies>

Projects without Maven can add the JAR files from the Aspose.PUB and Aspose.PDF download pages instead.

Convert PUB to EPUB in Java

The conversion takes five steps:

  1. Call PubFactory.createParser() with the file path, then call parse() to get the publication.
  2. Render the publication into a ByteArrayOutputStream with convertToPdf().
  3. Pass the PDF bytes to a new com.aspose.pdf.Document object.
  4. Create EpubSaveOptions, choose the Flow recognition mode, and give the e-book a title.
  5. Call save() with the output path and the options.

Here’s the complete Java program:

import com.aspose.pdf.EpubSaveOptions;
import com.aspose.pub.Document;
import com.aspose.pub.PubFactory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

public class ConvertPubToEpub {
    public static void main(String[] args) {
        // Path to the documents directory
        String dataDir = "C:\\Files\\";

        // Load and parse the PUB file
        Document document = PubFactory.createParser(dataDir + "halloween-flyer.pub").parse();

        // Convert the PUB document to PDF in memory
        ByteArrayOutputStream pdfStream = new ByteArrayOutputStream();
        PubFactory.createPdfConverter().convertToPdf(document, pdfStream);

        // Open the PDF data
        com.aspose.pdf.Document pdf = new com.aspose.pdf.Document(
                new ByteArrayInputStream(pdfStream.toByteArray()));

        // Set the EPUB options
        EpubSaveOptions options = new EpubSaveOptions();
        options.setContentRecognitionMode(EpubSaveOptions.RecognitionMode.Flow);
        options.setTitle("Halloween Party 2026");

        // Save the EPUB file
        pdf.save(dataDir + "halloween-flyer.epub", options);
        pdf.close();
    }
}

This code produces an EPUB 3 e-book whose text reflows to fit the screen. The fonts used in the publication are embedded in the package as WOFF files, so the e-book keeps its typography. Load the output in Calibre or Apple Books to see the result.

Both libraries define a class named Document. The code imports the Aspose.PUB one and refers to the PDF one by its full name, com.aspose.pdf.Document, to avoid a naming conflict.

Create a Fixed-Layout EPUB from a PUB File

Reflowable text suits newsletters, but a flyer loses its character when its text is rearranged to fit a screen. For design-heavy publications, a fixed-layout e-book is the better choice. Each page appears as it was designed, with text and graphics in their original positions.

Switching to this output only takes a different value for the content recognition mode. Choose the mode based on the type of publication:

ModeResultBest for
FlowReflowable text that adapts to the screenNewsletters, booklets, text-heavy publications
FixedPages that keep the original designFlyers, brochures, posters, cards

The following program creates a fixed-layout EPUB:

import com.aspose.pdf.EpubSaveOptions;
import com.aspose.pub.Document;
import com.aspose.pub.PubFactory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

public class ConvertPubToFixedLayoutEpub {
    public static void main(String[] args) {
        // Path to the documents directory
        String dataDir = "C:\\Files\\";

        // Load the PUB file and convert it to PDF in memory
        Document document = PubFactory.createParser(dataDir + "halloween-flyer.pub").parse();
        ByteArrayOutputStream pdfStream = new ByteArrayOutputStream();
        PubFactory.createPdfConverter().convertToPdf(document, pdfStream);

        // Open the PDF data
        com.aspose.pdf.Document pdf = new com.aspose.pdf.Document(
                new ByteArrayInputStream(pdfStream.toByteArray()));

        // Keep the page layout of the publication
        EpubSaveOptions options = new EpubSaveOptions();
        options.setContentRecognitionMode(EpubSaveOptions.RecognitionMode.Fixed);
        options.setTitle("Halloween Party 2026");

        // Save the fixed-layout EPUB file
        pdf.save(dataDir + "halloween-flyer-fixed.epub", options);
        pdf.close();
    }
}

In this mode, the backgrounds and artwork of the flyer are packed into the EPUB as PNG and SVG images. The file is bigger than the reflowable version, but readers see the flyer the way its designer laid it out.

Tip: Want both a reflowable and a fixed-layout copy? Keep the PDF byte array and load a fresh com.aspose.pdf.Document for each save. A PDF document object can’t be reused after it has been saved as EPUB.

Convert PUB to EPUB in Memory

Servers often receive PUB files as uploads and send EPUB files back in the response. Writing these files to disk adds cleanup work and slows down the request. Instead, pass an InputStream to PubFactory.createParser() and an OutputStream to the save() method of the PDF document.

The convertPubToEpub() method below works with any pair of streams:

import com.aspose.pdf.EpubSaveOptions;
import com.aspose.pub.Document;
import com.aspose.pub.PubFactory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class PubToEpubStream {
    // Converts a PUB stream to an EPUB stream
    public static void convertPubToEpub(InputStream pubInput, OutputStream epubOutput) {
        // Parse the PUB data and convert it to PDF in memory
        Document document = PubFactory.createParser(pubInput).parse();
        ByteArrayOutputStream pdfStream = new ByteArrayOutputStream();
        PubFactory.createPdfConverter().convertToPdf(document, pdfStream);

        // Write the EPUB data to the output stream
        com.aspose.pdf.Document pdf = new com.aspose.pdf.Document(
                new ByteArrayInputStream(pdfStream.toByteArray()));
        pdf.save(epubOutput, new EpubSaveOptions());
        pdf.close();
    }

    public static void main(String[] args) throws IOException {
        // Path to the documents directory
        String dataDir = "C:\\Files\\";

        // Convert a file using streams
        try (InputStream pubInput = new FileInputStream(dataDir + "halloween-flyer.pub");
             OutputStream epubOutput = new FileOutputStream(dataDir + "halloween-flyer.epub")) {
            convertPubToEpub(pubInput, epubOutput);
        }
    }
}

The main() method uses file streams only to demonstrate the call. Inside a Spring Boot controller or a servlet, call convertPubToEpub() with the input stream of the uploaded file and the output stream of the HTTP response, and set the response content type to application/epub+zip.

Batch Convert a Folder of PUB Files

Migrating a library of publications one file at a time isn’t practical. The following Java code reads every PUB file in a folder, converts it to EPUB, and names each e-book after its source file:

import com.aspose.pdf.EpubSaveOptions;
import com.aspose.pub.Document;
import com.aspose.pub.PubFactory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;

public class BatchConvertPubToEpub {
    public static void main(String[] args) {
        // Input and output folders
        File inputDir = new File("C:\\Files\\Publications\\");
        File outputDir = new File("C:\\Files\\EPUB\\");
        outputDir.mkdirs();

        // Find the PUB files in the input folder
        File[] pubFiles = inputDir.listFiles((dir, name) -> name.toLowerCase().endsWith(".pub"));
        if (pubFiles == null) {
            return;
        }

        for (File pubFile : pubFiles) {
            // Parse the PUB file and convert it to PDF in memory
            Document document = PubFactory.createParser(pubFile.getPath()).parse();
            ByteArrayOutputStream pdfStream = new ByteArrayOutputStream();
            PubFactory.createPdfConverter().convertToPdf(document, pdfStream);

            // Use the file name as the e-book title
            String name = pubFile.getName().replaceFirst("(?i)\\.pub$", "");
            EpubSaveOptions options = new EpubSaveOptions();
            options.setTitle(name);

            // Save the EPUB file with the same name
            com.aspose.pdf.Document pdf = new com.aspose.pdf.Document(
                    new ByteArrayInputStream(pdfStream.toByteArray()));
            File epubFile = new File(outputDir, name + ".epub");
            pdf.save(epubFile.getPath(), options);
            pdf.close();

            System.out.println("Converted: " + epubFile);
        }
    }
}

The filter matches .pub and .PUB extensions alike, and the console prints the path of each e-book as it’s created.

Add an Author to the EPUB File

Without an author, an e-book appears as “Unknown” in most reading apps. EpubSaveOptions has a setTitle() method but no author setting, and neither the PUB metadata nor the PDF properties reach the EPUB file.

The fix is a small change inside the package. Every EPUB has a content.opf file that lists its metadata, and the author goes in a dc:creator element. Java’s built-in ZIP file system provider lets you edit that file in place:

  1. Open the EPUB with FileSystems.newFileSystem(), which treats the archive like a folder.
  2. Get the path of EPUB/content.opf inside it.
  3. Read the file content into a string.
  4. Insert a dc:creator element right after the closing dc:title tag.
  5. Write the string back. Closing the file system saves the archive.

Here’s the code:

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class SetEpubAuthor {
    public static void main(String[] args) throws IOException {
        // Path to the EPUB file
        Path epubPath = Paths.get("C:\\Files\\halloween-flyer.epub");

        // Open the EPUB package as a file system
        try (FileSystem epub = FileSystems.newFileSystem(epubPath, (ClassLoader) null)) {
            Path opfPath = epub.getPath("EPUB/content.opf");

            // Read the package document
            String opf = new String(Files.readAllBytes(opfPath), StandardCharsets.UTF_8);

            // Add the author after the title
            opf = opf.replace("</dc:title>", "</dc:title>\n    <dc:creator>Events Team</dc:creator>");

            // Save the updated package document
            Files.write(opfPath, opf.getBytes(StandardCharsets.UTF_8));
        }
    }
}

Reading apps now list the book under “Events Team”. The ZIP file system provider only rewrites the changed file, so the mimetype entry keeps its required first position and the package stays valid.

The author name doesn’t have to be hard-coded. A PUB file often stores its author already, and you can get it with document.getSummaryInfo().getAuthor(). See Read and Edit PUB Metadata in Java for the full list of properties.

Evaluate Without Limitations

Unlicensed copies of Aspose.PUB and Aspose.PDF for Java place evaluation notices in the generated e-books. To test the full output, get a free temporary license and apply it for both libraries before you run the conversion.

Free Online PUB to EPUB Converter

Need to convert only a few files? The Aspose PUB to EPUB converter runs in your browser and needs no installation or code.

Learning Resources

The following resources cover more features of Aspose.PUB for Java:

Conclusion

Aspose.PUB and Aspose.PDF for Java together turn Publisher files into EPUB e-books in a few lines of code. Pick Flow for text-heavy publications that should adapt to small screens, and Fixed when the design of a flyer or brochure matters most. The same approach works with streams in web services and with folders of files in migration jobs. Questions or feedback? Visit our free support forum.

Frequently Asked Questions

How do I convert a PUB file to EPUB in Java?

Parse the PUB file using PubFactory.createParser(), convert it to PDF in memory using convertToPdf(), open the PDF with Aspose.PDF for Java, and save it with EpubSaveOptions.

Why does the Java conversion go through PDF?

Aspose.PUB for Java converts PUB files to PDF. Aspose.PDF for Java then saves the PDF as EPUB. The PDF stays in memory, so no temporary file is created.

What is the difference between a reflowable and a fixed-layout EPUB?

A reflowable EPUB adapts the text to the screen of the reader. A fixed-layout EPUB keeps the page design of the publication, including the position of text and graphics.

How do I set the title of the EPUB in Java?

Call setTitle() on the EpubSaveOptions object before you save the file. To add an author, update the content.opf file of the EPUB package as shown in this article.

Can I convert PUB to EPUB in memory in Java?

Yes. PubFactory.createParser() accepts an InputStream, and the save() method of the PDF document writes to any OutputStream, such as a servlet response.

Does the conversion work on Linux?

Yes. Aspose.PUB and Aspose.PDF for Java are pure Java libraries. They run on Windows, Linux, and macOS, and they don’t need Microsoft Publisher.

See Also