精華|使用教程|編輯:胡濤|2022-08-02 11:30:45.337|閱讀 312 次
概述:在本文中,我們將學習如何使用 Java 將 OneNote 文檔轉換為 PDF。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
OneNote是一個數字筆記本,允許收集、組織和協作筆記、繪圖、屏幕剪輯和音頻評論。在某些情況下,我們可能需要將 OneNote 文檔的內容導出為 PDF 文檔。它允許與沒有 OneNote 的人共享講義。PDF是在不丟失格式的情況下共享和打印文檔的最流行格式。在本文中,我們將學習如何使用 Java 將 OneNote 文檔轉換為 PDF。
本文將涵蓋以下主題:
為了將 OneNote 文檔轉換為 PDF,我們將使用Aspose.Note for Java API。它允許在不使用 Microsoft OneNote 的情況下以編程方式創建、閱讀和轉換 OneNote 文檔。
API的Document類代表一個 Onenote 文檔。它提供了各種方法和屬性來處理 OneNote 文檔。該類的 save() 方法允許將 OneNote 文檔以指定的格式保存在該磁盤上。Page類表示 OneNote 文檔中的一個頁面。API 的 PdfSaveOptions 類提供了用于創建 PDF 的選項,例如 PageIndex、PageCount 等。
請下載API 的 JAR 或在基于 Maven 的 Java 應用程序中添加以下pom.xml配置。
<repository> <id>AsposeJavaAPI</id> <name>Aspose Java API</name> <url>//repository.aspose.com/repo/</url> </repository><dependency> <groupId>com.aspose</groupId> <artifactId>aspose-note</artifactId> <version>22.3</version> <classifier>jdk17</classifier> </dependency>
我們可以按照以下步驟將現有的 OneNote 文檔轉換為 PDF:
以下代碼示例展示了如何使用 Java 將現有 OneNote 文檔轉換為 PDF。
// This code example demonstrates how to convert an existing OneNote to PDF. // Load an existing OneNote document. Document oneFile = new Document("C:\\Files\\Sample1.one"); // Save OneNote as PDF oneFile.save("C:\\Files\\Sample1_out.pdf", SaveFormat.Pdf);
我們可以按照以下步驟創建 OneNote 文檔并以編程方式將其轉換為 PDF:
以下代碼示例展示了如何創建 OneNote 文檔并使用 Java 將其轉換為 PDF。
// This code example demonstrates how to create a new OneNote document and convert to PDF. // Initialize OneNote document Document doc = new Document(); // Add new Page Page page = new Page(); // Default style for all text in the document. ParagraphStyle textStyle = new ParagraphStyle(); textStyle.setFontColor(Color.BLACK); textStyle.setFontName("Arial"); textStyle.setFontSize(10); // Set page title properties Title title = new Title(); RichText titleText = new RichText(); titleText.setText("Title text."); titleText.setParagraphStyle(textStyle); title.setTitleText(titleText); RichText titleDate = new RichText(); Calendar cal = Calendar.getInstance(); cal.set(2018, 04, 03); titleDate.setText(cal.getTime().toString()); titleDate.setParagraphStyle(textStyle); title.setTitleDate(titleDate); RichText titleTime = new RichText(); titleTime.setText("12:34"); titleTime.setParagraphStyle(textStyle); title.setTitleText(titleTime); page.setTitle(title); // Append Page node in the document doc.appendChildLast(page); // Save into PDF format doc.save("C:\\Files\\CreateOneNoteDocAndSaveAsPDF.pdf");
我們可以按照以下步驟將一系列頁面從 OneNote 文檔轉換為 PDF:
以下代碼示例展示了如何使用 Java 將一系列頁面從 OneNote 文檔轉換為 PDF。
// This code example demonstrates how to convert a range of pages of a OneNote to PDF. // Load the document Document oneFile = new Document("C:\\Files\\Sample1.one"); // Initialize PdfSaveOptions object PdfSaveOptions options = new PdfSaveOptions(); // Set page index: 0 means to start saving from first page. options.setPageIndex(0); // Set page count: 1 means to save only one page. options.setPageCount(1); // Save OneNote as PDF oneFile.save("C:\\Files\\ConvertRange_out.pdf", options);
我們可以按照以下步驟在將 OneNote 文檔的圖像轉換為 PDF 文檔時對其進行壓縮:
以下代碼示例展示了如何將 OneNote 文檔轉換為 PDF 并使用 Java 應用圖像壓縮。
// This code example demonstrates how to convert a OneNote to PDF with Image compression. // Load the document Document oneFile = new Document("C:\\Files\\Sample1.one"); // Initialize PdfSaveOptions object PdfSaveOptions options = new PdfSaveOptions(); // Use Jpeg compression options.setImageCompression(PdfImageCompression.Jpeg); // Quality for JPEG compression options.setJpegQuality(90); // Save OneNote as PDF oneFile.save("C:\\Files\\ConvertWithImageCompression.pdf", options);
在本文中,我們學習了如何:
歡迎下載|體驗更多Aspose產品
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn