For more details, please visit Insert or Extract Images from OneNote File in C#
Last active
December 23, 2021 05:50
-
-
Save aspose-com-gists/12bbcc53310dce4971854eae512f54e8 to your computer and use it in GitHub Desktop.
Insert or Extract Images from OneNote .one File Programmatically using C#
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 with Document class. | |
Document oneFile = new Document(dataDir + "Aspose.one"); | |
// Get all Image nodes | |
IList<Image> nodes = oneFile.GetChildNodes<Image>(); | |
foreach (Image image in nodes) | |
{ | |
using (MemoryStream stream = new MemoryStream(image.Bytes)) | |
{ | |
using (Bitmap bitMap = new Bitmap(stream)) | |
{ | |
// Save image bytes to a file | |
bitMap.Save(String.Format("{0}", Path.GetFileName(image.FileName))); | |
} | |
} | |
} |
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.FirstChild; | |
// Load an image from the file. | |
Image image = new Image(oneFile, "Input.jpg"); | |
// Change the image's size according to your needs (optional). | |
image.Width = 100; | |
image.Height = 100; | |
// Set the image's location in the page (optional). | |
image.VerticalOffset = 400; | |
image.HorizontalOffset = 100; | |
// Set image alignment | |
image.Alignment = 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