Learn how to insert PDF into a OneNote as an attachment using C# : https://blog.aspose.com/note/insert-pdf-into-onenote-using-csharp/
The following topics are covered in this article:
Learn how to insert PDF into a OneNote as an attachment using C# : https://blog.aspose.com/note/insert-pdf-into-onenote-using-csharp/
The following topics are covered in this article:
// Load an existing OneNote document | |
Document doc = new Document("C:\\Files\\Sample1.one"); | |
// Initialize Page class object | |
Page page = new Page(); | |
// Initialize Outline class object | |
Outline outline = new Outline(); | |
// Initialize OutlineElement class object | |
OutlineElement outlineElem = new OutlineElement(); | |
// Input PDF file to insert | |
var stream = File.OpenRead("C:\\Files\\companies.pdf"); | |
// PDF file icon to insert | |
var iconStream = File.OpenRead("C:\\Files\\PDF_Icon.png"); | |
// Initialize AttachedFile class object and also pass its icon path | |
//AttachedFile attachedFile = new AttachedFile("companies.pdf", stream); | |
AttachedFile attachedFile = new AttachedFile("companies.pdf", stream, iconStream, ImageFormat.Png); | |
// Add attached file | |
outlineElem.AppendChildLast(attachedFile); | |
// Add outline element node | |
outline.AppendChildLast(outlineElem); | |
// Add outline node | |
page.AppendChildLast(outline); | |
// Add page node | |
doc.AppendChildLast(page); | |
// Save the Document | |
doc.Save("C:\\Files\\Sample1_out.one"); |
// Create an object of the Document class | |
Document doc = new Document(); | |
// Initialize Page class object | |
Page page = new Page(); | |
// Initialize Outline class object | |
Outline outline = new Outline(); | |
// Initialize OutlineElement class object | |
OutlineElement outlineElem = new OutlineElement(); | |
// Input PDF file to insert | |
var stream = File.OpenRead("C:\\Files\\companies.pdf"); | |
// PDF file icon to insert | |
var iconStream = File.OpenRead("C:\\Files\\PDF_Icon.png"); | |
// Initialize AttachedFile class object and also pass its icon path | |
//AttachedFile attachedFile = new AttachedFile("companies.pdf", stream); | |
AttachedFile attachedFile = new AttachedFile("companies.pdf", stream, iconStream, ImageFormat.Png); | |
// Add attached file | |
outlineElem.AppendChildLast(attachedFile); | |
// Add outline element node | |
outline.AppendChildLast(outlineElem); | |
// Add outline node | |
page.AppendChildLast(outline); | |
// Add page node | |
doc.AppendChildLast(page); | |
// Save the Document | |
doc.Save("C:\\Files\\AttachFileAndSetIcon_out.one"); |