Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active June 20, 2024 07:14
Show Gist options
  • Save aspose-com-gists/d668dbe65998ea0a6651c553e8c6f24b to your computer and use it in GitHub Desktop.
Save aspose-com-gists/d668dbe65998ea0a6651c553e8c6f24b to your computer and use it in GitHub Desktop.
Java Convert EPUB to PDF Programmatically | Page Setup Password PDF
// 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");
}
// 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");
}
// 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");
}
@sword-dot
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment