精華|使用教程|編輯:胡濤|2022-08-02 11:30:45.337|閱讀 312 次
概述:在本文中,我們將學(xué)習(xí)如何使用 Java 將 OneNote 文檔轉(zhuǎn)換為 PDF。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
OneNote是一個(gè)數(shù)字筆記本,允許收集、組織和協(xié)作筆記、繪圖、屏幕剪輯和音頻評(píng)論。在某些情況下,我們可能需要將 OneNote 文檔的內(nèi)容導(dǎo)出為 PDF 文檔。它允許與沒有 OneNote 的人共享講義。PDF是在不丟失格式的情況下共享和打印文檔的最流行格式。在本文中,我們將學(xué)習(xí)如何使用 Java 將 OneNote 文檔轉(zhuǎn)換為 PDF。
本文將涵蓋以下主題:
為了將 OneNote 文檔轉(zhuǎn)換為 PDF,我們將使用Aspose.Note for Java API。它允許在不使用 Microsoft OneNote 的情況下以編程方式創(chuàng)建、閱讀和轉(zhuǎn)換 OneNote 文檔。
API的Document類代表一個(gè) Onenote 文檔。它提供了各種方法和屬性來處理 OneNote 文檔。該類的 save() 方法允許將 OneNote 文檔以指定的格式保存在該磁盤上。Page類表示 OneNote 文檔中的一個(gè)頁面。API 的 PdfSaveOptions 類提供了用于創(chuàng)建 PDF 的選項(xiàng),例如 PageIndex、PageCount 等。
請(qǐng)下載API 的 JAR 或在基于 Maven 的 Java 應(yīng)用程序中添加以下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>
我們可以按照以下步驟將現(xiàn)有的 OneNote 文檔轉(zhuǎn)換為 PDF:
以下代碼示例展示了如何使用 Java 將現(xiàn)有 OneNote 文檔轉(zhuǎn)換為 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);
我們可以按照以下步驟創(chuàng)建 OneNote 文檔并以編程方式將其轉(zhuǎn)換為 PDF:
以下代碼示例展示了如何創(chuàng)建 OneNote 文檔并使用 Java 將其轉(zhuǎn)換為 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 文檔轉(zhuǎn)換為 PDF:
以下代碼示例展示了如何使用 Java 將一系列頁面從 OneNote 文檔轉(zhuǎn)換為 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 文檔的圖像轉(zhuǎn)換為 PDF 文檔時(shí)對(duì)其進(jìn)行壓縮:
以下代碼示例展示了如何將 OneNote 文檔轉(zhuǎn)換為 PDF 并使用 Java 應(yīng)用圖像壓縮。
// 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);
在本文中,我們學(xué)習(xí)了如何:
歡迎下載|體驗(yàn)更多Aspose產(chǎn)品
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn