Basic samples how to convert OneNote to Html

Save OneNote to Html using default options

The following code example demonstrates how to convert OneNote to Html using the default options. With default options all pages of the document are saved, css and images are saved to separate files and fonts are not exported.

                
            

Save specified page’s range of OneNote to Html

The following code example demonstrates how to convert a specified range of pages from OneNote to Html. This range is specified by setting PageIndex and PageCount properties.

The code below saves the first page of OneNote document into a file in HTML format.

 1            // The path to the documents directory.
 2            string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
 3
 4            // Initialize OneNote document
 5            Document doc = new Document();
 6
 7            Page page = doc.AppendChildLast(new Page(null));
 8     
 9            // Default style for all text in the document.
10            ParagraphStyle textStyle = new ParagraphStyle { FontColor = Color.Black, FontName = "Arial", FontSize = 10 };
11            page.Title = new Title(doc)
12                         {
13                             TitleText = new RichText(doc) { Text = "Title text.", ParagraphStyle = textStyle },
14                             TitleDate = new RichText(doc) { Text = new DateTime(2011, 11, 11).ToString("D", CultureInfo.InvariantCulture), ParagraphStyle = textStyle },
15                             TitleTime = new RichText(doc) { Text = "12:34", ParagraphStyle = textStyle }
16                         };
17
18            // Save into HTML format
19            dataDir = dataDir + "CreateAndSavePageRange_out.html";
20            doc.Save(dataDir, new HtmlSaveOptions
21                              {
22                                  PageCount = 1,
23                                  PageIndex = 0
24                              });

Save OneNote to Html with embedded resources

Html/CSS allows to store inside all required resources(fonts/images/css). The following code example demonstrates how to convert OneNote to Html with embedding of all resources(css/fonts/images).

 1            string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
 2            var document = new Document(Path.Combine(dataDir, "Aspose.one"));
 3
 4            var options = new HtmlSaveOptions()
 5                         {
 6                             ExportCss = ResourceExportType.ExportEmbedded,
 7                             ExportFonts = ResourceExportType.ExportEmbedded,
 8                             ExportImages = ResourceExportType.ExportEmbedded,
 9                             FontFaceTypes = FontFaceType.Ttf
10                         };
11            
12            var r = new MemoryStream();
13            document.Save(r, options);

Save OneNote to Html with resources in separate files

The default way to store resources like fonts/images/css is external files. The following code example demonstrates how to convert OneNote to Html with storing all resources(css/fonts/images) to a separate files.

 1            string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
 2            var document = new Document(Path.Combine(dataDir, "Aspose.one"));
 3
 4            var options = new HtmlSaveOptions()
 5                         {
 6                             ExportCss = ResourceExportType.ExportAsStream,
 7                             ExportFonts = ResourceExportType.ExportAsStream,
 8                             ExportImages = ResourceExportType.ExportAsStream,
 9                             FontFaceTypes = FontFaceType.Ttf
10                         };
11            document.Save(dataDir + "document_out.html", options);
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.