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