Class Document

Class Document

名称: Aspose.Note 集合: Aspose.Note.dll (25.4.0)

代表 Aspose.Note 文件。

public class Document : CompositeNode<page>, INode, ICompositeNode<page>, ICompositeNode, IEnumerable<page>, IEnumerable, INotebookChildNode

Inheritance

object Node CompositeNodeBase CompositeNode Document

Implements

INode , ICompositeNode , ICompositeNode , IEnumerable , IEnumerable , INotebookChildNode

继承人

CompositeNode.GetEnumerator() , CompositeNode.InsertChild(int, T1) , CompositeNode.InsertChildrenRange(int, IEnumerable) , CompositeNode.InsertChildrenRange(int, params Page[]) , CompositeNode.AppendChildFirst(T1) , CompositeNode.AppendChildLast(T1) , CompositeNode.RemoveChild(T1) , CompositeNode.Accept(DocumentVisitor) , CompositeNode.GetChildNodes(NodeType) , CompositeNode.GetChildNodes() , CompositeNode.IsComposite , CompositeNode.FirstChild , CompositeNode.LastChild , CompositeNodeBase.GetChildNodes(NodeType) , CompositeNodeBase.GetChildNodes() , CompositeNodeBase.CheckDocument(Node) , Node.Accept(DocumentVisitor) , Node.Document , Node.IsComposite , Node.NodeType , Node.ParentNode , Node.PreviousSibling , Node.NextSibling , object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()

Examples

显示如何将文档发送到打印机,使用默认的 Windows 对话与默定的选项。

// The path to the documents directory.
                                                                                                      string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                                                                      var document = new Aspose.Note.Document(dataDir + "Aspose.one");

                                                                                                      document.Print();

显示如何保存文件。

string inputFile = "Sample1.one";
                                        string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
                                        string outputFile = "SaveDocToOneNoteFormat_out.one";

                                        Document doc = new Document(dataDir + inputFile);
                                        doc.Save(dataDir + outputFile);

显示如何进行加密文件。

// The path to the documents directory.
                                              string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                              LoadOptions loadOptions = new LoadOptions { DocumentPassword = "password" };
                                              Document doc = new Document(dataDir + "Sample1.one", loadOptions);

显示如何通过加密保存文档。

// The path to the documents directory.
                                                      string dataDir = RunExamples.GetDataDir_NoteBook();

                                                      Document document = new Document();
                                                      document.Save(dataDir + "CreatingPasswordProtectedDoc_out.one", new OneSaveOptions() { DocumentPassword = "pass" });

显示如何使用 SaveFormat 列表保存文档。

string inputFile = "Sample1.one";
                                                                     string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
                                                                     string outputFile = "SaveDocToOneNoteFormatUsingSaveFormat_out.one";

                                                                     Document document = new Document(dataDir + inputFile);

                                                                     document.Save(dataDir + outputFile, SaveFormat.One);

显示如何使用 OneSaveOptions 保存文档。

string inputFile = "Sample1.one";
                                                             string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
                                                             string outputFile = "SaveDocToOneNoteFormatUsingOneSaveOptions_out.one";

                                                             Document document = new Document(dataDir + inputFile);

                                                             document.Save(dataDir + outputFile, new OneSaveOptions());

显示如何获取文档的页面数量。

// The path to the documents directory.
                                                       string dataDir = RunExamples.GetDataDir_Pages();

                                                       // Load the document into Aspose.Note.
                                                       Document oneFile = new Document(dataDir + "Aspose.one");

                                                       // Get number of pages
                                                       int count = oneFile.Count();

                                                       // Print count on the output screen
                                                       Console.WriteLine(count);

显示如何使用默认设置保存文档的PDF格式。

// The path to the documents directory.
                                                                             string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                                             // Load the document into Aspose.Note.
                                                                             Document oneFile = new Document(dataDir + "Aspose.one");

                                                                             // Save the document as PDF
                                                                             dataDir = dataDir + "SaveWithDefaultSettings_out.pdf";
                                                                             oneFile.Save(dataDir, SaveFormat.Pdf);

显示如何在GIF格式保存文档。

// The path to the documents directory.
                                                      string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                      // Load the document into Aspose.Note.
                                                      Document oneFile = new Document(dataDir + "Aspose.one");

                                                      dataDir = dataDir + "SaveToImageDefaultOptions_out.gif";

                                                      // Save the document as gif.
                                                      oneFile.Save(dataDir, SaveFormat.Gif);

显示如何在保存文档时设置图像质量为 JPEG 格式。

// The path to the documents directory.
                                                                                         string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                                                         // Load the document into Aspose.Note.
                                                                                         Document doc = new Document(dataDir + "Aspose.one");

                                                                                         dataDir = dataDir + "SetOutputImageResolution_out.jpg";

                                                                                         // Save the document.
                                                                                         doc.Save(dataDir, new ImageSaveOptions(SaveFormat.Jpeg) { Quality = 100 });

显示如何设置图像分辨率,当将文档保存为图片时。

// The path to the documents directory.
                                                                             string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                                             // Load the document into Aspose.Note.
                                                                             Document doc = new Document(dataDir + "Aspose.one");

                                                                             dataDir = dataDir + "SetOutputImageResolution_out.jpg";

                                                                             // Save the document.
                                                                             doc.Save(dataDir, new ImageSaveOptions(SaveFormat.Jpeg) { Resolution = 220 });

显示如何获取文件格式的文件。

// The path to the documents directory.
                                                      string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                      var document = new Aspose.Note.Document(dataDir + "Aspose.one");
                                                      switch (document.FileFormat)
                                                      {
                                                          case FileFormat.OneNote2010:
                                                              // Process OneNote 2010
                                                              break;
                                                          case FileFormat.OneNoteOnline:
                                                              // Process OneNote Online
                                                              break;
                                                      }

显示如何将 hyperlink 连接到图像。

// The path to the documents directory.
                                                     string dataDir = RunExamples.GetDataDir_Images(); 

                                                     var document = new Document();

                                                     var page = new Page(document);

                                                     var image = new Image(document, dataDir + "image.jpg") { HyperlinkUrl = "http://image.com" };

                                                     page.AppendChildLast(image);

                                                     document.AppendChildLast(page);

                                                     document.Save(dataDir + "Image with Hyperlink_out.one");

显示如何将文件存储在流中。

// The path to the documents directory.
                                                    string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                    // Load the document into Aspose.Note.
                                                    Document doc = new Document(dataDir + "Aspose.one");

                                                    MemoryStream dstStream = new MemoryStream();
                                                    doc.Save(dstStream, SaveFormat.Pdf);

                                                    // Rewind the stream position back to zero so it is ready for next reader.
                                                    dstStream.Seek(0, SeekOrigin.Begin);

显示如何检查文档是否受密码保护。

// The path to the documents directory.
                                                                  string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
                                                                  string fileName = Path.Combine(dataDir, "Aspose.one");

                                                                  Document document;
                                                                  if (!Document.IsEncrypted(fileName, out document))
                                                                  {
                                                                      Console.WriteLine("The document is loaded and ready to be processed.");
                                                                  }
                                                                  else
                                                                  {
                                                                      Console.WriteLine("The document is encrypted. Provide a password.");
                                                                  }

显示如何将新部分添加到笔记本电脑中。

// The path to the documents directory.
                                                      string dataDir = RunExamples.GetDataDir_NoteBook();

                                                      // Load a OneNote Notebook
                                                      var notebook = new Notebook(dataDir + "Notizbuch �ffnen.onetoc2");

                                                      // Append a new child to the Notebook
                                                      notebook.AppendChild(new Document(dataDir + "Neuer Abschnitt 1.one"));

                                                      dataDir = dataDir + "AddChildNode_out.onetoc2";

                                                      // Save the Notebook
                                                      notebook.Save(dataDir);

显示如何检查文档负载是否失败,因为 OneNote 2007 格式不支持。

// The path to the documents directory.
                                                                                                        string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
                                                                                                        string fileName = Path.Combine(dataDir, "OneNote2007.one");

                                                                                                        try
                                                                                                        {
                                                                                                            new Document(fileName);
                                                                                                        }
                                                                                                        catch (UnsupportedFileFormatException e)
                                                                                                        {
                                                                                                            if (e.FileFormat == FileFormat.OneNote2007)
                                                                                                            {
                                                                                                                Console.WriteLine("It looks like the provided file is in OneNote 2007 format that is not supported.");
                                                                                                            }
                                                                                                            else
                                                                                                                throw;
                                                                                                        }

显示如何恢复一页的旧版本。

// The path to the documents directory.
                                                           string dataDir = RunExamples.GetDataDir_Pages();

                                                           // Load OneNote document and get first child           
                                                           Document document = new Document(dataDir + "Aspose.one");
                                                           Page page = document.FirstChild;           
                                                           Page previousPageVersion = document.GetPageHistory(page).Last();

                                                           document.RemoveChild(page);
                                                           document.AppendChildLast(previousPageVersion);

                                                           document.Save(dataDir + "RollBackRevisions_out.one");

如何克隆一页

// The path to the documents directory.
                                     string dataDir = RunExamples.GetDataDir_Pages();

                                     // Load OneNote document
                                     Document document = new Document(dataDir + "Aspose.one", new LoadOptions { LoadHistory = true });

                                     // Clone into new document without history
                                     var cloned = new Document();
                                     cloned.AppendChildLast(document.FirstChild.Clone());

                                     // Clone into new document with history
                                     cloned = new Document();
                                     cloned.AppendChildLast(document.FirstChild.Clone(true));

显示如何将文档保存到 html 格式,并将所有资源(css/fonts/images)存储到单独的文件中。

string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
                                                                                                                        var document = new Document(Path.Combine(dataDir, "Aspose.one"));

                                                                                                                        var options = new HtmlSaveOptions()
                                                                                                                                     {
                                                                                                                                         ExportCss = ResourceExportType.ExportAsStream,
                                                                                                                                         ExportFonts = ResourceExportType.ExportAsStream,
                                                                                                                                         ExportImages = ResourceExportType.ExportAsStream,
                                                                                                                                         FontFaceTypes = FontFaceType.Ttf
                                                                                                                                     };
                                                                                                                        document.Save(dataDir + "document_out.html", options);

显示如何将文档存储到 html 格式的流程,并包含所有资源(css/fonts/images)。

string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
                                                                                                                     var document = new Document(Path.Combine(dataDir, "Aspose.one"));

                                                                                                                     var options = new HtmlSaveOptions()
                                                                                                                                  {
                                                                                                                                      ExportCss = ResourceExportType.ExportEmbedded,
                                                                                                                                      ExportFonts = ResourceExportType.ExportEmbedded,
                                                                                                                                      ExportImages = ResourceExportType.ExportEmbedded,
                                                                                                                                      FontFaceTypes = FontFaceType.Ttf
                                                                                                                                  };

                                                                                                                     var r = new MemoryStream();
                                                                                                                     document.Save(r, options);

显示如何为图像设置文本描述。

// The path to the documents directory.
                                                          string dataDir = RunExamples.GetDataDir_Images();

                                                          var document = new Document();
                                                          var page = new Page(document);
                                                          var image = new Image(document, dataDir + "image.jpg")
                                                                      {
                                                                          AlternativeTextTitle = "This is an image's title!",
                                                                          AlternativeTextDescription = "And this is an image's description!"
                                                                      };
                                                          page.AppendChildLast(image);
                                                          document.AppendChildLast(page);

                                                          dataDir = dataDir + "ImageAlternativeText_out.one";
                                                          document.Save(dataDir);

显示如何获取关于页面的 meta 信息。

// The path to the documents directory.
                                                          string dataDir = RunExamples.GetDataDir_Pages();

                                                          // Load the document into Aspose.Note.
                                                          Document oneFile = new Document(dataDir + "Aspose.one");

                                                          foreach (Page page in oneFile)
                                                          {
                                                              Console.WriteLine("LastModifiedTime: {0}", page.LastModifiedTime);
                                                              Console.WriteLine("CreationTime: {0}", page.CreationTime);
                                                              Console.WriteLine("Title: {0}", page.Title);
                                                              Console.WriteLine("Level: {0}", page.Level);
                                                              Console.WriteLine("Author: {0}", page.Author);
                                                              Console.WriteLine();
                                                          }

当长 OneNote 页面存储在 PDF 格式时,它们分为各页。

// The path to the documents directory.
                                                                                                                                                                                  string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                                                                                                                                                  // Load the document into Aspose.Note.
                                                                                                                                                                                  Document doc = new Document(dataDir + "Aspose.one");

                                                                                                                                                                                  var pdfSaveOptions = new PdfSaveOptions();

                                                                                                                                                                                  pdfSaveOptions.PageSplittingAlgorithm = new KeepPartAndCloneSolidObjectToNextPageAlgorithm(100);
                                                                                                                                                                                  // or
                                                                                                                                                                                  pdfSaveOptions.PageSplittingAlgorithm = new KeepPartAndCloneSolidObjectToNextPageAlgorithm(400);

                                                                                                                                                                                  dataDir = dataDir + "PageSplittUsingKeepPartAndCloneSolidObjectToNextPageAlgorithm_out.pdf";
                                                                                                                                                                                  doc.Save(dataDir);

显示如何保存文档在png格式。

// The path to the documents directory.
                                                      string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                      // Load the document into Aspose.Note.
                                                      Document oneFile = new Document(dataDir + "Aspose.one");

                                                      // Initialize ImageSaveOptions object 
                                                      ImageSaveOptions opts = new ImageSaveOptions(SaveFormat.Png)
                                                                                  {
                                                                                      // Set page index
                                                                                      PageIndex = 1
                                                                                  };

                                                      dataDir = dataDir + "ConvertSpecificPageToImage_out.png";

                                                      // Save the document as PNG.
                                                      oneFile.Save(dataDir, opts);

显示如何编辑页面的历史。

// The path to the documents directory.
                                            string dataDir = RunExamples.GetDataDir_Pages();

                                            // Load OneNote document and get first child           
                                            Document document = new Document(dataDir + "Aspose.one");
                                            Page page = document.FirstChild;

                                            var pageHistory = document.GetPageHistory(page);

                                            pageHistory.RemoveRange(0, 1);

                                            pageHistory[0] = new Page(document);
                                            if (pageHistory.Count &gt; 1)
                                            {
                                                pageHistory[1].Title.TitleText.Text = "New Title";

                                                pageHistory.Add(new Page(document));

                                                pageHistory.Insert(1, new Page(document));

                                                document.Save(dataDir + "ModifyPageHistory_out.one");
                                            }

显示如何检查文档是否被特定密码保护。

// The path to the documents directory.
                                                                                       string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
                                                                                       string fileName = Path.Combine(dataDir, "Aspose.one");

                                                                                       Document document;
                                                                                       if (Document.IsEncrypted(fileName, "VerySecretPassword", out document))
                                                                                       {
                                                                                           if (document != null)
                                                                                           {
                                                                                               Console.WriteLine("The document is decrypted. It is loaded and ready to be processed.");
                                                                                           }
                                                                                           else
                                                                                           {
                                                                                               Console.WriteLine("The document is encrypted. Invalid password was provided.");
                                                                                           }
                                                                                       }
                                                                                       else
                                                                                       {
                                                                                           Console.WriteLine("The document is NOT encrypted. It is loaded and ready to be processed.");
                                                                                       }

显示如何将黑暗主题风格应用到文档。

// The path to the documents directory.
                                                             string dataDir = RunExamples.GetDataDir_Text();

                                                             // Load the document into Aspose.Note.
                                                             Document doc = new Document(Path.Combine(dataDir, "Aspose.one"));

                                                             foreach (var page in doc)
                                                             {
                                                                 page.BackgroundColor = Color.Black;
                                                             }

                                                             foreach (var node in doc.GetChildNodes<richtext>())
                                                             {
                                                                 var c = node.ParagraphStyle.FontColor;
                                                                 if (c.IsEmpty || Math.Abs(c.R - Color.Black.R) + Math.Abs(c.G - Color.Black.G) + Math.Abs(c.B - Color.Black.B) &lt;= 30)
                                                                 {
                                                                     node.ParagraphStyle.FontColor = Color.White;
                                                                 }
                                                             }

                                                             doc.Save(Path.Combine(dataDir, "AsposeDarkTheme.pdf"));</richtext>

展示如何通过笔记本的内容。

// The path to the documents directory.
                                                           string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
                                                           string fileName = "Open Notebook.onetoc2";
                                                           try
                                                           {
                                                               var notebook = new Notebook(dataDir + fileName);
                                                               foreach (var notebookChildNode in notebook)
                                                               {
                                                                   Console.WriteLine(notebookChildNode.DisplayName);
                                                                   if (notebookChildNode is Document)
                                                                   {
                                                                       // Do something with child document
                                                                   }
                                                                   else if (notebookChildNode is Notebook)
                                                                   {
                                                                       // Do something with child notebook
                                                                   }
                                                               }
                                                           }
                                                           catch (Exception ex)
                                                           {
                                                               Console.WriteLine(ex.Message);
                                                           }

显示如何从文件中获取图像。

// The path to the documents directory.
                                                     string dataDir = RunExamples.GetDataDir_Images();

                                                     // Load the document into Aspose.Note.
                                                     Document oneFile = new Document(dataDir + "Aspose.one");

                                                     // Get all Image nodes
                                                     IList<aspose.note.image> nodes = oneFile.GetChildNodes<aspose.note.image>();

                                                     foreach (Aspose.Note.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(dataDir + "{0}", Path.GetFileName(image.FileName)));
                                                             }
                                                         }
                                                     }</aspose.note.image></aspose.note.image>

显示如何在PDF格式保存文档。

// The path to the documents directory.
                                                      string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                      // Load the document into Aspose.Note.
                                                      Document oneFile = new Document(dataDir + "Aspose.one");

                                                      // Initialize PdfSaveOptions object
                                                      PdfSaveOptions opts = new PdfSaveOptions
                                                                                {
                                                                                    // Set page index of first page to be saved
                                                                                    PageIndex = 0,

                                                                                    // Set page count
                                                                                    PageCount = 1,
                                                                                };

                                                      // Save the document as PDF
                                                      dataDir = dataDir + "SaveRangeOfPagesAsPDF_out.pdf";
                                                      oneFile.Save(dataDir, opts);

显示如何使用特定设置保存文档的PDF格式。

// The path to the documents directory.
                                                                              string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                                              // Load the document into Aspose.Note.
                                                                              Document doc = new Document(dataDir + "Aspose.one");

                                                                              // Initialize PdfSaveOptions object
                                                                              PdfSaveOptions opts = new PdfSaveOptions
                                                                                                        {
                                                                                                            // Use Jpeg compression
                                                                                                            ImageCompression = Saving.Pdf.PdfImageCompression.Jpeg,

                                                                                                            // Quality for JPEG compression
                                                                                                            JpegQuality = 90
                                                                                                        };

                                                                              dataDir = dataDir + "Document.SaveWithOptions_out.pdf";
                                                                              doc.Save(dataDir, opts);

显示如何将文档发送到打印机,使用默认的 Windows 对话与指定的选项。

// The path to the documents directory.
                                                                                                        string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                                                                        var document = new Aspose.Note.Document(dataDir + "Aspose.one");

                                                                                                        var printerSettings = new PrinterSettings() { FromPage = 0, ToPage = 10 };
                                                                                                        printerSettings.DefaultPageSettings.Landscape = true;
                                                                                                        printerSettings.DefaultPageSettings.Margins = new System.Drawing.Printing.Margins(50, 50, 150, 50);

                                                                                                        document.Print(new PrintOptions()
                                                                                                                       {
                                                                                                                           PrinterSettings = printerSettings,
                                                                                                                           Resolution = 1200,
                                                                                                                           PageSplittingAlgorithm = new KeepSolidObjectsAlgorithm(),
                                                                                                                           DocumentName = "Test.one"
                                                                                                                       });

显示如何从附件文件中获取内容。

// The path to the documents directory.
                                                        string dataDir = RunExamples.GetDataDir_Attachments();

                                                        // Load the document into Aspose.Note.
                                                        Document oneFile = new Document(dataDir + "Sample1.one");

                                                        // Get a list of attached file nodes
                                                        IList<attachedfile> nodes = oneFile.GetChildNodes<attachedfile>();

                                                        // Iterate through all nodes
                                                        foreach (AttachedFile file in nodes)
                                                        {
                                                            // Load attached file to a stream object
                                                            using (Stream outputStream = new MemoryStream(file.Bytes))
                                                            {
                                                                // Create a local file
                                                                using (Stream fileStream = System.IO.File.OpenWrite(String.Format(dataDir + file.FileName)))
                                                                {
                                                                    // Copy file stream
                                                                    CopyStream(outputStream, fileStream);
                                                                }
                                                            }
                                                        }</attachedfile></attachedfile>

显示如何获取图像的 meta 信息。

// The path to the documents directory.
                                                     string dataDir = RunExamples.GetDataDir_Images();

                                                     // Load the document into Aspose.Note.
                                                     Document oneFile = new Document(dataDir + "Aspose.one");

                                                     // Get all Image nodes
                                                     IList<aspose.note.image> images = oneFile.GetChildNodes<aspose.note.image>();

                                                     foreach (Aspose.Note.Image image in images)
                                                     {
                                                         Console.WriteLine("Width: {0}", image.Width);
                                                         Console.WriteLine("Height: {0}", image.Height);
                                                         Console.WriteLine("OriginalWidth: {0}", image.OriginalWidth);
                                                         Console.WriteLine("OriginalHeight: {0}", image.OriginalHeight);
                                                         Console.WriteLine("FileName: {0}", image.FileName);
                                                         Console.WriteLine("LastModifiedTime: {0}", image.LastModifiedTime);
                                                         Console.WriteLine();
                                                     }</aspose.note.image></aspose.note.image>

显示如何获取页面历史。

// The path to the documents directory.
                                           string dataDir = RunExamples.GetDataDir_Pages();

                                           // Load OneNote document
                                           Document document = new Document(dataDir + "Aspose.one", new LoadOptions { LoadHistory = true });

                                           // Get first page
                                           Page firstPage = document.FirstChild;
                                           foreach (Page pageRevision in document.GetPageHistory(firstPage))
                                           {
                                               /*Use pageRevision like a regular page.*/
                                               Console.WriteLine("LastModifiedTime: {0}", pageRevision.LastModifiedTime);
                                               Console.WriteLine("CreationTime: {0}", pageRevision.CreationTime);
                                               Console.WriteLine("Title: {0}", pageRevision.Title);
                                               Console.WriteLine("Level: {0}", pageRevision.Level);
                                               Console.WriteLine("Author: {0}", pageRevision.Author);
                                               Console.WriteLine();
                                           }

显示如何使用文件路径将文件添加到文档中。

// The path to the documents directory.
                                                                   string dataDir = RunExamples.GetDataDir_Attachments();

                                                                   // Create an object of the Document class
                                                                   Document doc = new Document();

                                                                   // Initialize Page class object
                                                                   Aspose.Note.Page page = new Aspose.Note.Page(doc);

                                                                   // Initialize Outline class object
                                                                   Outline outline = new Outline(doc);

                                                                   // Initialize OutlineElement class object
                                                                   OutlineElement outlineElem = new OutlineElement(doc);

                                                                   // Initialize AttachedFile class object
                                                                   AttachedFile attachedFile = new AttachedFile(doc,  dataDir + "attachment.txt");

                                                                   // 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);

                                                                   dataDir = dataDir + "AttachFileByPath_out.one";
                                                                   doc.Save(dataDir);

显示如何创建文档并使用默认选项将其保存到 html 格式。

// The path to the documents directory.
                                                                                           string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                                                           // Initialize OneNote document
                                                                                           Document doc = new Document();
                                                                                           Page page = doc.AppendChildLast(new Page());

                                                                                           // Default style for all text in the document.
                                                                                           ParagraphStyle textStyle = new ParagraphStyle { FontColor = Color.Black, FontName = "Arial", FontSize = 10 };
                                                                                           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
                                                                                           dataDir = dataDir + "CreateOneNoteDocAndSaveToHTML_out.html";
                                                                                           doc.Save(dataDir);

显示如何检查一页是否是一个冲突页面(即它有 OneNote 无法自动合并的变更)。

string dataDir = RunExamples.GetDataDir_Pages();

                                                                                                                          // Load OneNote document
                                                                                                                          Document doc = new Document(dataDir + "Aspose.one", new LoadOptions { LoadHistory = true });

                                                                                                                          var history = doc.GetPageHistory(doc.FirstChild);
                                                                                                                          for (int i = 0; i &lt; history.Count; i++)
                                                                                                                          {
                                                                                                                              var historyPage = history[i];
                                                                                                                              Console.Write("    {0}. Author: {1}, {2:dd.MM.yyyy hh.mm.ss}",
                                                                                                                                              i,
                                                                                                                                              historyPage.PageContentRevisionSummary.AuthorMostRecent,
                                                                                                                                              historyPage.PageContentRevisionSummary.LastModifiedTime);
                                                                                                                              Console.WriteLine(historyPage.IsConflictPage ? ", IsConflict: true" : string.Empty);

                                                                                                                              // By default conflict pages are just skipped on saving.
                                                                                                                              // If mark it as non-conflict then it will be saved as usual one in the history.
                                                                                                                              if (historyPage.IsConflictPage)
                                                                                                                                  historyPage.IsConflictPage = false;
                                                                                                                          }

                                                                                                                          doc.Save(dataDir + "ConflictPageManipulation_out.one", SaveFormat.One);

显示如何从文件中添加图像到具有用户定义属性的文档。

// The path to the documents directory.
                                                                                          string dataDir = RunExamples.GetDataDir_Images();

                                                                                          // Load document from the stream.
                                                                                          Document doc = new Document(dataDir + "Aspose.one");

                                                                                          // Get the first page of the document.
                                                                                          Aspose.Note.Page page = doc.FirstChild;

                                                                                          // Load an image from the file.
                                                                                          Aspose.Note.Image image = new Aspose.Note.Image(doc, dataDir + "image.jpg")
                                                                                                                    {
                                                                                                                        // Change the image's size according to your needs (optional).
                                                                                                                        Width = 100,
                                                                                                                        Height = 100,

                                                                                                                        // Set the image's location in the page (optional).
                                                                                                                        HorizontalOffset = 100,
                                                                                                                        VerticalOffset = 400,

                                                                                                                        // Set image alignment
                                                                                                                        Alignment = HorizontalAlignment.Right
                                                                                                                    };

                                                                                          // Add the image to the page.
                                                                                          page.AppendChildLast(image);

显示如何从流中添加文件到文档。

// The path to the documents directory.
                                                               string dataDir = RunExamples.GetDataDir_Attachments();

                                                               // Create an object of the Document class
                                                               Document doc = new Document();

                                                               // Initialize Page class object
                                                               Aspose.Note.Page page = new Aspose.Note.Page(doc);

                                                               // Initialize Outline class object
                                                               Outline outline = new Outline(doc);

                                                               // Initialize OutlineElement class object
                                                               OutlineElement outlineElem = new OutlineElement(doc);

                                                               using (var stream = File.OpenRead(dataDir + "icon.jpg"))
                                                               {
                                                                   // Initialize AttachedFile class object and also pass its icon path
                                                                   AttachedFile attachedFile = new AttachedFile(doc, dataDir + "attachment.txt", stream, ImageFormat.Jpeg);

                                                                   // 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);

                                                               dataDir = dataDir + "AttachFileAndSetIcon_out.one";
                                                               doc.Save(dataDir);

当长长的 OneNote 页面存储在 PDF 格式时,它们分为各页。

// The path to the documents directory.
                                                                                                                                                                                   string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                                                                                                                                                   // Load the document into Aspose.Note.
                                                                                                                                                                                   Document doc = new Document(dataDir + "Aspose.one");
                                                                                                                                                                                   var pdfSaveOptions = new PdfSaveOptions();
                                                                                                                                                                                   pdfSaveOptions.PageSplittingAlgorithm = new AlwaysSplitObjectsAlgorithm();
                                                                                                                                                                                   // Or
                                                                                                                                                                                   pdfSaveOptions.PageSplittingAlgorithm = new KeepPartAndCloneSolidObjectToNextPageAlgorithm();
                                                                                                                                                                                   // Or
                                                                                                                                                                                   pdfSaveOptions.PageSplittingAlgorithm = new KeepSolidObjectsAlgorithm();

                                                                                                                                                                                   float heightLimitOfClonedPart = 500;
                                                                                                                                                                                   pdfSaveOptions.PageSplittingAlgorithm = new KeepPartAndCloneSolidObjectToNextPageAlgorithm(heightLimitOfClonedPart);
                                                                                                                                                                                   // Or
                                                                                                                                                                                   pdfSaveOptions.PageSplittingAlgorithm = new KeepSolidObjectsAlgorithm(heightLimitOfClonedPart);

                                                                                                                                                                                   pdfSaveOptions.PageSplittingAlgorithm = new KeepSolidObjectsAlgorithm(100);
                                                                                                                                                                                   // Or
                                                                                                                                                                                   pdfSaveOptions.PageSplittingAlgorithm = new KeepSolidObjectsAlgorithm(400);

                                                                                                                                                                                   dataDir = dataDir + "UsingKeepSOlidObjectsAlgorithm_out.pdf";
                                                                                                                                                                                   doc.Save(dataDir);

显示如何创建文档并在 html 格式中保存指定的页面范围。

// The path to the documents directory.
                                                                                           string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                                                           // Initialize OneNote document
                                                                                           Document doc = new Document();

                                                                                           Page page = doc.AppendChildLast(new Page());

                                                                                           // Default style for all text in the document.
                                                                                           ParagraphStyle textStyle = new ParagraphStyle { FontColor = Color.Black, FontName = "Arial", FontSize = 10 };
                                                                                           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
                                                                                           dataDir = dataDir + "CreateAndSavePageRange_out.html";
                                                                                           doc.Save(dataDir, new HtmlSaveOptions
                                                                                                             {
                                                                                                                 PageCount = 1,
                                                                                                                 PageIndex = 0
                                                                                                             });

显示如何创建标题页面的文档。

// The path to the documents directory.
                                                           string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                           // Create an object of the Document class
                                                           Document doc = new Aspose.Note.Document();

                                                           // Initialize Page class object
                                                           Aspose.Note.Page page = new Aspose.Note.Page(doc);

                                                           // Default style for all text in the document.
                                                           ParagraphStyle textStyle = new ParagraphStyle { FontColor = Color.Black, FontName = "Arial", FontSize = 10 };

                                                           // Set page title properties
                                                           page.Title = new Title(doc)
                                                                        {
                                                                            TitleText = new RichText(doc) { Text = "Title text.", ParagraphStyle = textStyle },
                                                                            TitleDate = new RichText(doc) { Text = new DateTime(2011, 11, 11).ToString("D", CultureInfo.InvariantCulture), ParagraphStyle = textStyle },
                                                                            TitleTime = new RichText(doc) { Text = "12:34", ParagraphStyle = textStyle }
                                                                        };

                                                           // Append Page node in the document
                                                           doc.AppendChildLast(page);

                                                           // Save OneNote document
                                                           dataDir = dataDir + "CreateDocWithPageTitle_out.one";
                                                           doc.Save(dataDir);

显示如何从流向文档添加图像。

// The path to the documents directory.
                                                               string dataDir = RunExamples.GetDataDir_Images();

                                                               // Create an object of the Document class
                                                               Document doc = new Document();

                                                               // Initialize Page class object
                                                               Aspose.Note.Page page = new Aspose.Note.Page(doc);

                                                               Outline outline1 = new Outline(doc);
                                                               OutlineElement outlineElem1 = new OutlineElement(doc);

                                                               using (FileStream fs = File.OpenRead(dataDir + "image.jpg"))
                                                               {

                                                                   // Load the second image using the image name, extension and stream.
                                                                   Aspose.Note.Image image1 = new Aspose.Note.Image(doc, "Penguins.jpg", fs)
                                                                                                  {
                                                                                                      // Set image alignment
                                                                                                      Alignment = HorizontalAlignment.Right
                                                                                                  };

                                                                   outlineElem1.AppendChildLast(image1);
                                                               }

                                                               outline1.AppendChildLast(outlineElem1);
                                                               page.AppendChildLast(outline1);

                                                               doc.AppendChildLast(page);

                                                               // Save OneNote document
                                                               dataDir = dataDir + "BuildDocAndInsertImageUsingImageStream_out.one";
                                                               doc.Save(dataDir);

显示如何从文件中添加图像到文档。

// The path to the documents directory.
                                                             string dataDir = RunExamples.GetDataDir_Images();

                                                             // Create an object of the Document class
                                                             Document doc = new Document();

                                                             // Initialize Page class object
                                                             Aspose.Note.Page page = new Aspose.Note.Page(doc);

                                                             // Initialize Outline class object and set offset properties
                                                             Outline outline = new Outline(doc);

                                                             // Initialize OutlineElement class object
                                                             OutlineElement outlineElem = new OutlineElement(doc);

                                                             // Load an image by the file path.
                                                             Aspose.Note.Image image = new Aspose.Note.Image(doc, dataDir + "image.jpg")
                                                                                       {
                                                                                           // Set image alignment
                                                                                           Alignment = HorizontalAlignment.Right
                                                                                       };

                                                             // Add image
                                                             outlineElem.AppendChildLast(image);

                                                             // Add outline elements
                                                             outline.AppendChildLast(outlineElem);

                                                             // Add Outline node
                                                             page.AppendChildLast(outline);

                                                             // Add Page node
                                                             doc.AppendChildLast(page);

                                                             // Save OneNote document
                                                             dataDir = dataDir + "BuildDocAndInsertImage_out.one";
                                                             doc.Save(dataDir);

显示如何用文本创建文档。

// The path to the documents directory.
                                                      string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                      // Create an object of the Document class
                                                      Document doc = new Document();

                                                      // Initialize Page class object
                                                      Page page = new Page(doc);

                                                      // Initialize Outline class object
                                                      Outline outline = new Outline(doc);

                                                      // Initialize OutlineElement class object
                                                      OutlineElement outlineElem = new OutlineElement(doc);

                                                      // Initialize TextStyle class object and set formatting properties
                                                      ParagraphStyle textStyle = new ParagraphStyle { FontColor = Color.Black, FontName = "Arial", FontSize = 10 };

                                                      // Initialize RichText class object and apply text style
                                                      RichText text = new RichText(doc) { Text = "Hello OneNote text!", ParagraphStyle = textStyle };

                                                      // Add RichText node
                                                      outlineElem.AppendChildLast(text);

                                                      // Add OutlineElement node
                                                      outline.AppendChildLast(outlineElem);

                                                      // Add Outline node
                                                      page.AppendChildLast(outline);

                                                      // Add Page node
                                                      doc.AppendChildLast(page);

                                                      // Save OneNote document
                                                      dataDir = dataDir + "CreateDocWithSimpleRichText_out.one";
                                                      doc.Save(dataDir);

显示如何保存不同格式的文档。

// The path to the documents directory.
                                                             string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                             // Initialize the new Document
                                                             Document doc = new Document() { AutomaticLayoutChangesDetectionEnabled = false };

                                                             // Initialize the new Page
                                                             Aspose.Note.Page page = new Aspose.Note.Page(doc);

                                                             // Default style for all text in the document.
                                                             ParagraphStyle textStyle = new ParagraphStyle { FontColor = Color.Black, FontName = "Arial", FontSize = 10 };
                                                             page.Title = new Title(doc)
                                                                          {
                                                                              TitleText = new RichText(doc) { Text = "Title text.", ParagraphStyle = textStyle },
                                                                              TitleDate = new RichText(doc) { Text = new DateTime(2011, 11, 11).ToString("D", CultureInfo.InvariantCulture), ParagraphStyle = textStyle },
                                                                              TitleTime = new RichText(doc) { Text = "12:34", ParagraphStyle = textStyle }
                                                                          };

                                                             // Append page node
                                                             doc.AppendChildLast(page);

                                                             // Save OneNote document in different formats, set text font size and detect layout changes manually.
                                                             doc.Save(dataDir + "ConsequentExportOperations_out.html");            
                                                             doc.Save(dataDir + "ConsequentExportOperations_out.pdf");            
                                                             doc.Save(dataDir + "ConsequentExportOperations_out.jpg");            
                                                             textStyle.FontSize = 11;           
                                                             doc.DetectLayoutChanges();            
                                                             doc.Save(dataDir + "ConsequentExportOperations_out.bmp");

显示如何在 html 格式中保存文档,通过使用用户定义的呼叫反馈来存储所有资源(css/fonts/images)。

// The code below creates 'documentFolder' folder containing document.html, 'css' folder with 'style.css' file, 'images' folder with images and 'fonts' folder with fonts.
                                                                                                                                    // 'style.css' file will contain at the end the following string "/* This line is appended to stream manually by user */"
                                                                                                                                    var savingCallbacks = new UserSavingCallbacks()
                                                                                                                                                              {
                                                                                                                                                                  RootFolder = "documentFolder",
                                                                                                                                                                  CssFolder = "css",
                                                                                                                                                                  KeepCssStreamOpened = true,
                                                                                                                                                                  ImagesFolder = "images",
                                                                                                                                                                  FontsFolder = "fonts"
                                                                                                                                                              };
                                                                                                                                    var options = new HtmlSaveOptions
                                                                                                                                                  {
                                                                                                                                                      FontFaceTypes = FontFaceType.Ttf,
                                                                                                                                                      CssSavingCallback = savingCallbacks,
                                                                                                                                                      FontSavingCallback = savingCallbacks,
                                                                                                                                                      ImageSavingCallback = savingCallbacks
                                                                                                                                                  };

                                                                                                                                    if (!Directory.Exists(savingCallbacks.RootFolder))
                                                                                                                                    {
                                                                                                                                        Directory.CreateDirectory(savingCallbacks.RootFolder);
                                                                                                                                    }

                                                                                                                                    string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
                                                                                                                                    var document = new Document(Path.Combine(dataDir, "Aspose.one"));

                                                                                                                                    using (var stream = File.Create(Path.Combine(savingCallbacks.RootFolder, "document.html")))
                                                                                                                                    {
                                                                                                                                        document.Save(stream, options);
                                                                                                                                    }

                                                                                                                                    using (var writer = new StreamWriter(savingCallbacks.CssStream))
                                                                                                                                    {
                                                                                                                                        writer.WriteLine();
                                                                                                                                        writer.WriteLine("/* This line is appended to stream manually by user */");
                                                                                                                                    }

显示如何将 hyperlink 连接到文本。

// The path to the documents directory.
                                                   string dataDir = RunExamples.GetDataDir_Tasks();

                                                   // Create an object of the Document class
                                                   Document doc = new Document();

                                                   RichText titleText = new RichText() { ParagraphStyle = ParagraphStyle.Default }.Append("Title!");

                                                   Outline outline = new Outline()
                                                                         {
                                                                             MaxWidth = 200,
                                                                             MaxHeight = 200,
                                                                             VerticalOffset = 100,
                                                                             HorizontalOffset = 100
                                                                         };

                                                   TextStyle textStyleRed = new TextStyle
                                                                                {
                                                                                    FontColor = Color.Red,
                                                                                    FontName = "Arial",
                                                                                    FontSize = 10,
                                                                                };

                                                   TextStyle textStyleHyperlink = new TextStyle
                                                                                      {
                                                                                          IsHyperlink = true,
                                                                                          HyperlinkAddress = "www.google.com"
                                                                                      };

                                                   RichText text = new RichText() { ParagraphStyle = ParagraphStyle.Default }
                                                                       .Append("This is ", textStyleRed)
                                                                       .Append("hyperlink", textStyleHyperlink)
                                                                       .Append(". This text is not a hyperlink.", TextStyle.Default);

                                                   OutlineElement outlineElem = new OutlineElement();
                                                   outlineElem.AppendChildLast(text);

                                                   // Add outline elements
                                                   outline.AppendChildLast(outlineElem);

                                                   // Initialize Title class object
                                                   Title title = new Title() { TitleText = titleText };

                                                   // Initialize Page class object
                                                   Page page = new Note.Page() { Title = title };

                                                   // Add Outline node
                                                   page.AppendChildLast(outline);

                                                   // Add Page node
                                                   doc.AppendChildLast(page);

                                                   // Save OneNote document
                                                   dataDir = dataDir + "AddHyperlink_out.one";
                                                   doc.Save(dataDir);

显示如何使用访问者访问文档的内容。

public static void Run()
                                                                   {
                                                                       // The path to the documents directory.
                                                                       string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                                       // Open the document we want to convert.
                                                                       Document doc = new Document(dataDir + "Aspose.one");

                                                                       // Create an object that inherits from the DocumentVisitor class.
                                                                       MyOneNoteToTxtWriter myConverter = new MyOneNoteToTxtWriter();

                                                                       // This is the well known Visitor pattern. Get the model to accept a visitor.
                                                                       // The model will iterate through itself by calling the corresponding methods
                                                                       // on the visitor object (this is called visiting).
                                                                       //
                                                                       // Note that every node in the object model has the Accept method so the visiting
                                                                       // can be executed not only for the whole document, but for any node in the document.
                                                                       doc.Accept(myConverter);

                                                                       // Once the visiting is complete, we can retrieve the result of the operation,
                                                                       // that in this example, has accumulated in the visitor.
                                                                       Console.WriteLine(myConverter.GetText());
                                                                       Console.WriteLine(myConverter.NodeCount);            
                                                                   }

                                                                   /// <summary>
                                                                   /// Simple implementation of saving a document in the plain text format. Implemented as a Visitor.
                                                                   /// </summary>
                                                                   public class MyOneNoteToTxtWriter : DocumentVisitor
                                                                   {
                                                                       public MyOneNoteToTxtWriter()
                                                                       {
                                                                           nodecount = 0;
                                                                           mIsSkipText = false;
                                                                           mBuilder = new StringBuilder();
                                                                       }

                                                                       /// <summary>
                                                                       /// Gets the plain text of the document that was accumulated by the visitor.
                                                                       /// </summary>
                                                                       public string GetText()
                                                                       {
                                                                           return mBuilder.ToString();
                                                                       }

                                                                       /// <summary>
                                                                       /// Adds text to the current output. Honors the enabled/disabled output flag.
                                                                       /// </summary>
                                                                       private void AppendText(string text)
                                                                       {
                                                                           if (!mIsSkipText)
                                                                           {
                                                                               mBuilder.AppendLine(text);
                                                                           }
                                                                       }

                                                                       /// <summary>
                                                                       /// Called when a RichText node is encountered in the document.
                                                                       /// </summary>
                                                                       public override void VisitRichTextStart(RichText run)
                                                                       {
                                                                           ++nodecount;
                                                                           AppendText(run.Text);
                                                                       }

                                                                       /// <summary>
                                                                       /// Called when a Document node is encountered in the document.
                                                                       /// </summary>
                                                                       public override void VisitDocumentStart(Document document)
                                                                       {
                                                                           ++nodecount;
                                                                       }

                                                                       /// <summary>
                                                                       /// Called when a Page node is encountered in the document.
                                                                       /// </summary>
                                                                       public override void VisitPageStart(Page page)
                                                                       {
                                                                           ++nodecount;
                                                                           this.AppendText($"*** Page '{page.Title?.TitleText?.Text ?? "(no title)"}' ***");
                                                                       }

                                                                       /// <summary>
                                                                       /// Called when processing of a Page node is finished.
                                                                       /// </summary>
                                                                       public override void VisitPageEnd(Page page)
                                                                       {
                                                                           this.AppendText(string.Empty);
                                                                       }

                                                                       /// <summary>
                                                                       /// Called when a Title node is encountered in the document.
                                                                       /// </summary>
                                                                       public override void VisitTitleStart(Title title)
                                                                       {
                                                                           ++nodecount;
                                                                       }

                                                                       /// <summary>
                                                                       /// Called when a Image node is encountered in the document.
                                                                       /// </summary>
                                                                       public override void VisitImageStart(Image image)
                                                                       {
                                                                           ++nodecount;
                                                                       }

                                                                       /// <summary>
                                                                       /// Called when a OutlineGroup node is encountered in the document.
                                                                       /// </summary>
                                                                       public override void VisitOutlineGroupStart(OutlineGroup outlineGroup)
                                                                       {
                                                                           ++nodecount;
                                                                       }

                                                                       /// <summary>
                                                                       /// Called when a Outline node is encountered in the document.
                                                                       /// </summary>
                                                                       public override void VisitOutlineStart(Outline outline)
                                                                       {
                                                                           ++nodecount;
                                                                       }

                                                                       /// <summary>
                                                                       /// Called when a OutlineElement node is encountered in the document.
                                                                       /// </summary>
                                                                       public override void VisitOutlineElementStart(OutlineElement outlineElement)
                                                                       {
                                                                           ++nodecount;
                                                                       }

                                                                       /// <summary>
                                                                       /// Gets the total count of nodes by the Visitor
                                                                       /// </summary>
                                                                       public Int32 NodeCount
                                                                       {
                                                                           get { return this.nodecount; }
                                                                       }

                                                                       private readonly StringBuilder mBuilder;
                                                                       private bool mIsSkipText;
                                                                       private Int32 nodecount;
                                                                   }

Constructors

Document()

启动 Aspose.Note.文档类的新例子。创建一个白色 OneNote 文档。

public Document()

Document(线条)

启动 Aspose.Note.文档类的新例子。从文件中打开现有 OneNote 文档。

public Document(string filePath)

Parameters

filePath string

文件路径。

Exceptions

UnsupportedFileFormatException

文件格式不被认可或支持。

FileCorruptedException

文件似乎是腐败的,不能被加载。

IncorrectPasswordException

文件是加密的,需要一个密码来打开,但您提供了一个错误的密码。

InvalidOperationException

该文件有一个问题,应该向 Aspose.Note 开发人员报告。

IOException

有一个输入/输出例外。

Document(字符串, LoadOptions)

启动 Aspose.Note.文档类的新例子。从文件中打开现有 OneNote 文档. 允许指定额外的选项,如加密密码。

public Document(string filePath, LoadOptions loadOptions)

Parameters

filePath string

文件路径。

loadOptions LoadOptions

用来加载文档的选项,可以是零。

Exceptions

UnsupportedFileFormatException

文件格式不被认可或支持。

FileCorruptedException

文件似乎是腐败的,不能被加载。

IncorrectPasswordException

文件是加密的,需要一个密码来打开,但您提供了一个错误的密码。

InvalidOperationException

该文件有一个问题,应该向 Aspose.Note 开发人员报告。

IOException

有一个输入/输出例外。

Document(Stream)

启动 Aspose.Note.文档类的新例子。从流中打开现有 OneNote 文档。

public Document(Stream inStream)

Parameters

inStream Stream

流的。

Exceptions

UnsupportedFileFormatException

文件格式不被认可或支持。

FileCorruptedException

文件似乎是腐败的,不能被加载。

IncorrectPasswordException

文件是加密的,需要一个密码来打开,但您提供了一个错误的密码。

InvalidOperationException

该文件有一个问题,应该向 Aspose.Note 开发人员报告。

IOException

有一个输入/输出例外。

ArgumentException

流不支持阅读,是零,或者已经关闭。

Document(流量, LoadOptions)

启动 Aspose.Note.文档类的新例子。从流中打开现有 OneNote 文档. 允许指定额外的选项,如加密密码。

public Document(Stream inStream, LoadOptions loadOptions)

Parameters

inStream Stream

流的。

loadOptions LoadOptions

用来加载文档的选项,可以是零。

Exceptions

UnsupportedFileFormatException

文件格式不被认可或支持。

FileCorruptedException

文件似乎是腐败的,不能被加载。

IncorrectPasswordException

文件是加密的,需要一个密码来打开,但您提供了一个错误的密码。

InvalidOperationException

该文件有一个问题,应该向 Aspose.Note 开发人员报告。

IOException

有一个输入/输出例外。

ArgumentException

流不支持阅读,是零,或者已经关闭。

Properties

AutomaticLayoutChangesDetectionEnabled

收到或设置一个值,表明 Aspose.Note 是否会自动检测布局变更。

public bool AutomaticLayoutChangesDetectionEnabled { get; set; }

财产价值

bool

Examples

显示如何保存不同格式的文档。

// The path to the documents directory.
                                                             string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                             // Initialize the new Document
                                                             Document doc = new Document() { AutomaticLayoutChangesDetectionEnabled = false };

                                                             // Initialize the new Page
                                                             Aspose.Note.Page page = new Aspose.Note.Page(doc);

                                                             // Default style for all text in the document.
                                                             ParagraphStyle textStyle = new ParagraphStyle { FontColor = Color.Black, FontName = "Arial", FontSize = 10 };
                                                             page.Title = new Title(doc)
                                                                          {
                                                                              TitleText = new RichText(doc) { Text = "Title text.", ParagraphStyle = textStyle },
                                                                              TitleDate = new RichText(doc) { Text = new DateTime(2011, 11, 11).ToString("D", CultureInfo.InvariantCulture), ParagraphStyle = textStyle },
                                                                              TitleTime = new RichText(doc) { Text = "12:34", ParagraphStyle = textStyle }
                                                                          };

                                                             // Append page node
                                                             doc.AppendChildLast(page);

                                                             // Save OneNote document in different formats, set text font size and detect layout changes manually.
                                                             doc.Save(dataDir + "ConsequentExportOperations_out.html");            
                                                             doc.Save(dataDir + "ConsequentExportOperations_out.pdf");            
                                                             doc.Save(dataDir + "ConsequentExportOperations_out.jpg");            
                                                             textStyle.FontSize = 11;           
                                                             doc.DetectLayoutChanges();            
                                                             doc.Save(dataDir + "ConsequentExportOperations_out.bmp");

Color

收取或设置颜色。

public Color Color { get; set; }

财产价值

Color

CreationTime

得到或设置创作时间。

public DateTime CreationTime { get; set; }

财产价值

DateTime

DisplayName

接收或设置显示名称。

public string DisplayName { get; set; }

财产价值

string

FileFormat

获取文件格式(OneNote 2010, OneNota Online)。

public FileFormat FileFormat { get; }

财产价值

FileFormat

Examples

显示如何获取文件格式的文件。

// The path to the documents directory.
                                                      string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                      var document = new Aspose.Note.Document(dataDir + "Aspose.one");
                                                      switch (document.FileFormat)
                                                      {
                                                          case FileFormat.OneNote2010:
                                                              // Process OneNote 2010
                                                              break;
                                                          case FileFormat.OneNoteOnline:
                                                              // Process OneNote Online
                                                              break;
                                                      }

Guid

获得对象的全球独特ID。

public Guid Guid { get; }

财产价值

Guid

Methods

Accept(DocumentVisitor)

接待节点的参观者。

public override void Accept(DocumentVisitor visitor)

Parameters

visitor DocumentVisitor

一个类的对象源于 Aspose.Note.DocumentVisitor。

Examples

显示如何使用访问者访问文档的内容。

public static void Run()
                                                                   {
                                                                       // The path to the documents directory.
                                                                       string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                                       // Open the document we want to convert.
                                                                       Document doc = new Document(dataDir + "Aspose.one");

                                                                       // Create an object that inherits from the DocumentVisitor class.
                                                                       MyOneNoteToTxtWriter myConverter = new MyOneNoteToTxtWriter();

                                                                       // This is the well known Visitor pattern. Get the model to accept a visitor.
                                                                       // The model will iterate through itself by calling the corresponding methods
                                                                       // on the visitor object (this is called visiting).
                                                                       //
                                                                       // Note that every node in the object model has the Accept method so the visiting
                                                                       // can be executed not only for the whole document, but for any node in the document.
                                                                       doc.Accept(myConverter);

                                                                       // Once the visiting is complete, we can retrieve the result of the operation,
                                                                       // that in this example, has accumulated in the visitor.
                                                                       Console.WriteLine(myConverter.GetText());
                                                                       Console.WriteLine(myConverter.NodeCount);            
                                                                   }

                                                                   /// <summary>
                                                                   /// Simple implementation of saving a document in the plain text format. Implemented as a Visitor.
                                                                   /// </summary>
                                                                   public class MyOneNoteToTxtWriter : DocumentVisitor
                                                                   {
                                                                       public MyOneNoteToTxtWriter()
                                                                       {
                                                                           nodecount = 0;
                                                                           mIsSkipText = false;
                                                                           mBuilder = new StringBuilder();
                                                                       }

                                                                       /// <summary>
                                                                       /// Gets the plain text of the document that was accumulated by the visitor.
                                                                       /// </summary>
                                                                       public string GetText()
                                                                       {
                                                                           return mBuilder.ToString();
                                                                       }

                                                                       /// <summary>
                                                                       /// Adds text to the current output. Honors the enabled/disabled output flag.
                                                                       /// </summary>
                                                                       private void AppendText(string text)
                                                                       {
                                                                           if (!mIsSkipText)
                                                                           {
                                                                               mBuilder.AppendLine(text);
                                                                           }
                                                                       }

                                                                       /// <summary>
                                                                       /// Called when a RichText node is encountered in the document.
                                                                       /// </summary>
                                                                       public override void VisitRichTextStart(RichText run)
                                                                       {
                                                                           ++nodecount;
                                                                           AppendText(run.Text);
                                                                       }

                                                                       /// <summary>
                                                                       /// Called when a Document node is encountered in the document.
                                                                       /// </summary>
                                                                       public override void VisitDocumentStart(Document document)
                                                                       {
                                                                           ++nodecount;
                                                                       }

                                                                       /// <summary>
                                                                       /// Called when a Page node is encountered in the document.
                                                                       /// </summary>
                                                                       public override void VisitPageStart(Page page)
                                                                       {
                                                                           ++nodecount;
                                                                           this.AppendText($"*** Page '{page.Title?.TitleText?.Text ?? "(no title)"}' ***");
                                                                       }

                                                                       /// <summary>
                                                                       /// Called when processing of a Page node is finished.
                                                                       /// </summary>
                                                                       public override void VisitPageEnd(Page page)
                                                                       {
                                                                           this.AppendText(string.Empty);
                                                                       }

                                                                       /// <summary>
                                                                       /// Called when a Title node is encountered in the document.
                                                                       /// </summary>
                                                                       public override void VisitTitleStart(Title title)
                                                                       {
                                                                           ++nodecount;
                                                                       }

                                                                       /// <summary>
                                                                       /// Called when a Image node is encountered in the document.
                                                                       /// </summary>
                                                                       public override void VisitImageStart(Image image)
                                                                       {
                                                                           ++nodecount;
                                                                       }

                                                                       /// <summary>
                                                                       /// Called when a OutlineGroup node is encountered in the document.
                                                                       /// </summary>
                                                                       public override void VisitOutlineGroupStart(OutlineGroup outlineGroup)
                                                                       {
                                                                           ++nodecount;
                                                                       }

                                                                       /// <summary>
                                                                       /// Called when a Outline node is encountered in the document.
                                                                       /// </summary>
                                                                       public override void VisitOutlineStart(Outline outline)
                                                                       {
                                                                           ++nodecount;
                                                                       }

                                                                       /// <summary>
                                                                       /// Called when a OutlineElement node is encountered in the document.
                                                                       /// </summary>
                                                                       public override void VisitOutlineElementStart(OutlineElement outlineElement)
                                                                       {
                                                                           ++nodecount;
                                                                       }

                                                                       /// <summary>
                                                                       /// Gets the total count of nodes by the Visitor
                                                                       /// </summary>
                                                                       public Int32 NodeCount
                                                                       {
                                                                           get { return this.nodecount; }
                                                                       }

                                                                       private readonly StringBuilder mBuilder;
                                                                       private bool mIsSkipText;
                                                                       private Int32 nodecount;
                                                                   }

DetectLayoutChanges()

检测到文档配置的所有变化,从之前的 Aspose.Note.Document.DetectLayoutChanges 呼叫。在 Aspose.Note.Document.AutomaticLayoutChangesDetection 已设置为真实,在文档出口开始时自动使用。

public void DetectLayoutChanges()

Examples

显示如何保存不同格式的文档。

// The path to the documents directory.
                                                             string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                             // Initialize the new Document
                                                             Document doc = new Document() { AutomaticLayoutChangesDetectionEnabled = false };

                                                             // Initialize the new Page
                                                             Aspose.Note.Page page = new Aspose.Note.Page(doc);

                                                             // Default style for all text in the document.
                                                             ParagraphStyle textStyle = new ParagraphStyle { FontColor = Color.Black, FontName = "Arial", FontSize = 10 };
                                                             page.Title = new Title(doc)
                                                                          {
                                                                              TitleText = new RichText(doc) { Text = "Title text.", ParagraphStyle = textStyle },
                                                                              TitleDate = new RichText(doc) { Text = new DateTime(2011, 11, 11).ToString("D", CultureInfo.InvariantCulture), ParagraphStyle = textStyle },
                                                                              TitleTime = new RichText(doc) { Text = "12:34", ParagraphStyle = textStyle }
                                                                          };

                                                             // Append page node
                                                             doc.AppendChildLast(page);

                                                             // Save OneNote document in different formats, set text font size and detect layout changes manually.
                                                             doc.Save(dataDir + "ConsequentExportOperations_out.html");            
                                                             doc.Save(dataDir + "ConsequentExportOperations_out.pdf");            
                                                             doc.Save(dataDir + "ConsequentExportOperations_out.jpg");            
                                                             textStyle.FontSize = 11;           
                                                             doc.DetectLayoutChanges();            
                                                             doc.Save(dataDir + "ConsequentExportOperations_out.bmp");

GetPageHistory(Page)

获取 Aspose.Note.PageHistory 包含在文档中提交的每个页面的完整历史(第一个在 0 指数)。目前的页面修订可以访问为 Aspose.Note.PageHistory.Current,并从历史版本的收藏中单独包含。

public PageHistory GetPageHistory(Page page)

Parameters

page Page

一个页面的当前修订。

Returns

PageHistory

此分類上一篇: WL31_.PageHistory

Examples

显示如何恢复一页的旧版本。

// The path to the documents directory.
                                                           string dataDir = RunExamples.GetDataDir_Pages();

                                                           // Load OneNote document and get first child           
                                                           Document document = new Document(dataDir + "Aspose.one");
                                                           Page page = document.FirstChild;           
                                                           Page previousPageVersion = document.GetPageHistory(page).Last();

                                                           document.RemoveChild(page);
                                                           document.AppendChildLast(previousPageVersion);

                                                           document.Save(dataDir + "RollBackRevisions_out.one");

显示如何编辑页面的历史。

// The path to the documents directory.
                                            string dataDir = RunExamples.GetDataDir_Pages();

                                            // Load OneNote document and get first child           
                                            Document document = new Document(dataDir + "Aspose.one");
                                            Page page = document.FirstChild;

                                            var pageHistory = document.GetPageHistory(page);

                                            pageHistory.RemoveRange(0, 1);

                                            pageHistory[0] = new Page(document);
                                            if (pageHistory.Count &gt; 1)
                                            {
                                                pageHistory[1].Title.TitleText.Text = "New Title";

                                                pageHistory.Add(new Page(document));

                                                pageHistory.Insert(1, new Page(document));

                                                document.Save(dataDir + "ModifyPageHistory_out.one");
                                            }

显示如何检查一页是否是一个冲突页面(即它有 OneNote 无法自动合并的变更)。

string dataDir = RunExamples.GetDataDir_Pages();

                                                                                                                          // Load OneNote document
                                                                                                                          Document doc = new Document(dataDir + "Aspose.one", new LoadOptions { LoadHistory = true });

                                                                                                                          var history = doc.GetPageHistory(doc.FirstChild);
                                                                                                                          for (int i = 0; i &lt; history.Count; i++)
                                                                                                                          {
                                                                                                                              var historyPage = history[i];
                                                                                                                              Console.Write("    {0}. Author: {1}, {2:dd.MM.yyyy hh.mm.ss}",
                                                                                                                                              i,
                                                                                                                                              historyPage.PageContentRevisionSummary.AuthorMostRecent,
                                                                                                                                              historyPage.PageContentRevisionSummary.LastModifiedTime);
                                                                                                                              Console.WriteLine(historyPage.IsConflictPage ? ", IsConflict: true" : string.Empty);

                                                                                                                              // By default conflict pages are just skipped on saving.
                                                                                                                              // If mark it as non-conflict then it will be saved as usual one in the history.
                                                                                                                              if (historyPage.IsConflictPage)
                                                                                                                                  historyPage.IsConflictPage = false;
                                                                                                                          }

                                                                                                                          doc.Save(dataDir + "ConflictPageManipulation_out.one", SaveFormat.One);

Import(流量,PdfImportOptions,Mergoptions)

从提供的 PDF 文档中进口一组页面。

public Document Import(Stream stream, PdfImportOptions importOptions = null, MergeOptions mergeOptions = null)

Parameters

stream Stream

一流与PDF文件。

importOptions PdfImportOptions

指定如何从 PDF 文档中导入页面的选项。

mergeOptions MergeOptions

指定如何合并提供的页面的选项。

Returns

Document

返回文档的参考。

Import(字符串, PdfImportOptions, Merge Options)

从提供的 PDF 文档中进口一组页面。

public Document Import(string file, PdfImportOptions importOptions = null, MergeOptions mergeOptions = null)

Parameters

file string

包含PDF文件的文件。

importOptions PdfImportOptions

指定如何从 PDF 文档中导入页面的选项。

mergeOptions MergeOptions

指定如何合并提供的页面的选项。

Returns

Document

返回文档的参考。

Examples

显示如何从一组PDF文档页面每页进口所有页面的方式。

string dataDir = RunExamples.GetDataDir_Import();

                                                                                  var d = new Document();

                                                                                  d.Import(Path.Combine(dataDir, "sampleText.pdf"))
                                                                                   .Import(Path.Combine(dataDir, "sampleImage.pdf"))
                                                                                   .Import(Path.Combine(dataDir, "sampleTable.pdf"));

                                                                                  d.Save(Path.Combine(dataDir, "sample_SimpleMerge.one"));

显示如何从一组PDF文件中导入所有页面,同时从每个PDF文档中输入页面的内容作为一个顶级 OneNote 页的孩子。

string dataDir = RunExamples.GetDataDir_Import();

                                                                                                                                                           var d = new Document();

                                                                                                                                                           foreach (var file in new[] { "sampleText.pdf", "sampleImage.pdf", "sampleTable.pdf" })
                                                                                                                                                           {
                                                                                                                                                               d.AppendChildLast(new Page()).Title = new Title() { TitleText = new RichText() { ParagraphStyle = ParagraphStyle.Default }.Append(file) };
                                                                                                                                                               d.Import(Path.Combine(dataDir, file), new PdfImportOptions(), new MergeOptions() { InsertAt = int.MaxValue, InsertAsChild = true });
                                                                                                                                                           }

                                                                                                                                                           d.Save(Path.Combine(dataDir, "sample_StructuredMerge.one"));

显示如何从一组PDF文件中导入所有内容,同时将每个PDF文档中的页面合并到 OneNote 单页。

string dataDir = RunExamples.GetDataDir_Import();

                                                                                                                                            var d = new Document();

                                                                                                                                            var importOptions = new PdfImportOptions();
                                                                                                                                            var mergeOptions = new MergeOptions() { ImportAsSinglePage = true, PageSpacing = 100 };

                                                                                                                                            d.Import(Path.Combine(dataDir, "sampleText.pdf"), importOptions, mergeOptions)
                                                                                                                                             .Import(Path.Combine(dataDir, "sampleImage.pdf"), importOptions, mergeOptions)
                                                                                                                                             .Import(Path.Combine(dataDir, "sampleTable.pdf"), importOptions, mergeOptions);

                                                                                                                                            d.Save(Path.Combine(dataDir, "sample_SinglePageMerge.one"));

Import(流量,HtmlImportOptions,Mergoptions)

从提供的 HTML 文档中导入一组页面。

public Document Import(Stream stream, HtmlImportOptions importOptions, MergeOptions mergeOptions = null)

Parameters

stream Stream

一流与HTML文档。

importOptions HtmlImportOptions

指定如何从 HTML 文档中导入页面的选项。

mergeOptions MergeOptions

指定如何合并提供的页面的选项。

Returns

Document

返回文档的参考。

Import(字符串,HtmlImportOptions,Mergoptions)

从提供的 HTML 文档中导入一组页面。

public Document Import(string file, HtmlImportOptions importOptions, MergeOptions mergeOptions = null)

Parameters

file string

包含HTML文件的文件。

importOptions HtmlImportOptions

指定如何从 HTML 文档中导入页面的选项。

mergeOptions MergeOptions

指定如何合并提供的页面的选项。

Returns

Document

返回文档的参考。

IsEncrypted(流, LoadOptions, Out 文档)

检查流中的文件是否被加密。要检查它,我们需要完全加载这份文件,所以这种方法可以导致性能罚款。

public static bool IsEncrypted(Stream stream, LoadOptions options, out Document document)

Parameters

stream Stream

流的。

options LoadOptions

负载选项。

document Document

加载的文件。

Returns

bool

返回真相,如果文件被加密,否则是虚假的。

Examples

显示如何检查文档是否受密码保护。

// The path to the documents directory.
                                                                  string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
                                                                  string fileName = Path.Combine(dataDir, "Aspose.one");

                                                                  Document document;
                                                                  if (!Document.IsEncrypted(fileName, out document))
                                                                  {
                                                                      Console.WriteLine("The document is loaded and ready to be processed.");
                                                                  }
                                                                  else
                                                                  {
                                                                      Console.WriteLine("The document is encrypted. Provide a password.");
                                                                  }

显示如何检查文档是否被特定密码保护。

// The path to the documents directory.
                                                                                       string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
                                                                                       string fileName = Path.Combine(dataDir, "Aspose.one");

                                                                                       Document document;
                                                                                       if (Document.IsEncrypted(fileName, "VerySecretPassword", out document))
                                                                                       {
                                                                                           if (document != null)
                                                                                           {
                                                                                               Console.WriteLine("The document is decrypted. It is loaded and ready to be processed.");
                                                                                           }
                                                                                           else
                                                                                           {
                                                                                               Console.WriteLine("The document is encrypted. Invalid password was provided.");
                                                                                           }
                                                                                       }
                                                                                       else
                                                                                       {
                                                                                           Console.WriteLine("The document is NOT encrypted. It is loaded and ready to be processed.");
                                                                                       }

IsEncrypted(流, string, out 文件)

检查流中的文件是否被加密。要检查它,我们需要完全加载这份文件,所以这种方法可以导致性能罚款。

public static bool IsEncrypted(Stream stream, string password, out Document document)

Parameters

stream Stream

流的。

password string

密码来解密文档。

document Document

加载的文件。

Returns

bool

返回真相,如果文件被加密,否则是虚假的。

Examples

显示如何检查文档是否受密码保护。

// The path to the documents directory.
                                                                  string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
                                                                  string fileName = Path.Combine(dataDir, "Aspose.one");

                                                                  Document document;
                                                                  if (!Document.IsEncrypted(fileName, out document))
                                                                  {
                                                                      Console.WriteLine("The document is loaded and ready to be processed.");
                                                                  }
                                                                  else
                                                                  {
                                                                      Console.WriteLine("The document is encrypted. Provide a password.");
                                                                  }

显示如何检查文档是否被特定密码保护。

// The path to the documents directory.
                                                                                       string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
                                                                                       string fileName = Path.Combine(dataDir, "Aspose.one");

                                                                                       Document document;
                                                                                       if (Document.IsEncrypted(fileName, "VerySecretPassword", out document))
                                                                                       {
                                                                                           if (document != null)
                                                                                           {
                                                                                               Console.WriteLine("The document is decrypted. It is loaded and ready to be processed.");
                                                                                           }
                                                                                           else
                                                                                           {
                                                                                               Console.WriteLine("The document is encrypted. Invalid password was provided.");
                                                                                           }
                                                                                       }
                                                                                       else
                                                                                       {
                                                                                           Console.WriteLine("The document is NOT encrypted. It is loaded and ready to be processed.");
                                                                                       }

IsEncrypted(流,出文档)

检查流中的文件是否被加密。要检查它,我们需要完全加载这份文件,所以这种方法可以导致性能罚款。

public static bool IsEncrypted(Stream stream, out Document document)

Parameters

stream Stream

流的。

document Document

加载的文件。

Returns

bool

返回真相,如果文件被加密,否则是虚假的。

Examples

显示如何检查文档是否受密码保护。

// The path to the documents directory.
                                                                  string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
                                                                  string fileName = Path.Combine(dataDir, "Aspose.one");

                                                                  Document document;
                                                                  if (!Document.IsEncrypted(fileName, out document))
                                                                  {
                                                                      Console.WriteLine("The document is loaded and ready to be processed.");
                                                                  }
                                                                  else
                                                                  {
                                                                      Console.WriteLine("The document is encrypted. Provide a password.");
                                                                  }

显示如何检查文档是否被特定密码保护。

// The path to the documents directory.
                                                                                       string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
                                                                                       string fileName = Path.Combine(dataDir, "Aspose.one");

                                                                                       Document document;
                                                                                       if (Document.IsEncrypted(fileName, "VerySecretPassword", out document))
                                                                                       {
                                                                                           if (document != null)
                                                                                           {
                                                                                               Console.WriteLine("The document is decrypted. It is loaded and ready to be processed.");
                                                                                           }
                                                                                           else
                                                                                           {
                                                                                               Console.WriteLine("The document is encrypted. Invalid password was provided.");
                                                                                           }
                                                                                       }
                                                                                       else
                                                                                       {
                                                                                           Console.WriteLine("The document is NOT encrypted. It is loaded and ready to be processed.");
                                                                                       }

IsEncrypted(字符串, LoadOptions, Out Document)

检查文件是否被加密。要检查它,我们需要完全加载这份文件,所以这种方法可以导致性能罚款。

public static bool IsEncrypted(string filePath, LoadOptions options, out Document document)

Parameters

filePath string

文件路径。

options LoadOptions

负载选项。

document Document

加载的文件。

Returns

bool

返回真相,如果文件被加密,否则是虚假的。

Examples

显示如何检查文档是否受密码保护。

// The path to the documents directory.
                                                                  string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
                                                                  string fileName = Path.Combine(dataDir, "Aspose.one");

                                                                  Document document;
                                                                  if (!Document.IsEncrypted(fileName, out document))
                                                                  {
                                                                      Console.WriteLine("The document is loaded and ready to be processed.");
                                                                  }
                                                                  else
                                                                  {
                                                                      Console.WriteLine("The document is encrypted. Provide a password.");
                                                                  }

显示如何检查文档是否被特定密码保护。

// The path to the documents directory.
                                                                                       string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
                                                                                       string fileName = Path.Combine(dataDir, "Aspose.one");

                                                                                       Document document;
                                                                                       if (Document.IsEncrypted(fileName, "VerySecretPassword", out document))
                                                                                       {
                                                                                           if (document != null)
                                                                                           {
                                                                                               Console.WriteLine("The document is decrypted. It is loaded and ready to be processed.");
                                                                                           }
                                                                                           else
                                                                                           {
                                                                                               Console.WriteLine("The document is encrypted. Invalid password was provided.");
                                                                                           }
                                                                                       }
                                                                                       else
                                                                                       {
                                                                                           Console.WriteLine("The document is NOT encrypted. It is loaded and ready to be processed.");
                                                                                       }

IsEncrypted(string, out 文件)

检查文件是否被加密。要检查它,我们需要完全加载这份文件,所以这种方法可以导致性能罚款。

public static bool IsEncrypted(string filePath, out Document document)

Parameters

filePath string

文件路径。

document Document

加载的文件。

Returns

bool

返回真相,如果文件被加密,否则是虚假的。

Examples

显示如何检查文档是否受密码保护。

// The path to the documents directory.
                                                                  string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
                                                                  string fileName = Path.Combine(dataDir, "Aspose.one");

                                                                  Document document;
                                                                  if (!Document.IsEncrypted(fileName, out document))
                                                                  {
                                                                      Console.WriteLine("The document is loaded and ready to be processed.");
                                                                  }
                                                                  else
                                                                  {
                                                                      Console.WriteLine("The document is encrypted. Provide a password.");
                                                                  }

显示如何检查文档是否被特定密码保护。

// The path to the documents directory.
                                                                                       string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
                                                                                       string fileName = Path.Combine(dataDir, "Aspose.one");

                                                                                       Document document;
                                                                                       if (Document.IsEncrypted(fileName, "VerySecretPassword", out document))
                                                                                       {
                                                                                           if (document != null)
                                                                                           {
                                                                                               Console.WriteLine("The document is decrypted. It is loaded and ready to be processed.");
                                                                                           }
                                                                                           else
                                                                                           {
                                                                                               Console.WriteLine("The document is encrypted. Invalid password was provided.");
                                                                                           }
                                                                                       }
                                                                                       else
                                                                                       {
                                                                                           Console.WriteLine("The document is NOT encrypted. It is loaded and ready to be processed.");
                                                                                       }

IsEncrypted(字符串, string, out 文件)

检查文件是否被加密。要检查它,我们需要完全加载这份文件,所以这种方法可以导致性能罚款。

public static bool IsEncrypted(string filePath, string password, out Document document)

Parameters

filePath string

文件路径。

password string

密码来解密文档。

document Document

加载的文件。

Returns

bool

返回真相,如果文件被加密,否则是虚假的。

Examples

显示如何检查文档是否受密码保护。

// The path to the documents directory.
                                                                  string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
                                                                  string fileName = Path.Combine(dataDir, "Aspose.one");

                                                                  Document document;
                                                                  if (!Document.IsEncrypted(fileName, out document))
                                                                  {
                                                                      Console.WriteLine("The document is loaded and ready to be processed.");
                                                                  }
                                                                  else
                                                                  {
                                                                      Console.WriteLine("The document is encrypted. Provide a password.");
                                                                  }

显示如何检查文档是否被特定密码保护。

// The path to the documents directory.
                                                                                       string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
                                                                                       string fileName = Path.Combine(dataDir, "Aspose.one");

                                                                                       Document document;
                                                                                       if (Document.IsEncrypted(fileName, "VerySecretPassword", out document))
                                                                                       {
                                                                                           if (document != null)
                                                                                           {
                                                                                               Console.WriteLine("The document is decrypted. It is loaded and ready to be processed.");
                                                                                           }
                                                                                           else
                                                                                           {
                                                                                               Console.WriteLine("The document is encrypted. Invalid password was provided.");
                                                                                           }
                                                                                       }
                                                                                       else
                                                                                       {
                                                                                           Console.WriteLine("The document is NOT encrypted. It is loaded and ready to be processed.");
                                                                                       }

Merge(无数>页面>, MergeOptions)

将一组页面转移到文件中。

public Document Merge(IEnumerable<page> pages, MergeOptions mergeOptions = null)

Parameters

pages IEnumerable < Page >

一组页面。

mergeOptions MergeOptions

指定如何合并提供的页面的选项。

Returns

Document

返回文档的参考。

Examples

显示如何从 PDF 文档组合每 5 页的所有页面进口到 OneNote 单页。

string dataDir = RunExamples.GetDataDir_Import();

                                                                                                           var d = new Document();

                                                                                                           var mergeOptions = new MergeOptions() { ImportAsSinglePage = true, PageSpacing = 100 };

                                                                                                           IEnumerable<page> pages = PdfImporter.Import(Path.Combine(dataDir, "SampleGrouping.pdf"));
                                                                                                           while (pages.Any())
                                                                                                           {
                                                                                                               d.Merge(pages.Take(5), mergeOptions);
                                                                                                               pages = pages.Skip(5);
                                                                                                           }

                                                                                                           d.Save(Path.Combine(dataDir, "sample_CustomMerge.one"));</page>

Print()

使用默认打印机打压文档。

public void Print()

Examples

显示如何将文档发送到打印机,使用默认的 Windows 对话与默定的选项。

// The path to the documents directory.
                                                                                                      string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                                                                      var document = new Aspose.Note.Document(dataDir + "Aspose.one");

                                                                                                      document.Print();

显示如何将文档发送到打印机,使用默认的 Windows 对话与指定的选项。

// The path to the documents directory.
                                                                                                        string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                                                                        var document = new Aspose.Note.Document(dataDir + "Aspose.one");

                                                                                                        var printerSettings = new PrinterSettings() { FromPage = 0, ToPage = 10 };
                                                                                                        printerSettings.DefaultPageSettings.Landscape = true;
                                                                                                        printerSettings.DefaultPageSettings.Margins = new System.Drawing.Printing.Margins(50, 50, 150, 50);

                                                                                                        document.Print(new PrintOptions()
                                                                                                                       {
                                                                                                                           PrinterSettings = printerSettings,
                                                                                                                           Resolution = 1200,
                                                                                                                           PageSplittingAlgorithm = new KeepSolidObjectsAlgorithm(),
                                                                                                                           DocumentName = "Test.one"
                                                                                                                       });

Print(PrintOptions)

使用默认打印机打压文档。

public void Print(PrintOptions options)

Parameters

options PrintOptions

用来打印文档的选项可以是零。

Save(线条)

将 OneNote 文档存储到文件中。

public void Save(string fileName)

Parameters

fileName string

文件的完整名称 如果已有指定的全名文件,则已存在的文件将被过写。

Examples

显示如何保存文件。

string inputFile = "Sample1.one";
                                        string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
                                        string outputFile = "SaveDocToOneNoteFormat_out.one";

                                        Document doc = new Document(dataDir + inputFile);
                                        doc.Save(dataDir + outputFile);

Exceptions

IncorrectDocumentStructureException

文件结构违反了规格。

UnsupportedSaveFormatException

请求保存格式不支持。

Save(Stream)

将 OneNote 文档存储到流。

public void Save(Stream stream)

Parameters

stream Stream

System.IO.Stream 将保存文件。

Exceptions

IncorrectDocumentStructureException

文件结构违反了规格。

UnsupportedSaveFormatException

请求保存格式不支持。

Save(字符串,SaveFormat)

将 OneNote 文档存储到指定格式的文件中。

public void Save(string fileName, SaveFormat format)

Parameters

fileName string

文件的完整名称 如果已有指定的全名文件,则已存在的文件将被过写。

format SaveFormat

保存文档的格式。

Examples

显示如何使用 SaveFormat 列表保存文档。

string inputFile = "Sample1.one";
                                                                     string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
                                                                     string outputFile = "SaveDocToOneNoteFormatUsingSaveFormat_out.one";

                                                                     Document document = new Document(dataDir + inputFile);

                                                                     document.Save(dataDir + outputFile, SaveFormat.One);

显示如何在GIF格式保存文档。

// The path to the documents directory.
                                                      string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                      // Load the document into Aspose.Note.
                                                      Document oneFile = new Document(dataDir + "Aspose.one");

                                                      dataDir = dataDir + "SaveToImageDefaultOptions_out.gif";

                                                      // Save the document as gif.
                                                      oneFile.Save(dataDir, SaveFormat.Gif);

Exceptions

IncorrectDocumentStructureException

文件结构违反了规格。

UnsupportedSaveFormatException

请求保存格式不支持。

Save(流量,SaveFormat)

将 OneNote 文档存储到指定的格式中的流。

public void Save(Stream stream, SaveFormat format)

Parameters

stream Stream

System.IO.Stream 将保存文件。

format SaveFormat

保存文档的格式。

Examples

显示如何使用默认设置保存文档的PDF格式。

// The path to the documents directory.
                                                                             string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                                             // Load the document into Aspose.Note.
                                                                             Document oneFile = new Document(dataDir + "Aspose.one");

                                                                             // Save the document as PDF
                                                                             dataDir = dataDir + "SaveWithDefaultSettings_out.pdf";
                                                                             oneFile.Save(dataDir, SaveFormat.Pdf);

显示如何将文件存储在流中。

// The path to the documents directory.
                                                    string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                    // Load the document into Aspose.Note.
                                                    Document doc = new Document(dataDir + "Aspose.one");

                                                    MemoryStream dstStream = new MemoryStream();
                                                    doc.Save(dstStream, SaveFormat.Pdf);

                                                    // Rewind the stream position back to zero so it is ready for next reader.
                                                    dstStream.Seek(0, SeekOrigin.Begin);

显示如何将黑暗主题风格应用到文档。

// The path to the documents directory.
                                                             string dataDir = RunExamples.GetDataDir_Text();

                                                             // Load the document into Aspose.Note.
                                                             Document doc = new Document(Path.Combine(dataDir, "Aspose.one"));

                                                             foreach (var page in doc)
                                                             {
                                                                 page.BackgroundColor = Color.Black;
                                                             }

                                                             foreach (var node in doc.GetChildNodes<richtext>())
                                                             {
                                                                 var c = node.ParagraphStyle.FontColor;
                                                                 if (c.IsEmpty || Math.Abs(c.R - Color.Black.R) + Math.Abs(c.G - Color.Black.G) + Math.Abs(c.B - Color.Black.B) &lt;= 30)
                                                                 {
                                                                     node.ParagraphStyle.FontColor = Color.White;
                                                                 }
                                                             }

                                                             doc.Save(Path.Combine(dataDir, "AsposeDarkTheme.pdf"));</richtext>

Exceptions

IncorrectDocumentStructureException

文件结构违反了规格。

UnsupportedSaveFormatException

请求保存格式不支持。

Save(字符串,SaveOptions)

将 OneNote 文档保存到文件中,使用所指定的保存选项。

public void Save(string fileName, SaveOptions options)

Parameters

fileName string

文件的完整名称 如果已有指定的全名文件,则已存在的文件将被过写。

options SaveOptions

指定文件存储方式的选项。

Examples

显示如何使用 OneSaveOptions 保存文档。

string inputFile = "Sample1.one";
                                                             string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
                                                             string outputFile = "SaveDocToOneNoteFormatUsingOneSaveOptions_out.one";

                                                             Document document = new Document(dataDir + inputFile);

                                                             document.Save(dataDir + outputFile, new OneSaveOptions());

显示如何保存文档作为图像在Jpeg格式使用SaveFormat。

// The path to the documents directory.
                                                                                 string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                                                 // Load the document into Aspose.Note.
                                                                                 Document oneFile = new Document(dataDir + "Aspose.one");

                                                                                 dataDir = dataDir + "SaveToJpegImageUsingSaveFormat_out.jpg";

                                                                                 // Save the document.
                                                                                 oneFile.Save(dataDir, SaveFormat.Jpeg);

显示如何使用 ImageSaveOptions 在 Bmp 格式中保存文档作为图像。

// The path to the documents directory.
                                                                                      string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                                                      // Load the document into Aspose.Note.
                                                                                      Document oneFile = new Document(dataDir + "Aspose.one");

                                                                                      dataDir = dataDir + "SaveToBmpImageUsingImageSaveOptions_out.bmp";

                                                                                      // Save the document.
                                                                                      oneFile.Save(dataDir, new ImageSaveOptions(SaveFormat.Bmp));

显示如何保存文档的PDF格式与信页布局。

// The path to the documents directory.
                                                                              string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                                              // Load the document into Aspose.Note.
                                                                              Document oneFile = new Document(dataDir + "OneNote.one");

                                                                              var dst = Path.Combine(dataDir, "SaveToPdfUsingLetterPageSettings.pdf");

                                                                              // Save the document.
                                                                              oneFile.Save(dst, new PdfSaveOptions() { PageSettings = PageSettings.Letter });

显示如何保存文档的PDF格式与A4页面布局没有高度限制。

// The path to the documents directory.
                                                                                               string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                                                               // Load the document into Aspose.Note.
                                                                                               Document oneFile = new Document(dataDir + "OneNote.one");

                                                                                               var dst = Path.Combine(dataDir, "SaveToPdfUsingA4PageSettingsWithoutHeightLimit.pdf");

                                                                                               // Save the document.
                                                                                               oneFile.Save(dst, new PdfSaveOptions() { PageSettings = PageSettings.A4NoHeightLimit });

显示如何保存文档作为灰色图像。

// The path to the documents directory.
                                                           string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                           // Load the document into Aspose.Note.
                                                           Document oneFile = new Document(dataDir + "Aspose.one");

                                                           dataDir = dataDir + "SaveAsGrayscaleImage_out.png";

                                                           // Save the document as gif.
                                                           oneFile.Save(dataDir, new ImageSaveOptions(SaveFormat.Png)
                                                                                     {
                                                                                         ColorMode = ColorMode.GrayScale
                                                                                     });

显示如何保存文档作为图像在 Tiff 格式使用 PackBits 压缩。

// The path to the documents directory.
                                                                                           string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                                                           // Load the document into Aspose.Note.
                                                                                           Document oneFile = new Document(Path.Combine(dataDir, "Aspose.one"));

                                                                                           var dst = Path.Combine(dataDir, "SaveToTiffUsingPackBitsCompression.tiff");

                                                                                           // Save the document.
                                                                                           oneFile.Save(dst, new ImageSaveOptions(SaveFormat.Tiff)
                                                                                                                 {
                                                                                                                     TiffCompression = TiffCompression.PackBits
                                                                                                                 });

显示如何保存文档作为图像在 Tiff 格式使用 Jpeg 压缩。

// The path to the documents directory.
                                                                                       string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                                                       // Load the document into Aspose.Note.
                                                                                       Document oneFile = new Document(Path.Combine(dataDir, "Aspose.one"));

                                                                                       var dst = Path.Combine(dataDir, "SaveToTiffUsingJpegCompression.tiff");

                                                                                       // Save the document.
                                                                                       oneFile.Save(dst, new ImageSaveOptions(SaveFormat.Tiff)
                                                                                                             {
                                                                                                                 TiffCompression = TiffCompression.Jpeg,
                                                                                                                 Quality = 93
                                                                                                             });

显示如何使用 CCITT Group 3 传真压缩保存文档作为图像的 Tiff 格式。

// The path to the documents directory.
                                                                                                    string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                                                                    // Load the document into Aspose.Note.
                                                                                                    Document oneFile = new Document(Path.Combine(dataDir, "Aspose.one"));

                                                                                                    var dst = Path.Combine(dataDir, "SaveToTiffUsingCcitt3Compression.tiff");

                                                                                                    // Save the document.
                                                                                                    oneFile.Save(dst, new ImageSaveOptions(SaveFormat.Tiff)
                                                                                                                          {
                                                                                                                              ColorMode = ColorMode.BlackAndWhite,
                                                                                                                              TiffCompression = TiffCompression.Ccitt3
                                                                                                                          });

显示如何在PDF格式保存文档。

// The path to the documents directory.
                                                      string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                      // Load the document into Aspose.Note.
                                                      Document oneFile = new Document(dataDir + "Aspose.one");

                                                      // Initialize PdfSaveOptions object
                                                      PdfSaveOptions opts = new PdfSaveOptions
                                                                                {
                                                                                    // Set page index of first page to be saved
                                                                                    PageIndex = 0,

                                                                                    // Set page count
                                                                                    PageCount = 1,
                                                                                };

                                                      // Save the document as PDF
                                                      dataDir = dataDir + "SaveRangeOfPagesAsPDF_out.pdf";
                                                      oneFile.Save(dataDir, opts);

显示如何使用特定设置保存文档的PDF格式。

// The path to the documents directory.
                                                                              string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                                              // Load the document into Aspose.Note.
                                                                              Document doc = new Document(dataDir + "Aspose.one");

                                                                              // Initialize PdfSaveOptions object
                                                                              PdfSaveOptions opts = new PdfSaveOptions
                                                                                                        {
                                                                                                            // Use Jpeg compression
                                                                                                            ImageCompression = Saving.Pdf.PdfImageCompression.Jpeg,

                                                                                                            // Quality for JPEG compression
                                                                                                            JpegQuality = 90
                                                                                                        };

                                                                              dataDir = dataDir + "Document.SaveWithOptions_out.pdf";
                                                                              doc.Save(dataDir, opts);

显示如何使用 Otsu 方法保存文档作为二进制图像。

// The path to the documents directory.
                                                                            string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                                            // Load the document into Aspose.Note.
                                                                            Document oneFile = new Document(dataDir + "Aspose.one");

                                                                            dataDir = dataDir + "SaveToBinaryImageUsingOtsuMethod_out.png";

                                                                            // Save the document as gif.
                                                                            oneFile.Save(dataDir, new ImageSaveOptions(SaveFormat.Png)
                                                                                                    {
                                                                                                        ColorMode = ColorMode.BlackAndWhite,
                                                                                                        BinarizationOptions = new ImageBinarizationOptions()
                                                                                                                              {
                                                                                                                                  BinarizationMethod = BinarizationMethod.Otsu,
                                                                                                                              }
                                                                                                    });

显示如何使用固定边界保存文档作为二进制图像。

// The path to the documents directory.
                                                                              string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                                              // Load the document into Aspose.Note.
                                                                              Document oneFile = new Document(dataDir + "Aspose.one");

                                                                              dataDir = dataDir + "SaveToBinaryImageUsingFixedThreshold_out.png";

                                                                              // Save the document as gif.
                                                                              oneFile.Save(dataDir, new ImageSaveOptions(SaveFormat.Png)
                                                                                                        {
                                                                                                            ColorMode = ColorMode.BlackAndWhite,
                                                                                                            BinarizationOptions = new ImageBinarizationOptions()
                                                                                                                                      {
                                                                                                                                          BinarizationMethod = BinarizationMethod.FixedThreshold,
                                                                                                                                          BinarizationThreshold = 123
                                                                                                                                      }
                                                                                                        });

Exceptions

IncorrectDocumentStructureException

文件结构违反了规格。

UnsupportedSaveFormatException

请求保存格式不支持。

Save(流量,SaveOptions)

将 OneNote 文档存储到一个流,使用所指定的保存选项。

public void Save(Stream stream, SaveOptions options)

Parameters

stream Stream

System.IO.Stream 将保存文件。

options SaveOptions

指定如何存储文档的选项。

Examples

显示如何保存文档在PDF格式使用指定的默认字体。

// The path to the documents directory.
                                                                                   string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                                                   // Load the document into Aspose.Note.
                                                                                   Document oneFile = new Document(Path.Combine(dataDir, "missing-font.one"));

                                                                                   // Save the document as PDF
                                                                                   dataDir = dataDir + "SaveUsingDocumentFontsSubsystemWithDefaultFontName_out.pdf";
                                                                                   oneFile.Save(dataDir, new PdfSaveOptions() 
                                                                                                         {
                                                                                                             FontsSubsystem = DocumentFontsSubsystem.UsingDefaultFont("Times New Roman")
                                                                                                         });

显示如何从文件中保存文档的PDF格式使用默认字体。

// The path to the documents directory.
                                                                                     string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                                                     string fontFile = Path.Combine(dataDir, "geo_1.ttf");

                                                                                     // Load the document into Aspose.Note.
                                                                                     Document oneFile = new Document(Path.Combine(dataDir, "missing-font.one"));

                                                                                     // Save the document as PDF
                                                                                     dataDir = dataDir + "SaveUsingDocumentFontsSubsystemWithDefaultFontFromFile_out.pdf";
                                                                                     oneFile.Save(dataDir, new PdfSaveOptions()
                                                                                                               {
                                                                                                                   FontsSubsystem = DocumentFontsSubsystem.UsingDefaultFontFromFile(fontFile)
                                                                                                               });

显示如何保存文档在PDF格式使用默认字体从流。

// The path to the documents directory.
                                                                                       string dataDir = RunExamples.GetDataDir_LoadingAndSaving();

                                                                                       string fontFile = Path.Combine(dataDir, "geo_1.ttf");

                                                                                       // Load the document into Aspose.Note.
                                                                                       Document oneFile = new Document(Path.Combine(dataDir, "missing-font.one"));

                                                                                       // Save the document as PDF
                                                                                       dataDir = dataDir + "SaveUsingDocumentFontsSubsystemWithDefaultFontFromStream_out.pdf";

                                                                                       using (var stream = File.Open(fontFile, FileMode.Open, FileAccess.Read, FileShare.Read))
                                                                                       {
                                                                                           oneFile.Save(dataDir, new PdfSaveOptions()
                                                                                                                     {
                                                                                                                         FontsSubsystem = DocumentFontsSubsystem.UsingDefaultFontFromStream(stream)
                                                                                                                     });
                                                                                       }

Exceptions

IncorrectDocumentStructureException

文件结构违反了规格。

UnsupportedSaveFormatException

请求保存格式不支持。

 中文