- EPUB Converter — Java
- Convert EPUB to PDF in Java
- EPUB to PDF by a few lines of Java code
- Convert EPUB to PDF in Java
- Save Options
- Convert EPUB to PDF using PdfSaveOptions
- Subscribe to Aspose Product Updates
- Convert EPUB to PDF via Java
- High-fidelity conversion of EPUB pages as PDF file using server-side Java library or online.
- Aspose.Html for Java
- Overview
- Convert EPUB to PDF Online
- Convert EPUB to PDF Using Java
- EPUB to PDF Java Conversion Source Code
- Steps to Convert EPUB to PDF via Java
- Free Online Converters
- System Requirements
- Get Started with Java HTML Parser Library
- Repository
EPUB Converter — Java
EPUB is an open-source e-book file format that is the standard digital publishing format. EPUB file standards are maintained by the International Digital Publishing Forum (IDPF). EPUB is supported by many e-readers and devices, including smartphones, tablets, and computers, making it a widely accepted format. An EPUB file is a collection of files, including HTML, CSS, and multimedia content, packaged together in a ZIP archive.
EPUB conversions are often required to take advantage of other formats that can provide greater flexibility and make it easier to share, print, store, and use digital content. Aspose.HTML for Java provides a wide range of EPUB conversions to popular formats, such as PDF, XPS, DOCX, JPG, PNG, BMP, TIFF, and GIF.
This section provides information on the list of supported EPUB conversions and how to perform them using convertEPUB() methods of the Converter class. It can be different scenarios, but any EPUB conversion can be made with a few required steps:
- Load an existing EPUB file.
- Create a Save Options object. You may customize the rendering process to get the desired result.
- Use one of the convertEPUB() methods and pass the required parameters to it.
Let’s consider the following code snippet that shows how to convert EPUB to PDF using our Java library:
1 // Prepare a path to a source EPUB file 2 String documentPath = Path.combine(getDataDir(), "input.epub"); 3 4 // Prepare a path to save the converted file 5 String savePath = Path.combine(getOutputDir(), "output.pdf"); 6 7 // Create an instance of PdfSaveOptions 8 PdfSaveOptions options = new PdfSaveOptions(); 9 10 // Call the convertEPUB() method 11 com.aspose.html.converters.Converter.convertEPUB(documentPath, options, savePath);
Note: You need to specify the path to the source and output file in your local file system ( sourcePath and savePath ).
You can download the complete examples and data files from GitHub.
Aspose.HTML provides a free online EPUB Converter that enables you to convert EPUB files to various popular formats. This tool can easily convert EPUB to PDF, XPS, DOCX, JPG, PNG, BMP, TIFF, and GIF. The conversion process is simple and fast. All you need to do is select the file and choose the desired output format. The best part is that it’s completely free!
Convert EPUB to PDF in Java
EPUB is a format that is widely used for e-books, but it is not always compatible with all devices or software applications. Converting EPUB to PDF can be helpful in situations where you want to create a document that is easily readable across different devices and platforms. PDFs are also optimized for printing, making them ideal for creating physical copies of your documents. You can configure security settings for PDF files to restrict access or editing.
In this article, you will find information about how to convert EPUB to PDF using Aspose.HTML for Java library and how to use PdfSaveOptions and MemoryStreamProvider.
EPUB to PDF by a few lines of Java code
The static methods of the Converter class are primarily used as the easiest way to convert an EPUB file into various formats. You can convert EPUB to PDF in your Java application literally with a few lines of code!
1 // Open an existing EPUB file for reading 2 final FileStream stream = File.openRead(StringExtensions.concat(getDataDir(), "input.epub")); 3 try > 4 finally if (stream != null) ((IDisposable)stream).dispose(); > 5 6 // Invoke the convertEPUB() method 7 com.aspose.html.converters.Converter.convertEPUB(stream, new PdfSaveOptions(), Path.combine(getOutputDir(), "convert-by-few-lines.pdf"));
Convert EPUB to PDF in Java
You should follow a few steps:
- Open an existing EPUB file. In the example, we use the openRead() method of System.IO.FileStream class to open and read an EPUB file from the file system at the specified path.
- Create an instance of PdfSaveOptions. Use the empty PdfSaveOptions() constructor to convert with the default save options.
- Use the convertEPUB(stream, options, savePath) method of the Converter class to save EPUB as a PDF file. You need to pass the EPUB file stream, PdfSaveOptions, and output file path to the ConvertEPUB() method as parameters.
The following Java code snippet shows how to convert EPUB to PDF using Aspose.HTML:
1 // Open an existing EPUB file for reading 2 final FileStream stream = File.openRead(StringExtensions.concat(getDataDir(), "input.epub")); 3 try > 4 finally if (stream != null) ((IDisposable)stream).dispose(); > 5 6 // Prepare a path to save the converted file 7 String savePath = Path.combine(getOutputDir(), "input-output.pdf"); 8 9 // Create an instance of PdfSaveOptions 10 PdfSaveOptions options = new PdfSaveOptions(); 11 12 // Call the convertEPUB() method 13 com.aspose.html.converters.Converter.convertEPUB(stream, options, savePath);
You can download the complete examples and data files from GitHub.
Save Options
Aspose.HTML provides the ability to programmatically convert EPUB to PDF with full control over various conversion options using PdfSaveOptions. This feature allows users to customize the rendering process by setting the page size, margins, file permissions, CSS media-type, and other parameters.
Metod | Description |
---|---|
setJpegQuality(value) | Specifies the quality of JPEG compression for images. The default value is 95. |
getCss() | Gets a CssOptions object which is used for configuration of CSS properties processing. |
setBackgroundColor(value) | Sets the color that will fill the background of every page. By default, this property is Transparent . |
setPageSetup(value) | This method sets a page setup object and uses it for configuration output page-set. |
setHorizontalResolution(value) | Sets horizontal resolution for internal images, in pixels per inch. By default this property is 300 dpi. |
setVerticalResolution(value) | Sets vertical resolution for output images in pixels per inch. The default value is 300 dpi. |
setEncryption | This method gets or sets encryption details. If it is not set, then no encryption will be performed. |
For further information on how to customize the conversion process with PdfSaveOptions, you can refer to the Fine-Tuning Converters article.
Please note that you cannot set values against the Application and Producer fields, because Aspose Ltd. and Aspose.HTML for Java x.x.x will be displayed against these fields.
Convert EPUB to PDF using PdfSaveOptions
Setting different options of PdfSaveOptions class gives you control over the page size, resolution, background color, and compression settings for the output PDF. These are the steps to convert an EPUB file to PDF format with PdfSaveOptions specifying.
- Open an existing EPUB file.
- Create a new PdfSaveOptions object and specify the required save options. Use the setPageSetup() and setBackgroundColor() methods to set the page size and background color.
- Call the convertEPUB(stream, options, savePath) method to save EPUB as a PDF file. You need to pass the EPUB file stream, PdfSaveOptions, and output file path to the convertEPUB () method as parameters.
The following example shows how to use PdfSaveOptions and create a PDF file with custom custom page-size and background color:
1 // Open an existing EPUB file for reading 2 final FileStream stream = File.openRead(StringExtensions.concat(getDataDir(), "input.epub")); 3 try > 4 finally if (stream != null) ((IDisposable)stream).dispose(); > 5 6 // Prepare a path to save the converted file 7 String savePath = Path.combine(getOutputDir(), "input-options.pdf"); 8 9 // Create an instance of PdfSaveOptions. Set up the page-size and change the background color to AliceBlue 10 PdfSaveOptions options = new PdfSaveOptions(); 11 PageSetup pageSetup = new PageSetup(); 12 Page anyPage = new Page(); 13 anyPage.setSize(new com.aspose.html.drawing.Size(Length.fromPixels(1000),Length.fromPixels(1000))); 14 pageSetup.setAnyPage(anyPage); 15 options.setPageSetup(pageSetup); 16 options.setBackgroundColor(Color.getAliceBlue()); 17 18 // Call the convertEPUB() method 19 com.aspose.html.converters.Converter.convertEPUB(stream, options, savePath);
Check the quality of EPUB to PDF conversion with our online EPUB to PDF Converter. Upload, convert your files and get the result in a few seconds. Try our forceful EPUB to PDF Converter for free now!
Subscribe to Aspose Product Updates
Get monthly newsletters & offers directly delivered to your mailbox.
Convert EPUB to PDF via Java
High-fidelity conversion of EPUB pages as PDF file using server-side Java library or online.
Aspose.Html for Java
Overview
Download from Maven
You can easily use Aspose.Html for Java directly from a Maven based project by following simple installation instructions.
Convert EPUB to PDF Online
You can test the quality of EPUB to PDF conversion right in your browser! Please load an EPUB file from the local file system, select the required output format from the list and run the example. You will immediately get the result as a separate file. It’s fast, easy, secure and completely free!
Convert EPUB to PDF Using Java
In order to convert EPUB to PDF, we’ll use Aspose.HTML for Java API which is a feature-rich, powerful and easy to use document manipulation and conversion API for Java platform. EPUB conversions are often required to take advantage of other formats. You can transform EPUB to PDF programmatically with full control over a wide range of conversion parameters. Powerful Java library allows you to convert EPUB to popular formats quickly and in high quality!
EPUB to PDF Java Conversion Source Code
// Open an existing EPUB file for reading try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("input.epub")) // Call the convertEPUB method to convert EPUB to PDF com.aspose.html.converters.Converter.convertEPUB( fileInputStream, new com.aspose.html.saving.PdfSaveOptions(), "output.pdf" ); >
Steps to Convert EPUB to PDF via Java
If you would like to consider conversion functionality in your product or you want to convert EPUB to PDF programmatically, please see the Java code example above or learn the Documentation chapters. Developers can easily convert HTML file to PDF in just a few lines of code:
- Open an existing EPUB file for reading.
- Create a new PdfSaveOptions object.
- Call the convertEPUB() method to convert EPUB to PDF.
- The PDF file will be saved to the specified path.
Free Online Converters
Aspose.HTML offers free online EPUB Converter for converting EPUB documents to PDF, XPS, DOCX, JPG, PNG, BMP, TIFF, GIF and other formats. It works from all platforms including Windows, Linux, Mac OS, Android, and iOS. All files are processed on our servers. No plugin or software installation required for you. Just upload, convert your documents and get results in a few seconds. Try our forceful online EPUB Converter for free now!
System Requirements
Before running the conversion example code, make sure that you have the following prerequisites.
- Microsoft Windows or a compatible OS with Java Runtime Environment for JSP/JSF Application and Desktop Applications.
- Get latest version of Aspose.HTML for Java directly from Maven.
Get Started with Java HTML Parser Library
HTML API is an advanced web scraping and HTML parsing library. One can create, edit, navigate through nodes, extract data and convert HTML, XHTML, and MHTML files to PDF, Images, and other formats. Moreover, it also handles CSS, HTML Canvas, SVG, XPath, and JavaScript out-of-the-box to extend manipulation tasks. It’s a standalone API and does not require any software installation.
You can download its latest version directly from Aspose Maven Repository and install it within your Maven-based project by adding the following configurations to the pom.xml.
Repository
AsposeJavaAPI Aspose Java API https://repository.aspose.com/repo/