如何使用 Java 将 OneNote 转换为 HTML

这篇简单的文章重点介绍如何使用 Java 将 OneNote 转换为 HTML。它代表了配置环境的所有细节,包括使用示例代码的 Aspose.Note、定义的编程任务列表,以及使用 Java 创建基本的 OneNote 到 HTML 转换器的工作代码。开发的应用程序可以在 macOS、Linux 或 Windows 中的任何 Java 配置环境中使用。

使用 Java 将 OneNote 转换为 HTML 的步骤

  1. 配置 IDE 以使用存储库管理器中的 Aspose.Note for Java 将 OneNote 转换为 HTML
  2. 使用 Document 类实例创建一个默认的 OneNote 文件,并在其中添加一个空白页面
  3. 初始化 ParagraphStyle 类并设置所需的文本格式设置
  4. 通过设置标题文本和日期字段为所选页面添加页面标题
  5. 将 OneNote 文件另存为磁盘上的 HTML

上面提到的逐步过程需要使用 Java* 将 *OneNote 导出到 HTML 的过程。该过程将从使用 Document 类实例创建一个默认的 OneNote (.ONE) 文档开始;但是,您也可以访问现有的 OneNote 文件。将在文档中插入一个默认的空白页面,然后使用 ParagraphStyle 类对象为要添加的文本定义文本样式。然后使用先前定义的文本样式为所选页面标题插入页面标题、标题日期和时间,最后,OneNote 文件将导出为磁盘上的 HTML。

使用 Java 将 OneNote 转换为 HTML 的代码

import com.aspose.note.Document;
import com.aspose.note.License;
import static com.aspose.note.NodeType.Page;
import com.aspose.note.Page;
import com.aspose.note.ParagraphStyle;
import com.aspose.note.RichText;
import com.aspose.note.Title;
import java.awt.Color;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class NoteToHtml {
public static void main(String[] htmlArgs) throws IOException{
String path="/Users/Documents/TestData/";
// Set the Note API license
License lic= new License();
lic.setLicense(path + "Conholdate.Total.Product.Family.lic");
//Initialize the OneNote document instance
Document noteDoc = new Document();
//Add a default empty page inside the document
Page page = noteDoc.appendChildLast(new Page());
//Add the styling for the entire text in the document
ParagraphStyle textStyle = new ParagraphStyle();
textStyle.setFontColor(Color.BLACK);
textStyle.setFontName("Arial");
textStyle.setFontSize(10);
Title title = new Title();
RichText titleText = new RichText();
titleText.setText("Title text.");
titleText.setParagraphStyle(textStyle);
title.setTitleText(titleText);
RichText titleDate = new RichText();
DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd");
titleDate.setText(dateFormat.format(new Date(2023,6,9)));
titleDate.setParagraphStyle(textStyle);
title.setTitleText(titleDate);
RichText titleTime = new RichText();
titleTime.setText("12:23");
titleTime.setParagraphStyle(textStyle);
title.setTitleText(titleTime);
page.setTitle(title);
//Convert OneNote to HTML format
noteDoc.save(path + "CreateOneNoteDoc_out.html");
}
}

此示例演示了 OneNote 使用 Java 导出到 HTML 的过程。在自定义文本样式期间,您可以使用 ParagraphStyle 类来配置 FontName、FontColor、FontStyle、删除线、下划线、高亮、斜体和粗体等属性。我们可以有多个段落样式实例,可以为 OneNote 文件中文本的不同部分设置不同的样式。在此演示中,我们只关注为 Page 标题添加文本,但是,您也可以为页面内的其他文档节点设置文本。

本文向我们介绍了使用 Java* 将 *One Note 导出到 HTML 的过程。如果您有兴趣了解保护 .ONE 文件的过程,请参阅 如何使用 Java 保护 OneNote 文件 上的文章。

 简体中文