Class Document
Il nome: Aspose.Note Assemblea: Aspose.Note.dll (25.4.0)
Si tratta di un documento Aspose.Note.
public class Document : CompositeNode<Page>, INode, ICompositeNode<Page>, ICompositeNode, IEnumerable<Page>, IEnumerable, INotebookChildNode
{
}
Inheritance
object
←
Node
←
CompositeNodeBase
←
CompositeNode
Implements
INode
,
ICompositeNode
I membri ereditari
CompositeNode
Examples
Mostra come inviare un documento a una stampante utilizzando il dialogo Windows standard con le opzioni predefinite.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
var document = new Aspose.Note.Document(dataDir + "Aspose.one");
document.Print();
Mostra come salvare un documento.
string inputFile = "Sample1.one";
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
string outputFile = "SaveDocToOneNoteFormat_out.one";
Document doc = new Document(dataDir + inputFile);
doc.Save(dataDir + outputFile);
Mostra come fare un documento crittografato.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
LoadOptions loadOptions = new LoadOptions { DocumentPassword = "password" };
Document doc = new Document(dataDir + "Sample1.one", loadOptions);
Mostra come salvare il documento con la crittografia.
string dataDir = RunExamples.GetDataDir_NoteBook();
Document document = new Document();
document.Save(dataDir + "CreatingPasswordProtectedDoc_out.one", new OneSaveOptions { DocumentPassword = "pass" });
Mostra come salvare un documento utilizzando l’elenco 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);
Mostra come salvare un documento utilizzando 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());
Mostra come ottenere il conteggio della pagina di un documento.
string dataDir = RunExamples.GetDataDir_Pages();
Document oneFile = new Document(dataDir + "Aspose.one");
int count = oneFile.Count();
Console.WriteLine(count);
Mostra come salvare un documento in formato pdf utilizzando le impostazioni predefinite.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document oneFile = new Document(dataDir + "Aspose.one");
dataDir += "SaveWithDefaultSettings_out.pdf";
oneFile.Save(dataDir, SaveFormat.Pdf);
Mostra come salvare un documento in formato gif.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document oneFile = new Document(dataDir + "Aspose.one");
dataDir += "SaveToImageDefaultOptions_out.gif";
oneFile.Save(dataDir, SaveFormat.Gif);
Mostra come impostare la qualità dell’immagine quando si salva il documento come immagine in formato JPEG.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document doc = new Document(dataDir + "Aspose.one");
dataDir = dataDir + "SetOutputImageResolution_out.jpg";
doc.Save(dataDir, new ImageSaveOptions(SaveFormat.Jpeg) { Quality = 100 });
Mostra come impostare una risoluzione dell’immagine quando si salva il documento come immagine.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document doc = new Document(dataDir + "Aspose.one");
int resolution = 220;
dataDir = dataDir + "SetOutputImageResolution_out.jpg";
doc.Save(dataDir, new ImageSaveOptions(SaveFormat.Jpeg) { Resolution = resolution });
Mostra come ottenere il formato di file di un documento.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
var document = new Aspose.Note.Document(dataDir + "Aspose.one");
switch (document.FileFormat)
{
case FileFormat.OneNote2010:
break;
case FileFormat.OneNoteOnline:
break;
}
Mostra come collegare un collegamento ad un’immagine.
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");
Mostra come salvare un documento in un flusso.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document doc = new Document(dataDir + "Aspose.one");
MemoryStream dstStream = new MemoryStream();
doc.Save(dstStream, SaveFormat.Pdf);
dstStream.Seek(0, SeekOrigin.Begin);
Mostra come verificare se un documento è protetto dalla password.
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.");
}
Mostra come aggiungere una nuova sezione a un notebook.
string dataDir = RunExamples.GetDataDir_NoteBook();
var notebook = new Notebook(dataDir + "Notizbuch Öffnen.onetoc2");
notebook.AppendChild(new Document(dataDir + "Neuer Abschnitt 1.one"));
dataDir += @"\AddChildNode_out.onetoc2";
notebook.Save(dataDir);
Mostra come verificare se un carico di documento fallisce perché il formato OneNote 2007 non è supportato.
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;
}
}
Mostra come ripristinare la versione precedente di una pagina.
string dataDir = RunExamples.GetDataDir_Pages();
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");
Come clonare una pagina.
string dataDir = RunExamples.GetDataDir_Pages();
Document document = new Document(dataDir + "Aspose.one", new LoadOptions { LoadHistory = true });
var cloned = new Document();
cloned.AppendChildLast(document.FirstChild.Clone());
cloned = new Document();
cloned.AppendChildLast(document.FirstChild.Clone(true));
Mostra come salvare un documento in formato html memorizzando tutte le risorse (css/fonti/immagini) in un file separato.
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);
Mostra come salvare un documento in un flusso in formato html con l’integrazione di tutte le risorse (css/fonti/immagini).
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);
Mostra come impostare la descrizione del testo per un’immagine.
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 += "ImageAlternativeText_out.one";
document.Save(dataDir);
Mostra come ottenere meta informazioni su una pagina.
string dataDir = RunExamples.GetDataDir_Pages();
Aspose.Words.Document oneFile = new Aspose.Words.Document(dataDir + "Aspose.one");
foreach (Aspose.Words.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();
}
Quando le lunghe pagine di OneNote vengono memorizzate in formato pdf, vengono suddivise su pagina.Il campione mostra come configurare la logica di divisione degli oggetti che si trovano sulle interruzioni del sito.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document doc = new Document(dataDir + "Aspose.one");
var pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.PageSplittingAlgorithm = new KeepPartAndCloneSolidObjectToNextPageAlgorithm(100);
pdfSaveOptions.PageSplittingAlgorithm = new KeepPartAndCloneSolidObjectToNextPageAlgorithm(400);
dataDir = dataDir + "PageSplittUsingKeepPartAndCloneSolidObjectToNextPageAlgorithm_out.pdf";
doc.Save(dataDir, pdfSaveOptions);
Mostra come salvare un documento in formato png.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document oneFile = new Document(dataDir + "Aspose.one");
ImageSaveOptions opts = new ImageSaveOptions(SaveFormat.Png)
{
PageIndex = 1
};
dataDir += "ConvertSpecificPageToImage_out.png";
oneFile.Save(dataDir, opts);
Mostra come modificare la storia della pagina.
string dataDir = RunExamples.GetDataDir_Pages();
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 > 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");
}
Mostra come verificare se un documento è protetto da una password specifica.
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.");
}
Mostra come applicare lo stile tema oscuro a un documento.
string dataDir = RunExamples.GetDataDir_Text();
Document doc = new Document(Path.Combine(dataDir, "Aspose.one"));
foreach (var page in doc)
{
page.BackgroundColor = Color.Black;
}
foreach (var node in doc.GetChildNodes<Aspose.Words.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) <= 30)
{
node.ParagraphStyle.FontColor = Color.White;
}
}
doc.Save(Path.Combine(dataDir, "AsposeDarkTheme.pdf"));
Mostra come passare attraverso il contenuto di un notebook.
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)
{
}
else if (notebookChildNode is Notebook)
{
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Mostra come ottenere un’immagine da un documento.
string dataDir = RunExamples.GetDataDir_Images();
Document oneFile = new Document(dataDir + "Aspose.one");
IList<aspose.note.Image> nodes = oneFile.GetChildNodes<aspose.note.Image>();
foreach (var image in nodes)
{
using (MemoryStream stream = new MemoryStream(image.Bytes))
{
using (Bitmap bitMap = new Bitmap(stream))
{
bitMap.Save(Path.Combine(dataDir, Path.GetFileName(image.FileName)));
}
}
}
Mostra come salvare un documento in formato pdf.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document oneFile = new Document(dataDir + "Aspose.one");
PdfSaveOptions opts = new PdfSaveOptions()
{
PageIndex = 0,
PageCount = 1,
};
dataDir += "SaveRangeOfPagesAsPDF_out.pdf";
oneFile.Save(dataDir, opts);
Mostra come salvare un documento in formato pdf utilizzando impostazioni specifiche.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document doc = new Document(dataDir + "Aspose.one");
PdfSaveOptions opts = new PdfSaveOptions()
{
ImageCompression = Saving.Pdf.PdfImageCompression.Jpeg,
JpegQuality = 90
};
dataDir += "Document.SaveWithOptions_out.pdf";
doc.Save(dataDir, opts);
Mostra come inviare un documento a una stampante utilizzando il dialogo Windows standard con le opzioni specificate.
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"
});
Mostra come ottenere il contenuto di un file allegato.
string dataDir = RunExamples.GetDataDir_Attachments();
Document oneFile = new Document(dataDir + "Sample1.one");
IList<attachedfile> nodes = oneFile.GetChildNodes<attachedfile>();
foreach (AttachedFile file in nodes)
{
using (Stream outputStream = new MemoryStream(file.Bytes))
{
using (System.IO.FileStream fileStream = System.IO.File.OpenWrite(String.Format(dataDir + file.FileName)))
{
CopyStream(outputStream, fileStream);
}
}
}
Mostra come ottenere le informazioni meta dell’immagine.
string dataDir = RunExamples.GetDataDir_Images();
Document oneFile = new Document(dataDir + "Aspose.one");
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();
}
Mostra come ottenere la storia della pagina.
string dataDir = RunExamples.GetDataDir_Pages();
Document document = new Document(dataDir + "Aspose.one", new LoadOptions { LoadHistory = true });
Page firstPage = document.FirstChild;
foreach (Page pageRevision in document.GetPageHistory(firstPage))
{
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();
}
Mostra come aggiungere un file a un documento utilizzando il filepath.
string dataDir = RunExamples.GetDataDir_Attachments();
Document doc = new Document();
Aspose.Note.Page page = new Aspose.Note.Page(doc);
Outline outline = new Outline(doc);
OutlineElement outlineElem = new OutlineElement(doc);
AttachedFile attachedFile = new AttachedFile(doc, dataDir + "attachment.txt");
outlineElem.AppendChildLast(attachedFile);
outline.AppendChildLast(outlineElem);
page.AppendChildLast(outline);
doc.AppendChildLast(page);
dataDir += "AttachFileByPath_out.one";
doc.Save(dataDir);
Mostra come creare un documento e salvarlo in formato html utilizzando le opzioni predefinite.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document doc = new Document();
Page page = doc.AppendChildLast(new Page());
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 }
};
dataDir = dataDir + "CreateOneNoteDocAndSaveToHTML_out.html";
doc.Save(dataDir);
Visualizza come verificare se una pagina è una page di conflitto (cioè ha cambiamenti che OneNote non poteva automaticamente fusione).
string dataDir = RunExamples.GetDataDir_Pages();
Document doc = new Document(dataDir + "Aspose.one", new LoadOptions { LoadHistory = true });
var history = doc.GetPageHistory(doc.FirstChild);
for (int i = 0; i < 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);
if (historyPage.IsConflictPage)
historyPage.IsConflictPage = false;
}
doc.Save(dataDir + "ConflictPageManipulation_out.one", SaveFormat.One);
Mostra come aggiungere un’immagine dal file a un documento con proprietà definite dall’utente.
string dataDir = RunExamples.GetDataDir_Images();
Document doc = new Document(dataDir + "Aspose.one");
Aspose.Note.Page page = doc.FirstChild;
Aspose.Note.Image image = new Aspose.Note.Image(doc, dataDir + "image.jpg")
{
Width = 100,
Height = 100,
HorizontalOffset = 100,
VerticalOffset = 400,
Alignment = HorizontalAlignment.Right
};
page.AppendChildLast(image);
Mostra come aggiungere un file da un flusso a un documento.
string dataDir = RunExamples.GetDataDir_Attachments();
Document doc = new Document();
Aspose.Note.Page page = new Aspose.Note.Page(doc);
Outline outline = new Outline(doc);
OutlineElement outlineElem = new OutlineElement(doc);
using (var stream = File.OpenRead(dataDir + "icon.jpg"))
{
AttachedFile attachedFile = new AttachedFile(doc, dataDir + "attachment.txt", stream, ImageFormat.Jpeg);
outlineElem.AppendChildLast(attachedFile);
}
outline.AppendChildLast(outlineElem);
page.AppendChildLast(outline);
doc.AppendChildLast(page);
dataDir += "AttachFileAndSetIcon_out.one";
doc.Save(dataDir);
Quando le lunghe pagine di OneNote vengono memorizzate in formato pdf, vengono suddivise su pagina.L’esempio mostra come configurare la logica di suddizione degli oggetti situati sulle interruzioni della Pagina.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document doc = new Document(dataDir + "Aspose.one");
var pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.PageSplittingAlgorithm = new AlwaysSplitObjectsAlgorithm();
pdfSaveOptions.PageSplittingAlgorithm = new KeepPartAndCloneSolidObjectToNextPageAlgorithm();
pdfSaveOptions.PageSplittingAlgorithm = new KeepSolidObjectsAlgorithm();
float heightLimitOfClonedPart = 500;
pdfSaveOptions.PageSplittingAlgorithm = new KeepPartAndCloneSolidObjectToNextPageAlgorithm(heightLimitOfClonedPart);
pdfSaveOptions.PageSplittingAlgorithm = new KeepSolidObjectsAlgorithm(heightLimitOfClonedPart);
pdfSaveOptions.PageSplittingAlgorithm = new KeepSolidObjectsAlgorithm(100);
pdfSaveOptions.PageSplittingAlgorithm = new KeepSolidObjectsAlgorithm(400);
dataDir = dataDir + "UsingKeepSOlidObjectsAlgorithm_out.pdf";
doc.Save(dataDir, pdfSaveOptions);
Mostra come creare un documento e salvare in formato html una gamma specifica di pagine.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document doc = new Document();
Page page = doc.AppendChildLast(new Page());
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
}
};
dataDir = dataDir + "CreateAndSavePageRange_out.html";
doc.Save(dataDir, new HtmlSaveOptions
{
PageCount = 1,
PageIndex = 0
});
Mostra come creare un documento con una pagina titolare.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Aspose.Note.Document doc = new Aspose.Note.Document();
Aspose.Note.Page page = new Aspose.Note.Page(doc);
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 }
};
doc.AppendChildLast(page);
dataDir += "CreateDocWithPageTitle_out.one";
doc.Save(dataDir);
Mostra come aggiungere un’immagine dal flusso a un documento.
string dataDir = RunExamples.GetDataDir_Images();
Document doc = new Document();
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"))
{
Aspose.Note.Image image1 = new Aspose.Note.Image(doc, "Penguins.jpg", fs)
{
Alignment = HorizontalAlignment.Right
};
outlineElem1.AppendChildLast(image1);
}
outline1.AppendChildLast(outlineElem1);
page.AppendChildLast(outline1);
doc.AppendChildLast(page);
dataDir = dataDir + "BuildDocAndInsertImageUsingImageStream_out.one";
doc.Save(dataDir);
Mostra come aggiungere un’immagine dal file a un documento.
string dataDir = RunExamples.GetDataDir_Images();
Document doc = new Document();
Aspose.Note.Page page = new Aspose.Note.Page(doc);
Outline outline = new Outline(doc);
OutlineElement outlineElem = new OutlineElement(doc);
Aspose.Note.Image image = new Aspose.Note.Image(doc, dataDir + "image.jpg")
{
Alignment = HorizontalAlignment.Right
};
outlineElem.AppendChildLast(image);
outline.AppendChildLast(outlineElem);
page.AppendChildLast(outline);
doc.AppendChildLast(page);
dataDir = dataDir + "BuildDocAndInsertImage_out.one";
doc.Save(dataDir);
Mostra come creare un documento con un testo.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document doc = new Document();
Page page = new Page(doc);
Outline outline = new Outline(doc);
OutlineElement outlineElem = new OutlineElement(doc);
ParagraphStyle textStyle = new ParagraphStyle
{
FontColor = Color.Black,
FontName = "Arial",
FontSize = 10
};
RichText text = new RichText(doc)
{
Text = "Hello OneNote text!",
ParagraphStyle = textStyle
};
outlineElem.AppendChildLast(text);
outline.AppendChildLast(outlineElem);
page.AppendChildLast(outline);
doc.AppendChildLast(page);
dataDir += "CreateDocWithSimpleRichText_out.one";
doc.Save(dataDir);
Mostra come salvare un documento in diversi formati.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document doc = new Document() { AutomaticLayoutChangesDetectionEnabled = false };
Aspose.Note.Page page = new Aspose.Note.Page(doc);
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 }
};
doc.AppendChildLast(page);
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");
Mostra come salvare un documento in formato html con il salvataggio di tutte le risorse (css/fonti/immagini) utilizzando callbacks definiti dall’utente.
using System.IO;
using Aspose.Words;
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 */");
}
Mostra come collegare un collegamento a un testo.
string dataDir = RunExamples.GetDataDir_Tasks();
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()
.Append("This is ", textStyleRed)
.Append("hyperlink", textStyleHyperlink)
.Append(". This text is not a hyperlink.", TextStyle.Default);
OutlineElement outlineElem = new OutlineElement();
outlineElem.AppendChildLast(text);
outline.AppendChildLast(outlineElem);
Title title = new Title() { TitleText = titleText };
Page page = new Note.Page() { Title = title };
page.AppendChildLast(outline);
doc.AppendChildLast(page);
dataDir = dataDir + "AddHyperlink_out.one";
doc.Save(dataDir);
Mostra come accedere al contenuto di un documento utilizzando il visitatore.
public static void Run()
{
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document doc = new Document(dataDir + "Aspose.one");
MyOneNoteToTxtWriter myConverter = new MyOneNoteToTxtWriter();
doc.Accept(myConverter);
Console.WriteLine(myConverter.GetText());
Console.WriteLine(myConverter.NodeCount);
}
public class MyOneNoteToTxtWriter : DocumentVisitor
{
public MyOneNoteToTxtWriter()
{
NodeCount = 0;
IsSkipText = false;
Builder = new StringBuilder();
}
public string GetText()
{
return Builder.ToString();
}
private void AppendText(string text)
{
if (!IsSkipText)
{
Builder.AppendLine(text);
}
}
public override void VisitRichTextStart(RichText run)
{
++NodeCount;
AppendText(run.Text);
}
public override void VisitDocumentStart(Document document)
{
++NodeCount;
}
public override void VisitPageStart(Page page)
{
++NodeCount;
AppendText($"*** Page '{page.Title?.TitleText?.Text ?? "(no title)"}' ***");
}
public override void VisitPageEnd(Page page)
{
AppendText(string.Empty);
}
public override void VisitTitleStart(Title title)
{
++NodeCount;
}
public override void VisitImageStart(Image image)
{
++NodeCount;
}
public override void VisitOutlineGroupStart(OutlineGroup outlineGroup)
{
++NodeCount;
}
public override void VisitOutlineStart(Outline outline)
{
++NodeCount;
}
public override void VisitOutlineElementStart(OutlineElement outlineElement)
{
++NodeCount;
}
public Int32 NodeCount
{
get { return this.nodeCount; }
}
private readonly StringBuilder Builder;
private bool IsSkipText;
private int nodeCount;
}
Constructors
Il documento ( )
Inizia una nuova instanza della classe Aspose.Note.Document.Crea un documento OneNote bianco.
public Document()
{
}
Il testo (string )
Inizia una nuova instanza della classe Aspose.Note.Document.Apri un documento OneNote esistente da un file.
public Document(string filePath)
{
}
Parameters
filePath
string
Il percorso del file.
Exceptions
UnsupportedFileFormatException
Il formato del documento non è riconosciuto o supportato.
Il documento sembra essere corrotto e non può essere caricato.
Il documento è crittografato e richiede una password per aprire, ma hai fornito una password sbagliata.
C’è un problema con il documento e dovrebbe essere segnalato ai sviluppatori Aspose.Note.
C’è un’eccezione di input/output.
Documento (string, LoadOptions)
Inizia una nuova instanza della classe Aspose.Note.Document.Apri un documento OneNote esistente da un file. consente di specificare ulteriori opzioni come una password di crittografia.
public Document(string filePath, LoadOptions loadOptions)
{
}
Parameters
filePath
string
Il percorso del file.
loadOptions
LoadOptions
Le opzioni utilizzate per caricare un documento. può essere zero.
Exceptions
UnsupportedFileFormatException
Il formato del documento non è riconosciuto o supportato.
Il documento sembra essere corrotto e non può essere caricato.
Il documento è crittografato e richiede una password per aprire, ma hai fornito una password sbagliata.
C’è un problema con il documento e dovrebbe essere segnalato ai sviluppatori Aspose.Note.
C’è un’eccezione di input/output.
Il messaggio (Stream)
Inizia una nuova instanza della classe Aspose.Note.Document.Apri un documento OneNote esistente da un flusso.
public Document(Stream inStream)
{
}
Parameters
inStream
Stream
Il flusso .
Exceptions
UnsupportedFileFormatException
Il formato del documento non è riconosciuto o supportato.
Il documento sembra essere corrotto e non può essere caricato.
Il documento è crittografato e richiede una password per aprire, ma hai fornito una password sbagliata.
C’è un problema con il documento e dovrebbe essere segnalato ai sviluppatori Aspose.Note.
C’è un’eccezione di input/output.
Il flusso non supporta la lettura, è zero o è già chiuso.
Documentazione (Stream, LoadOptions)
Inizia una nuova instanza della classe Aspose.Note.Document.Apri un documento OneNote esistente da un flusso. consente di specificare ulteriori opzioni come una password di crittografia.
public Document(Stream inStream, LoadOptions loadOptions)
{
}
Parameters
inStream
Stream
Il flusso .
loadOptions
LoadOptions
Le opzioni utilizzate per caricare un documento. può essere zero.
Exceptions
UnsupportedFileFormatException
Il formato del documento non è riconosciuto o supportato.
Il documento sembra essere corrotto e non può essere caricato.
Il documento è crittografato e richiede una password per aprire, ma hai fornito una password sbagliata.
C’è un problema con il documento e dovrebbe essere segnalato ai sviluppatori Aspose.Note.
C’è un’eccezione di input/output.
Il flusso non supporta la lettura, è zero o è già chiuso.
Properties
AutomaticLayoutChangesDetectionEnabled
Riceve o impone un valore che indica se Aspose.Note esegue la rilevazione dei cambiamenti di layout automaticamente.Il valore predefinito è ‘verità’.
public bool AutomaticLayoutChangesDetectionEnabled
{
get;
set;
}
Valore di proprietà
Examples
Mostra come salvare un documento in diversi formati.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document doc = new Document() { AutomaticLayoutChangesDetectionEnabled = false };
Aspose.Note.Page page = new Aspose.Note.Page(doc);
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 }
};
doc.AppendChildLast(page);
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
Riceve o mette il colore.
public Color Color
{
get { return this.Color; }
set { this.Color = value; }
}
Valore di proprietà
CreationTime
Riceve o stabilisce il tempo della creazione.
public DateTime CreationTime
{
get;
set;
}
Valore di proprietà
DisplayName
Riceve o impone il nome della visualizzazione.
public string DisplayName
{
get;
set;
}
Valore di proprietà
FileFormat
Riceve il formato di file (OneNote 2010, OneNota Online).
public FileFormat FileFormat
{
get;
}
Valore di proprietà
Examples
Mostra come ottenere il formato di file di un documento.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
var document = new Aspose.Note.Document(dataDir + "Aspose.one");
switch (document.FileFormat)
{
case Aspose.Words.FileFormat.OneNote2010:
break;
case Aspose.Words.FileFormat.OneNoteOnline:
break;
}
Guid
Riceve l’ID unico globale dell’oggetto.
public Guid Guid
{
get;
}
Valore di proprietà
Methods
Accettazione (DocumentVisitor)
Accetta il visitatore del nodo.
public override void Accept(DocumentVisitor visitor)
{
}
Parameters
visitor
DocumentVisitor
L’oggetto di una classe derivato dal Aspose.Note.DocumentVisitor.
Examples
Mostra come accedere al contenuto di un documento utilizzando il visitatore.
public static void Run()
{
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document doc = new Document(dataDir + "Aspose.one");
MyOneNoteToTxtWriter myConverter = new MyOneNoteToTxtWriter();
doc.Accept(myConverter);
Console.WriteLine(myConverter.GetText());
Console.WriteLine(myConverter.NodeCount);
}
public class MyOneNoteToTxtWriter : DocumentVisitor
{
public MyOneNoteToTxtWriter()
{
nodecount = 0;
mIsSkipText = false;
mBuilder = new StringBuilder();
}
public string GetText()
{
return mBuilder.ToString();
}
private void AppendText(string text)
{
if (!mIsSkipText)
{
mBuilder.AppendLine(text);
}
}
public override void VisitRichTextStart(RichText run)
{
++nodecount;
AppendText(run.Text);
}
public override void VisitDocumentStart(Document document)
{
++nodecount;
}
public override void VisitPageStart(Page page)
{
++nodecount;
this.AppendText($"*** Page '{page.Title?.TitleText?.Text ?? "(no title)"}' ***");
}
public override void VisitPageEnd(Page page)
{
this.AppendText(string.Empty);
}
public override void VisitTitleStart(Title title)
{
++nodecount;
}
public override void VisitImageStart(Image image)
{
++nodecount;
}
public override void VisitOutlineGroupStart(OutlineGroup outlineGroup)
{
++nodecount;
}
public override void VisitOutlineStart(Outline outline)
{
++nodecount;
}
public override void VisitOutlineElementStart(OutlineElement outlineElement)
{
++nodecount;
}
public Int32 NodeCount
{
get { return this.nodecount; }
}
private readonly StringBuilder mBuilder;
private bool mIsSkipText;
private Int32 nodecount;
}
Sviluppo dei cambiamenti ()
Detecta tutti i cambiamenti apportati al layout del documento dal precedente chiamato Aspose.Note.Document.DetectLayoutChanges.Nel caso Aspose.Note.Document.AutomaticLayoutChangesDetectionEnabled impostato a vero, utilizzato automaticamente all’inizio dell’esportazione del documento.
public void DetectLayoutChanges()
{
}
Examples
Mostra come salvare un documento in diversi formati.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document doc = new Document() { AutomaticLayoutChangesDetectionEnabled = false };
Aspose.Note.Page page = new Aspose.Note.Page(doc);
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
}
};
doc.AppendChildLast(page);
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");
Sviluppo della pagina (Page)
Riceve il Aspose.Note.PageHistory che contiene la storia completa per ogni pagina presentata in un documento (la prima all’indice 0).L’attuale revisione della pagina può essere accessibile come Aspose.Note.PageHistory.Current e contenuta separatamente dalla raccolta di versioni storiche.
public PageHistory GetPageHistory(Page page)
{
}
I have reformatted the given C# code by:
- Properly indented the method body and comments.
- Added a single space between the opening brace, method name, and opening parenthesis.
- Added a single line between the method signature and its implementation.
- Added two spaces for each level of nesting within the method body for improved readability.
Parameters
page
Page
La revisione attuale di una pagina.
Returns
Il Aspose.Note.Pagina di Storia.
Examples
Mostra come ripristinare la versione precedente di una pagina.
string dataDir = RunExamples.GetDataDir_Pages();
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");
Mostra come modificare la storia della pagina.
string dataDir = RunExamples.GetDataDir_Pages();
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 > 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");
}
Visualizza come verificare se una pagina è una page di conflitto (cioè ha cambiamenti che OneNote non poteva automaticamente fusione).
string dataDir = RunExamples.GetDataDir_Pages();
Document doc = new Document(dataDir + "Aspose.one", new LoadOptions { LoadHistory = true });
var history = doc.GetPageHistory(doc.FirstChild);
for (int i = 0; i < history.Count; i++)
{
var historyPage = history[i];
Console.Write(" {0}. Author: ", i);
Console.Write("{1}, ", historyPage.PageContentRevisionSummary.AuthorMostRecent);
Console.WriteLine("{2:dd.MM.yyyy hh.mm.ss}", historyPage.PageContentRevisionSummary.LastModifiedTime);
Console.WriteLine(historyPage.IsConflictPage ? ", IsConflict: true" : string.Empty);
if (historyPage.IsConflictPage)
historyPage.IsConflictPage = false;
}
doc.Save(dataDir + "ConflictPageManipulation_out.one", SaveFormat.One);
Importazione (Stream, PdfImportOptions, MergeOption)
Importa un insieme di pagine dal documento PDF fornito.
public Document Import(Stream stream, PdfImportOptions importOptions = null, MergeOptions mergeOptions = null)
{
}
Parameters
stream
Stream
Un flusso con un documento PDF.
importOptions
PdfImportOptions
Specifica le opzioni come importare pagine dal documento PDF.
mergeOptions
MergeOptions
Specifica le opzioni su come combinare le pagine fornite.
Returns
Ritorna il riferimento al documento.
Importazione (string, PdfImportOptions, Mergeoptions)
Importa un insieme di pagine dal documento PDF fornito.
public Document Import(string file, PdfImportOptions importOptions = null, MergeOptions mergeOptions = null)
{
}
Parameters
file
string
Un file con un documento PDF.
importOptions
PdfImportOptions
Specifica le opzioni come importare pagine dal documento PDF.
mergeOptions
MergeOptions
Specifica le opzioni su come combinare le pagine fornite.
Returns
Ritorna il riferimento al documento.
Examples
Mostra come importare tutte le pagine da una pagina di documenti PDF per pagina.
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"));
Visualizza come importare tutte le pagine da un insieme di documenti PDF mentre inserisci la pagina da ogni documento PDF come bambini di una pagina OneNote di alto livello.
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
.SetTitleText(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"));
Mostra come importare tutti i contenuti da un insieme di documenti PDF mentre unisce pagine da ogni documento PDF a una sola pagina 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"));
Importazione (Stream, HtmlImportOptions, MergeOption)
Importa un insieme di pagine dal documento HTML fornito.
public Document Import(
Stream stream,
HtmlImportOptions importOptions,
MergeOptions mergeOptions = null)
{
}
Parameters
stream
Stream
Un file con un documento HTML.
importOptions
HtmlImportOptions
Specifica le opzioni come importare pagine dal documento HTML.
mergeOptions
MergeOptions
Specifica le opzioni su come combinare le pagine fornite.
Returns
Ritorna il riferimento al documento.
Importazione (string, HtmlImportOptions, Mergeoptions)
Importa un insieme di pagine dal documento HTML fornito.
public Document Import(string file, HtmlImportOptions importOptions, MergeOptions mergeOptions = null)
{
}
Parameters
file
string
Un file con un documento HTML.
importOptions
HtmlImportOptions
Specifica le opzioni come importare pagine dal documento HTML.
mergeOptions
MergeOptions
Specifica le opzioni su come combinare le pagine fornite.
Returns
Ritorna il riferimento al documento.
IsEncrypted(Stream, LoadOptions, Out Document)
Verifica se un documento da un flusso è crittografato.Per verificare che dobbiamo caricare completamente questo documento. Così questo metodo può portare alla penalità di prestazione.
public static bool IsEncrypted(Stream stream, LoadOptions options, out Document document)
{
document = null;
try
{
document = new Document();
document.Load(stream, options);
return document.IsEncrypted;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return false;
}
Parameters
stream
Stream
Il flusso .
options
LoadOptions
Le opzioni di carico.
document
Document
Il documento caricato.
Returns
Ritorna vero se il documento è crittografato altrimenti falso.
Examples
Mostra come verificare se un documento è protetto dalla password.
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.");
}
Mostra come verificare se un documento è protetto da una password specifica.
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(Stream, string, out Document)
Verifica se un documento da un flusso è crittografato.Per verificare che dobbiamo caricare completamente questo documento. Così questo metodo può portare alla penalità di prestazione.
public static bool IsEncrypted(Stream stream, string password, out Document document)
{
document = null;
try
{
document = new Document();
document.Load(stream, Aspose.Words.FileFormatUtil.DetectEncryptionType(stream), password);
}
catch (Exception ex)
{
return false;
}
return true;
}
Parameters
stream
Stream
Il flusso .
password
string
La password per decodificare un documento.
document
Document
Il documento caricato.
Returns
Ritorna vero se il documento è crittografato altrimenti falso.
Examples
Mostra come verificare se un documento è protetto dalla password.
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.");
}
Mostra come verificare se un documento è protetto da una password specifica.
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 (Stream, fuori Documento)
Verifica se un documento da un flusso è crittografato.Per verificare che dobbiamo caricare completamente questo documento. Così questo metodo può portare alla penalità di prestazione.
public static bool IsEncrypted(Stream stream, out Document document)
{
document = null;
try
{
document = new Document();
document.Load(stream);
return document.EncryptionSettings != null && document.EncryptionSettings.IsEncrypted;
}
catch
{
document = null;
throw;
}
}
Parameters
stream
Stream
Il flusso .
document
Document
Il documento caricato.
Returns
Ritorna vero se il documento è crittografato altrimenti falso.
Examples
Mostra come verificare se un documento è protetto dalla password.
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.");
}
Mostra come verificare se un documento è protetto da una password specifica.
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, LoadOptions, Out Document)
Verifica se un documento di un file è crittografato.Per verificare che dobbiamo caricare completamente questo documento. Così questo metodo può portare alla penalità di prestazione.
public static bool IsEncrypted(string filePath, LoadOptions options, out Document document)
{
document = null;
try
{
using (var doc = new Document(File.OpenRead(filePath), options))
{
document = doc;
return false;
}
}
catch (InvalidPasswordException ex)
{
document = null;
return true;
}
}
Parameters
filePath
string
Il percorso del file.
options
LoadOptions
Le opzioni di carico.
document
Document
Il documento caricato.
Returns
Ritorna vero se il documento è crittografato altrimenti falso.
Examples
Mostra come verificare se un documento è protetto dalla password.
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.");
}
Mostra come verificare se un documento è protetto da una password specifica.
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, fuori Documento)
Verifica se un documento di un file è crittografato.Per verificare che dobbiamo caricare completamente questo documento. Così questo metodo può portare alla penalità di prestazione.
public static bool IsEncrypted(string filePath, out Document document)
{
document = null;
try
{
Aspose.Words.Document asposeDoc = new Aspose.Words.Document(filePath);
document = asposeDoc;
return asposeDoc.ProtectionSettings.EncryptionInfo != null;
}
catch (Exception ex)
{
}
document = null;
return false;
}
Parameters
filePath
string
Il percorso del file.
document
Document
Il documento caricato.
Returns
Ritorna vero se il documento è crittografato altrimenti falso.
Examples
Mostra come verificare se un documento è protetto dalla password.
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.");
}
Mostra come verificare se un documento è protetto da una password specifica.
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, string, out Document)
Verifica se un documento di un file è crittografato.Per verificare che dobbiamo caricare completamente questo documento. Così questo metodo può portare alla penalità di prestazione.
public static bool IsEncrypted(string filePath, string password, out Document document)
{
}
Parameters
filePath
string
Il percorso del file.
password
string
La password per decodificare un documento.
document
Document
Il documento caricato.
Returns
Ritorna vero se il documento è crittografato altrimenti falso.
Examples
Mostra come verificare se un documento è protetto dalla password.
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.");
}
Mostra come verificare se un documento è protetto da una password specifica.
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.");
}
Il numero (non numeroso)di MergeOptions)
Aggiungete una serie di pagine al documento.
public Document Merge(IEnumerable<Page> pages, MergeOptions mergeOptions = null)
{
}
Parameters
pages
IEnumerable
di <
Page
>
Un insieme di pagine.
mergeOptions
MergeOptions
Specifica le opzioni su come combinare le pagine fornite.
Returns
Ritorna il riferimento al documento.
Examples
Visualizza come importare tutte le pagine dal documento PDF, gruppiando ogni 5 Pagine a una sola pagina 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"));
La stampa ( )
Stampa il documento utilizzando la stampante predefinita.
public void Print()
{
}
Examples
Mostra come inviare un documento a una stampante utilizzando il dialogo Windows standard con le opzioni predefinite.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
var document = new Aspose.Note.Document(dataDir + "Aspose.one");
document.Print();
Mostra come inviare un documento a una stampante utilizzando il dialogo Windows standard con le opzioni specificate.
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"
});
Immagini di stampa (Print Options)
Stampa il documento utilizzando la stampante predefinita.
public void Print(PrintOptions options)
{
}
Parameters
options
PrintOptions
Le opzioni utilizzate per stampare un documento. può essere zero.
Salvataggio ( String )
Salva il documento OneNote in un file.
public void Save(string fileName)
{
}
Parameters
fileName
string
Se un file con il nome completo specificato esiste già, il file esistente viene sopratto.
Examples
Mostra come salvare un documento.
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
La struttura del documento viola le specifiche.
UnsupportedSaveFormatException
Il formato di salvataggio richiesto non è supportato.
Il salvataggio (Stream)
Salva il documento OneNote in un flusso.
public void Save(Stream stream)
{
}
Parameters
stream
Stream
Il System.IO.Stream dove il documento sarà salvato.
Exceptions
IncorrectDocumentStructureException
La struttura del documento viola le specifiche.
UnsupportedSaveFormatException
Il formato di salvataggio richiesto non è supportato.
Salva (string e SaveFormat)
Salva il documento OneNote in un file nel formato specificato.
public void Save(string fileName, Aspose.Words.SaveFormat format)
{
}
Parameters
fileName
string
Se un file con il nome completo specificato esiste già, il file esistente viene sopratto.
format
SaveFormat
Il formato in cui salvare il documento.
Examples
Mostra come salvare un documento utilizzando l’elenco 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);
Mostra come salvare un documento in formato gif.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document oneFile = new Document(dataDir + "Aspose.one");
dataDir += "SaveToImageDefaultOptions_out.gif";
oneFile.Save(dataDir, SaveFormat.Gif);
Exceptions
IncorrectDocumentStructureException
La struttura del documento viola le specifiche.
UnsupportedSaveFormatException
Il formato di salvataggio richiesto non è supportato.
Salva (Stream e SaveFormat)
Salva il documento OneNote in un flusso nel formato specificato.
public void Save(Stream stream, SaveFormat format)
{
}
Parameters
stream
Stream
Il System.IO.Stream dove il documento sarà salvato.
format
SaveFormat
Il formato in cui salvare il documento.
Examples
Mostra come salvare un documento in formato pdf utilizzando le impostazioni predefinite.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document oneFile = new Document(dataDir + "Aspose.one");
string dataDirWithFileName = dataDir + "SaveWithDefaultSettings_out.pdf";
oneFile.Save(dataDirWithFileName, SaveFormat.Pdf);
Mostra come salvare un documento in un flusso.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document doc = new Document(dataDir + "Aspose.one");
MemoryStream dstStream = new MemoryStream();
doc.Save(dstStream, SaveFormat.Pdf);
dstStream.Seek(0, SeekOrigin.Begin);
Mostra come applicare lo stile tema oscuro a un documento.
string dataDir = RunExamples.GetDataDir_Text();
Document doc = new Document(Path.Combine(dataDir, "Aspose.one"));
foreach (var page in doc)
{
page.BackgroundColor = Color.Black;
}
foreach (var node in doc.GetChildNodes<Aspose.Words.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) <= 30)
{
node.ParagraphStyle.FontColor = Color.White;
}
}
doc.Save(Path.Combine(dataDir, "AsposeDarkTheme.pdf"));
Exceptions
IncorrectDocumentStructureException
La struttura del documento viola le specifiche.
UnsupportedSaveFormatException
Il formato di salvataggio richiesto non è supportato.
Salva (string, opzioni di salvataggio)
Salva il documento OneNote in un file utilizzando le opzioni di salvataggio specificate.
public void Save(string fileName, SaveOptions options)
{
}
Parameters
fileName
string
Se un file con il nome completo specificato esiste già, il file esistente viene sopratto.
options
SaveOptions
Specifica le opzioni su come il documento viene salvato nel file.
Examples
Mostra come salvare un documento utilizzando 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());
Mostra come salvare un documento come immagine in formato JPEG utilizzando SaveFormat.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document oneFile = new Document(dataDir + "Aspose.one");
dataDir += "SaveToJpegImageUsingSaveFormat_out.jpg";
oneFile.Save(dataDir, SaveFormat.Jpeg);
Mostra come salvare un documento come immagine in formato Bmp utilizzando ImageSaveOptions.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document oneFile = new Document(dataDir + "Aspose.one");
dataDir += "SaveToBmpImageUsingImageSaveOptions_out.bmp";
oneFile.Save(dataDir, new ImageSaveOptions(SaveFormat.Bmp));
Mostra come salvare un documento in formato PDF con il layout della pagina Letter.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document oneFile = new Document(dataDir + "OneNote.one");
var dst = Path.Combine(dataDir, "SaveToPdfUsingLetterPageSettings.pdf");
oneFile.Save(dst, new PdfSaveOptions() { PageSettings = PageSettings.Letter });
Mostra come salvare un documento in formato PDF con layout di pagina A4 senza limite di altezza.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document oneFile = new Document(dataDir + "OneNote.one");
var dst = Path.Combine(dataDir, "SaveToPdfUsingA4PageSettingsWithoutHeightLimit.pdf");
oneFile.Save(dst, new PdfSaveOptions() { PageSettings = PageSettings.A4NoHeightLimit });
Mostra come salvare un documento come immagine di grayscale.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document oneFile = new Document(dataDir + "Aspose.one");
dataDir += "SaveAsGrayscaleImage_out.png";
oneFile.Save(dataDir, new ImageSaveOptions(SaveFormat.Png)
{
ColorMode = ColorMode.GrayScale
});
Mostra come salvare un documento come immagine in formato Tiff utilizzando la compressione PackBits.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document oneFile = new Document(Path.Combine(dataDir, "Aspose.one"));
var dst = Path.Combine(dataDir, "SaveToTiffUsingPackBitsCompression.tiff");
oneFile.Save(dst, new ImageSaveOptions(SaveFormat.Tiff)
{
TiffCompression = TiffCompression.PackBits
});
Mostra come salvare un documento come immagine in formato Tiff utilizzando la compressione Jpeg.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document oneFile = new Document(Path.Combine(dataDir, "Aspose.one"));
var dst = Path.Combine(dataDir, "SaveToTiffUsingJpegCompression.tiff");
oneFile.Save(dst, new ImageSaveOptions(SaveFormat.Tiff)
{
TiffCompression = TiffCompression.Jpeg,
Quality = 93
});
Mostra come salvare un documento come immagine in formato Tiff utilizzando la compressione di fax CCITT Group 3.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document oneFile = new Document(Path.Combine(dataDir, "Aspose.one"));
var dst = Path.Combine(dataDir, "SaveToTiffUsingCcitt3Compression.tiff");
oneFile.Save(dst, new ImageSaveOptions(SaveFormat.Tiff)
{
ColorMode = ColorMode.BlackAndWhite,
TiffCompression = TiffCompression.Ccitt3
});
Mostra come salvare un documento in formato pdf.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document oneFile = new Document(dataDir + "Aspose.one");
PdfSaveOptions opts = new PdfSaveOptions()
{
PageIndex = 0,
PageCount = 1,
};
dataDir += "SaveRangeOfPagesAsPDF_out.pdf";
oneFile.Save(dataDir, opts);
Mostra come salvare un documento in formato pdf utilizzando impostazioni specifiche.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document doc = new Document(dataDir + "Aspose.one");
PdfSaveOptions opts = new PdfSaveOptions
{
ImageCompression = Saving.Pdf.PdfImageCompression.Jpeg,
JpegQuality = 90
};
dataDir += "Document.SaveWithOptions_out.pdf";
doc.Save(dataDir, opts);
Mostra come salvare un documento come immagine binaria utilizzando il metodo di Otsu.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document oneFile = new Document(dataDir + "Aspose.one");
dataDir += "SaveToBinaryImageUsingOtsuMethod_out.png";
oneFile.Save(dataDir, new ImageSaveOptions(SaveFormat.Png)
{
ColorMode = ColorMode.BlackAndWhite,
BinarizationOptions = new ImageBinarizationOptions()
{
BinarizationMethod = BinarizationMethod.Otsu,
}
});
Mostra come salvare un documento come immagine binaria utilizzando un limite fisso.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document oneFile = new Document(dataDir + "Aspose.one");
dataDir += "SaveToBinaryImageUsingFixedThreshold_out.png";
oneFile.Save(dataDir, new ImageSaveOptions(SaveFormat.Png)
{
ColorMode = ColorMode.BlackAndWhite,
BinarizationOptions = new ImageBinarizationOptions()
{
BinarizationMethod = BinarizationMethod.FixedThreshold,
BinarizationThreshold = 123
}
});
Exceptions
IncorrectDocumentStructureException
La struttura del documento viola le specifiche.
UnsupportedSaveFormatException
Il formato di salvataggio richiesto non è supportato.
Salva (Stream, Opzioni di salvataggio)
Salva il documento OneNote in un flusso utilizzando le opzioni di salvataggio specificate.
public void Save(Stream stream, SaveOptions options)
{
}
Parameters
stream
Stream
Il System.IO.Stream dove il documento sarà salvato.
options
SaveOptions
Specifica le opzioni su come il documento viene salvato nel flusso.
Examples
Mostra come salvare un documento in formato pdf utilizzando la font predefinita specificata.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
Document oneFile = new Document(Path.Combine(dataDir, "missing-font.one"));
string dataDirWithOutputPath = dataDir + "SaveUsingDocumentFontsSubsystemWithDefaultFontName_out.pdf";
oneFile.Save(dataDirWithOutputPath, new PdfSaveOptions()
{
FontsSubsystem = DocumentFontsSubsystem.UsingDefaultFont("Times New Roman")
});
Mostra come salvare un documento in formato pdf utilizzando la font predefinita da un file.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
string fontFile = Path.Combine(dataDir, "geo_1.ttf");
Document oneFile = new Document(Path.Combine(dataDir, "missing-font.one"));
string outputFile = dataDir + "SaveUsingDocumentFontsSubsystemWithDefaultFontFromFile_out.pdf";
oneFile.Save(outputFile, new PdfSaveOptions()
{
FontsSubsystem = DocumentFontsSubsystem.UsingDefaultFontFromFile(fontFile)
});
Mostra come salvare un documento in formato pdf utilizzando la font predefinita da un flusso.
string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
string fontFile = Path.Combine(dataDir, "geo_1.ttf");
Document oneFile = new Document(Path.Combine(dataDir, "missing-font.one"));
string fullDataDir = dataDir + "SaveUsingDocumentFontsSubsystemWithDefaultFontFromStream_out.pdf";
using (var stream = File.Open(fontFile, FileMode.Open, FileAccess.Read, FileShare.Read))
{
oneFile.Save(fullDataDir, new PdfSaveOptions()
{
FontsSubsystem = DocumentFontsSubsystem.UsingDefaultFontFromStream(stream)
});
}
Exceptions
IncorrectDocumentStructureException
La struttura del documento viola le specifiche.
UnsupportedSaveFormatException
Il formato di salvataggio richiesto non è supportato.