如何使用 Java 保护 OneNote 文件

本文涉及如何使用 Java 保护 OneNote 文件。它包含 IDE 设置,包括用于执行示例代码的 Aspose.Note、逐步编程流程和实现 OneNote 文档保护的示例代码在 Java 中。开发的应用程序可以在 Windows、macOS 和 Linux 中任何支持 Java 的环境中使用。

在 Java 中锁定 OneNote 文档的步骤

  1. 配置 IDE 以使用存储库管理器中的 Aspose.Note for Java 来密码保护 OneNote 文件
  2. 使用 Document 类对象从磁盘加载源 .ONE 文件
  3. 创建 OneSaveOptions 类的实例并设置所需的密码
  4. 将受密码保护的 .ONE 文件保存在磁盘上

上述步骤展示了在 Java 中*锁定 OneNote 文档的过程。这个过程相当简单,我们将首先使用 Document 类的实例加载源 OneNote 文档文件。然后通过使用 OneSaveOptions 类实例,我们将设置所需的密码并将受密码保护的 .ONE 文件保存在磁盘上。

Java 锁定 OneNote 文档的代码

import com.aspose.note.Document;
import com.aspose.note.License;
import com.aspose.note.OneSaveOptions;
import java.io.IOException;
public class PasswordProtectedNote {
public static void main(String[] argsPass) throws IOException {
String path="/Users/Documents/KnowledgeBase/TestData/";
// Set the Note API license to password protect the Note file
License licNotePasswordProtect= new License();
licNotePasswordProtect.setLicense(path + "Conholdate.Total.Product.Family.lic");
//Load the source OneNote document file
Document noteDocPasswordProtect = new Document(path+"source.one");
//Set the OneNote save options and apply the password
OneSaveOptions opts = new OneSaveOptions();
opts.setDocumentPassword("pass");
//Save the password protected note file
noteDocPasswordProtect.save(path + "CreatePasswordProtectedOneNoteDoc.one",opts);
}
}

此示例演示了使用非常简单的 API 接口在 Java 中保护 .ONE 文档的步骤。 OneSaveOptions 类对象用于设置所需的密码。它还支持设置其他属性,包括设置 FontsSubsystem、页面索引和页数。 OneSaveOptions 实例在重载的 save 方法中用作参数,以在加载的 .ONE 文档上应用设置。

在本文中,我们重点介绍了如何在 Java 中使用密码保护 .ONE 文件。如果您想了解将 .ONE 转换为 JPEG 的过程,请参阅 如何使用 Java 将 OneNote 转换为 JPEG 上的文章。

 简体中文