You can read all the details at: Convert EPUB to PDF Programmatically with Java
Last active
June 20, 2024 07:14
-
-
Save aspose-com-gists/d668dbe65998ea0a6651c553e8c6f24b to your computer and use it in GitHub Desktop.
Java Convert EPUB to PDF Programmatically | Page Setup Password PDF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open an existing EPUB file for reading | |
try (FileInputStream fileInputStream = new FileInputStream(dataDir + "input.epub")) { | |
// Initialize PdfSaveOptions class object | |
PdfSaveOptions options = new PdfSaveOptions(); | |
// Call the ConvertEPUB method to convert the EPUB to PDF | |
Converter.convertEPUB(fileInputStream, options, dataDir + "output.pdf"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open an existing EPUB file for reading | |
try (FileInputStream fileInputStream = new FileInputStream(dataDir + "input.epub")) { | |
PdfSaveOptions options = new PdfSaveOptions(); | |
Page page = new Page(); | |
// Set page size | |
Size size = new Size(Length.fromInches(12), Length.fromInches(10)); | |
// Set page Margin | |
Margin margin = new Margin(Length.fromInches(1), Length.fromInches(1), Length.fromInches(1), Length.fromInches(1)); | |
page.setSize(size); | |
page.setMargin(margin); | |
// Set page background color | |
options.setBackgroundColor(Color.getAliceBlue()); | |
options.getPageSetup().setAnyPage(page); | |
// Call the ConvertEPUB method to convert the EPUB to PDF | |
Converter.convertEPUB(fileInputStream, options, dataDir + "output.pdf"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open an existing EPUB file for reading | |
try (FileInputStream fileInputStream = new FileInputStream(dataDir + "input.epub")) { | |
// Set PDF password and encryption information | |
PdfEncryptionInfo info = new PdfEncryptionInfo("user" , "owner" , PdfPermissions.AssembleDocument, PdfEncryptionAlgorithm.RC4_128); | |
// Initialize PdfSaveOptions class object | |
PdfSaveOptions options = new PdfSaveOptions(); | |
options.setEncryption(info); | |
// Call the ConvertEPUB method to convert the EPUB to PDF | |
Converter.convertEPUB(fileInputStream, options, dataDir + "output.pdf"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i got an error below:
class com.aspose.html.internal.ms.System.InvalidOperationException: Cannot find a required cmap table.
how to fix it ?
my env is idea+jdk1.8. mbp.