OneNote文件处理控件Aspose.Note功能演示:使用 Java 从 OneNote 文件中插入或提取图像

除了文本内容之外,OneNote 文件还可以包含图像或绘图等视觉信息。在某些情况下,您可能需要在 OneNote 文档中插入或提取图像。本文介绍了如何使用 Java 在 .one 文件中插入或提取图像。

除了文本内容之外,OneNote 文件还可以包含图像或绘图等视觉信息。在某些情况下,您可能需要在 OneNote 文档中插入或提取图像。本文介绍了如何使用 Java 在 .one 文件中插入或提取图像。

Aspose.Note for .Java是功能丰富的OneNote文档处理API,可让您读取和转换OneNote文档。如果你还没有用过Aspose.Tasks可以点击这里下载最新版测试。

在 OneNote .one 文件中插入或提取图像 – Java API 安装

您可以使用Aspose.Note for Java API在 OneNote 文件中插入或提取图像。您可以从新版本部分下载 JAR 文件。同样,您可以在 pom.xml 文件中使用以下 Maven 规范对其进行配置:
存储库
 <repositories>
    <repository>
        <id>AsposeJavaAPI</id>
        <name>Aspose Java API</name>
        <url>https://repository.aspose.com/repo/</url>
    </repository>
</repositories>
依赖
 <dependencies>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-note</artifactId>
        <version>21.9</version>
        <classifier>jdk17</classifier>        
    </dependency>
</dependencies>
使用 Java 在 OneNote .one 文件中插入图像

您可以按照以下步骤在 OneNote .one 文件中插入图像:

  • 首先,初始化LoadOptions类对象并加载输入文件。
  • 获取文档的第一页并加载输入图像。
  • 设置图像位置和对齐方式。
  • 使用appendChildLast方法将图像添加到页面。
  • 最后,保存输出的 OneNote 文件。

以下代码片段显示了如何使用 Java 在 OneNote .one 文件中插入图像:

// Initialize LoadOptions class object.LoadOptions options = new LoadOptions();Document oneFile = new Document("Sample1.one", options);// Get the first page of the document.Page page = oneFile.getFirstChild();// Load an image from the file.Image image = new Image(oneFile, "Input.jpg");// Change the image's size according to your needs (optional).image.setWidth(100);image.setHeight(100);// Set the image's location in the page (optional).image.setVerticalOffset(400);image.setHorizontalOffset(100);// Set image alignmentimage.setAlignment(HorizontalAlignment.Right);// Add the image to the page.page.appendChildLast(image);// Save the document in the .one format.oneFile.save("InsertImage_out.one", SaveFormat.One);

使用 Java 从 OneNote .one 文件中提取图像

您可以通过以下步骤从 OneNote 文件中提取图像:

  • 使用Document类加载输入 OneNote 文件。
  • 使用getChildNodes方法获取所有图像。
  • 最后,遍历列表并保存输出图像。

下面的代码片段演示了如何使用 Java 从 OneNote 文件中提取图像:

// Load the document into Aspose.NoteDocument doc = new Document("Sample1.one");// Get all imagesList<Image> list = doc.getChildNodes(Image.class);System.out.printf("Total Images: %snn", list.size());// Traverse the listfor (int i = 0; i < list.size(); i++) {Image image = list.get(i);String outputFile = "ExtractImages_out" + i + "_" + image.getFileName();byte[] buffer = image.getBytes();        // Save output image file.Files.write(Paths.get(dataDir + outputFile), buffer);}

如果你想试用Aspose的全部完整功能,可联系在线客服获取30天临时授权体验。


还想要更多吗可以点击阅读【Aspose最新资源在线文库】查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询

标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年10月8日
下一篇 2021年10月8日

相关推荐

发表回复

登录后才能评论