Convert PDF to EPUB, Text, XPS, and More in Java

Aspose.PDF for Java can export PDF documents into text, ebook, print, and markup-oriented output formats.

Convert PDF to EPUB

Use this example when a PDF document should be exported to the EPUB ebook format.

  1. Open the source PDF document.
  2. Configure the save options for EPUB output.
  3. Save the converted EPUB file.
public static void convertPdfToEpub(Path inputFile, Path outputFile) {
        try (Document document = new Document(inputFile.toString())) {
            EpubSaveOptions saveOptions = new EpubSaveOptions();
            saveOptions.setContentRecognitionMode(EpubSaveOptions.RecognitionMode.Flow);
            document.save(outputFile.toString(), saveOptions);
        }
        System.out.println(inputFile + " converted into " + outputFile);
    }

Convert PDF to TeX

Use this example when PDF content should be exported into TeX markup.

  1. Open the source PDF document.
  2. Configure the save options for TeX output.
  3. Save the resulting TeX file.
public static void convertPdfToTex(Path inputFile, Path outputFile) {
    try (Document document = new Document(inputFile.toString())) {
        document.save(outputFile.toString(), new TeXSaveOptions());
    }
    System.out.println(inputFile + " converted into " + outputFile);
}

Convert PDF to plain text

Use this example when a PDF document should be exported as a text file.

  1. Open the source PDF document.
  2. Configure the text save options if needed.
  3. Save the text output file.
public static void convertPdfToTxt(Path inputFile, Path outputFile) {
    try (Document document = new Document(inputFile.toString())) {
        TextDevice device = new TextDevice();
        device.process(document.getPages().get_Item(1), outputFile.toString());
    }
    System.out.println(inputFile + " converted into " + outputFile);
}

Convert PDF to XPS

Use this example when a PDF document should be converted into XPS format.

  1. Open the source PDF document.
  2. Create the XPS save options.
  3. Save the converted XPS file.
public static void convertPdfToXps(Path inputFile, Path outputFile) {
    try (Document document = new Document(inputFile.toString())) {
        XpsSaveOptions saveOptions = new XpsSaveOptions();
        saveOptions.setUseEmbeddedTrueTypeFonts(true);
        document.save(outputFile.toString(), saveOptions);
    }
    System.out.println(inputFile + " converted into " + outputFile);
}

Convert PDF to Markdown

Use this example when PDF content should be exported as Markdown.

  1. Open the source PDF document.
  2. Configure the Markdown save options.
  3. Save the generated Markdown file.
public static void convertPdfToMd(Path inputFile, Path outputFile) {
    try (Document document = new Document(inputFile.toString())) {
        MarkdownSaveOptions saveOptions = new MarkdownSaveOptions();
        saveOptions.setResourcesDirectoryName("images");
        saveOptions.setUseImageHtmlTag(true);
        document.save(outputFile.toString(), saveOptions);
    }
    System.out.println(inputFile + " converted into " + outputFile);
}

Convert PDF to Mobi XML

Use this example when PDF content should be exported into Mobi-compatible XML.

  1. Open the source PDF document.
  2. Configure the save options for Mobi XML output.
  3. Save the converted file.
public static void convertPdfToMobiXml(Path inputFile, Path outputFile) {
    try (Document document = new Document(inputFile.toString())) {
        document.save(outputFile.toString(), SaveFormat.MobiXml);
    }
    System.out.println(inputFile + " converted into " + outputFile);
}