EPUB文件用于大规模发布。例如出版书籍,小册子。此外,EPUB到PDF的转换对于使文件与更多的系统环境和操作系统兼容非常有用。让我们使用Java以编程方式探索与EPUB到PDF转换有关的不同用例:
- 使用Java以编程方式将EPUB转换为PDF文件
- 在Java中使用加密和密码保护将EPUB转换为PDF
- 使用Java以编程方式通过特定页面设置将EPUB转换为PDF
Aspose.HTML for Java API支持EPUB,PDF和其他几种文件格式。您可以根据需要轻松地在不同的文件格式之间进行转换。点击下方按钮下方使用。
整合所有格式API处理控件Aspose.Total永久授权火热促销中,联系客服立马1分钟了解全部!
使用Java以编程方式将EPUB转换为PDF文件
可以在Java应用程序中将EPUB文件有效地转换为PDF文档。因此,以下步骤说明了如何执行转换:
- 加载输入的EPUB文件
- 初始化PdfSaveOptions类对象
- 转换EPUB为PDF档案
以下代码详细说明了如何使用Java语言以编程方式将EPUB转换为PDF:
// Open an existing EPUB file for readingtry (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");}
在Java中使用加密和密码保护将EPUB转换为PDF
可以使用密码保护和加密PDF文件,以确保授权或受限访问。也可以在使用密码加密输出文件的同时将EPUB渲染为PDF。以下是使用不同保护措施将EPUB转换为PDF文件的步骤:
- 加载输入的EPUB文件
- 初始化PdfEncryptionInfo类对象
- 使用PdfSaveOptions类将EPUB转换为PDF
以下代码段显示了如何使用Java语言通过密码保护和加密将EPUB转换为PDF:
// Open an existing EPUB file for readingtry (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");}
使用Java以编程方式将页面设置从EPUB转换为PDF
呈现PDF文档时,您可以控制不同的页面设置属性。可以根据需要设置页面大小,边距或背景颜色以及其他属性。因此,将EPUB文件转换为PDF时,只需按照以下步骤设置与页面相关的属性:
- 加载源EPUB文件
- 初始化PdfSaveOptions类对象
- 设置不同的页面相关属性
- 将输入的EPUB转换为PDF文档
下面的代码基于这些步骤。它显示了如何使用Java代码将EPUB文件转换为PDF格式:
// Open an existing EPUB file for readingtry (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"); }
如果你想试用Aspose的全部完整功能,可联系在线客服获取30天临时授权体验。
还想要更多吗可以点击阅读【2020 · Aspose最新资源整合】,查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询。
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!