翻譯|使用教程|編輯:李顯亮|2021-03-09 10:51:32.323|閱讀 381 次
概述:EPUB文件用于大規模發布。例如出版書籍,小冊子。此外,EPUB到PDF的轉換對于使文件與更多的系統環境和操作系統兼容非常有用。本文將使用Java以編程方式探索與EPUB到PDF轉換有關的不同用例。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
EPUB文件用于大規模發布。例如出版書籍,小冊子。此外,EPUB到PDF的轉換對于使文件與更多的系統環境和操作系統兼容非常有用。讓我們使用Java以編程方式探索與EPUB到PDF轉換有關的不同用例:
Aspose.HTML for Java API支持EPUB,PDF和其他幾種文件格式。您可以根據需要輕松地在不同的文件格式之間進行轉換。點擊下方按鈕下方使用。
可以在Java應用程序中將EPUB文件有效地轉換為PDF文檔。因此,以下步驟說明了如何執行轉換:
以下代碼詳細說明了如何使用Java語言以編程方式將EPUB轉換為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"); }
可以使用密碼保護和加密PDF文件,以確保授權或受限訪問。也可以在使用密碼加密輸出文件的同時將EPUB渲染為PDF。以下是使用不同保護措施將EPUB轉換為PDF文件的步驟:
以下代碼段顯示了如何使用Java語言通過密碼保護和加密將EPUB轉換為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"); }
呈現PDF文檔時,您可以控制不同的頁面設置屬性。可以根據需要設置頁面大小,邊距或背景顏色以及其他屬性。因此,將EPUB文件轉換為PDF時,只需按照以下步驟設置與頁面相關的屬性:
下面的代碼基于這些步驟。它顯示了如何使用Java代碼將EPUB文件轉換為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"); }
如果你想試用Aspose的全部完整功能,可聯系在線客服獲取30天臨時授權體驗。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn