For more details, please visit Insert or Extract Image from a OneNote File in Java
Last active
December 23, 2021 05:36
-
-
Save aspose-com-gists/a203abbe23ea73343ae424e0c6ebe423 to your computer and use it in GitHub Desktop.
Insert or Extract Image from a OneNote file using Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load the document into Aspose.Note | |
Document doc = new Document("Sample1.one"); | |
// Get all images | |
List<Image> list = doc.getChildNodes(Image.class); | |
System.out.printf("Total Images: %s\n\n", list.size()); | |
// Traverse the list | |
for (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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 alignment | |
image.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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment