Convert PDF to EPUB, Text, XPS, and More in Java
Contents
[
Hide
]
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.
- Open the source PDF document.
- Configure the save options for EPUB output.
- 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.
- Open the source PDF document.
- Configure the save options for TeX output.
- 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.
- Open the source PDF document.
- Configure the text save options if needed.
- 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.
- Open the source PDF document.
- Create the XPS save options.
- 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.
- Open the source PDF document.
- Configure the Markdown save options.
- 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.
- Open the source PDF document.
- Configure the save options for Mobi XML output.
- 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);
}