Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active April 16, 2022 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/8658b930850c543a7a0d86cf7c1d0b92 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/8658b930850c543a7a0d86cf7c1d0b92 to your computer and use it in GitHub Desktop.
Convert OneNote Document to HTML Webpage using C#
// This code example demontstrates how to create a OneNote document and save as HTML.
// Initialize OneNote document
Document doc = new Document();
// Add a page
Page page = new Page();
doc.AppendChildLast(page);
// Default style for all text in the document.
ParagraphStyle textStyle = new ParagraphStyle { FontColor = Color.Black, FontName = "Arial", FontSize = 10 };
// Set title
page.Title = new Title()
{
TitleText = new RichText() { Text = "Title text.", ParagraphStyle = textStyle },
TitleDate = new RichText() { Text = new DateTime(2011, 11, 11).ToString("D", CultureInfo.InvariantCulture), ParagraphStyle = textStyle },
TitleTime = new RichText() { Text = "12:34", ParagraphStyle = textStyle }
};
// Save into HTML format
string dataDir = @"D:\Files\Note\CreateOneNoteDocAndSaveToHTML_out.html";
doc.Save(dataDir);
// This code example demontstrates how to convert an existing OneNote document to HTML.
// Initialize OneNote document
Document doc = new Document(@"D:\Files\Note\Sample1.one");
// Save as HTML
string dataDir = @"D:\Files\Note\Sample1_out.html";
doc.Save(dataDir, SaveFormat.Html);
// This code example demontstrates how to convert a range of pages from OneNote document to HTML.
// Initialize OneNote document
Document doc = new Document(@"D:\Files\Note\Sample1.one");
// Define HTML save options
HtmlSaveOptions htmlSaveOptions = new HtmlSaveOptions()
{
PageCount = 1,
PageIndex = 0
};
// Save into HTML format
string dataDir = @"D:\Files\Note\ConvertRange.html";
doc.Save(dataDir, htmlSaveOptions);
// This code example demontstrates how to convert a OneNote document to HTML and embed resources.
// Initialize OneNote document
Document doc = new Document(@"D:\Files\Note\Sample1.one");
// Define HTML save options
var options = new HtmlSaveOptions()
{
ExportCss = ResourceExportType.ExportEmbedded,
ExportFonts = ResourceExportType.ExportEmbedded,
ExportImages = ResourceExportType.ExportEmbedded,
FontFaceTypes = FontFaceType.Ttf
};
// Save into HTML format
string dataDir = @"D:\Files\Note\ConvertRange.html";
doc.Save(dataDir, htmlSaveOptions);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment