public void LoadEncryptedUsingStream() { //ExStart //ExFor:PlainTextDocument.#ctor(Stream, LoadOptions) //ExSummary:Shows how to load the contents of an encrypted Microsoft Word document in plaintext using stream. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Writeln("Hello world!"); OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(); saveOptions.Password = "******"; doc.Save(ArtifactsDir + "PlainTextDocument.LoadFromStreamWithOptions.docx", saveOptions); LoadOptions loadOptions = new LoadOptions(); loadOptions.Password = "******"; using (FileStream stream = new FileStream(ArtifactsDir + "PlainTextDocument.LoadFromStreamWithOptions.docx", FileMode.Open)) { PlainTextDocument plaintext = new PlainTextDocument(stream, loadOptions); Assert.AreEqual("Hello world!", plaintext.Text.Trim()); } //ExEnd }
public void LoadEncrypted() { //ExStart //ExFor:PlainTextDocument.#ctor(String, LoadOptions) //ExSummary:Shows how to load the contents of an encrypted Microsoft Word document in plaintext. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Writeln("Hello world!"); OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(); saveOptions.Password = "******"; doc.Save(ArtifactsDir + "PlainTextDocument.LoadEncrypted.docx", saveOptions); LoadOptions loadOptions = new LoadOptions(); loadOptions.Password = "******"; PlainTextDocument plaintext = new PlainTextDocument(ArtifactsDir + "PlainTextDocument.LoadEncrypted.docx", loadOptions); Assert.AreEqual("Hello world!", plaintext.Text.Trim()); //ExEnd }
public void InsertWithLineBreaks() { var text = "Hello\nWorld"; var doc = new PlainTextDocument(); doc.InsertAt(0, text); doc.Root.Offset.Should().Be(0); doc.Root.EndOffset.Should().Be(11); doc.Root.Count.Should().Be(2); }
public void InsertOrdinaryText() { var doc = new PlainTextDocument(); doc.InsertAt(0, "Hello World"); doc.TextAt(0, doc.TextLength).Should().Be("Hello World"); doc.Root.Offset.Should().Be(0); doc.Root.EndOffset.Should().Be(11); doc.Root.Count.Should().Be(1); }
ParagraphTextView <PlainTextDocument> CreateView(string text = null) { var doc = new PlainTextDocument(); doc.InsertAt(0, text ?? "Hello World, Here I am. Long text ahead here. A long word, that is impossible to break apart."); var node = doc.Root[0]; var view = new ParagraphTextView <PlainTextDocument>(node, textStyle, new PlainTextViewFactory()); return(view); }
ParagraphTextView <PlainTextDocument> CreateView(string text) { var doc = new PlainTextDocument(); doc.InsertAt(0, text); var node = doc.Root[0]; var view = new ParagraphTextView <PlainTextDocument>(node, textStyle, new PlainTextViewFactory()); return(view); }
public void InsertAtEnd() { var text = "Hello World"; var doc = new PlainTextDocument(); doc.InsertAt(0, text); doc.InsertAt(doc.TextLength, " More"); doc.TextAt(0, doc.TextLength).Should().Be("Hello World More"); doc.Root.Count.Should().Be(1); doc.Root.Offset.Should().Be(0); doc.Root.EndOffset.Should().Be(16); }
public void RemoveAllText() { var text = "Hello World"; var doc = new PlainTextDocument(); doc.InsertAt(0, text); doc.DeleteAt(0, text.Length); doc.TextAt(0, doc.TextLength).Should().Be(""); doc.Root.Offset.Should().Be(0); doc.Root.EndOffset.Should().Be(0); doc.Root.Count.Should().Be(1); }
public void RemoveAcrossLineBreaks() { var text = "Hello World\n More"; var doc = new PlainTextDocument(); doc.InsertAt(0, text); doc.DeleteAt(6, 7); doc.TextAt(0, doc.TextLength).Should().Be("Hello More"); doc.Root.Offset.Should().Be(0); doc.Root.EndOffset.Should().Be(10); doc.Root.Count.Should().Be(1); }
public void InsertWithLineBreaksAtEndOfLine() { var text = "Hello World\n"; var doc = new PlainTextDocument(); doc.InsertAt(0, text); doc.TextAt(0, doc.TextLength).Should().Be(text); doc.Root.Offset.Should().Be(0); doc.Root.EndOffset.Should().Be(12); doc.Root.Count.Should().Be(2); doc.Root[1].Offset.Should().Be(12); doc.Root[1].EndOffset.Should().Be(12); }
private void Parse(string filePath) { if (string.IsNullOrEmpty(filePath)) { throw new ArgumentNullException("filePath"); } if (!File.Exists(filePath)) { throw new FileNotFoundException(); } plainTextDoc = new PlainTextDocument(filePath); }
public void EditDocument() { var doc = new PlainTextDocument(); doc.InsertAt(0, "A"); doc.Root.Offset.Should().Be(0); doc.Root.EndOffset.Should().Be(1); doc.DeleteAt(0, doc.TextLength); doc.Root.Offset.Should().Be(0); doc.Root.EndOffset.Should().Be(0); doc.InsertAt(0, "B"); doc.Root.Offset.Should().Be(0); doc.Root.EndOffset.Should().Be(1); }
BlockTextView <PlainTextDocument> CreateView(string text = null) { var doc = new PlainTextDocument(); doc.InsertAt(0, text ?? "Hello World, Here I am. \nLong text ahead here. \nA long word, that is impossible to break apart."); var textStyle = LayoutTestStyle.CreateTextStyle(styleSystem); var factory = new PlainTextViewFactory(); var view = new BlockTextView <PlainTextDocument>(doc.Root, textStyle); for (var i = 0; i < doc.Root.Count; i += 1) { view.Add(new ParagraphTextView <PlainTextDocument>(doc.Root[i], textStyle, factory)); } return(view); }
public void Load() { //ExStart //ExFor:PlainTextDocument //ExFor:PlainTextDocument.#ctor(String) //ExFor:PlainTextDocument.Text //ExSummary:Shows how to load a document in its plaintext state. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Writeln("Hello world!"); doc.Save(ArtifactsDir + "PlainTextDocument.Load.docx"); PlainTextDocument plaintext = new PlainTextDocument(ArtifactsDir + "PlainTextDocument.Load.docx"); Assert.AreEqual("Hello world!", plaintext.Text.Trim()); //ExEnd }
public void InsertNewLine() { var doc = new PlainTextDocument(); doc.InsertAt(0, "Hello World!"); doc.Root.Offset.Should().Be(0); doc.Root.EndOffset.Should().Be(12); doc.Root.Count.Should().Be(1); doc.Root[0].Offset.Should().Be(0); doc.Root[0].EndOffset.Should().Be(12); doc.InsertAt(5, '\n'); doc.Root.Count.Should().Be(2); doc.Root[0].Offset.Should().Be(0); doc.Root[0].EndOffset.Should().Be(6); doc.Root[1].Offset.Should().Be(6); doc.Root[1].EndOffset.Should().Be(13); }
public static TestDocumentView <PlainTextDocument> SetUp(Alignment alignment = Alignment.Start, string text = null) { var doc = new PlainTextDocument(); doc.InsertAt(0, text ?? "Hello World, Here I am. Long text ahead here. This is the first paragraph.\nAfter a line break, we should see a second paragraph in the document."); var style = LayoutTestStyle.Create(); var textStyles = style.StyleSystem.StylesFor <TextStyleDefinition>(); var documentView = new TestDocumentView <PlainTextDocument>(new PlainTextDocumentEditor(style)); documentView.Style.SetValue(textStyles.Alignment, alignment); documentView.Style.SetValue(textStyles.Font, style.Style.MediumFont); documentView.Document = doc; style.StyleResolver.AddRoot(documentView); return(documentView); }
public void LoadFromStream() { //ExStart //ExFor:PlainTextDocument.#ctor(Stream) //ExSummary:Shows how to load the contents of a Microsoft Word document in plaintext using stream. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Writeln("Hello world!"); doc.Save(ArtifactsDir + "PlainTextDocument.LoadFromStream.docx"); using (FileStream stream = new FileStream(ArtifactsDir + "PlainTextDocument.LoadFromStream.docx", FileMode.Open)) { PlainTextDocument plaintext = new PlainTextDocument(stream); Assert.AreEqual("Hello world!", plaintext.Text.Trim()); } //ExEnd }
public void CustomDocumentProperties() { //ExStart //ExFor:PlainTextDocument.CustomDocumentProperties //ExSummary:Shows how to load the contents of a Microsoft Word document in plaintext and then access the original document's custom properties. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Writeln("Hello world!"); doc.CustomDocumentProperties.Add("Location of writing", "123 Main St, London, UK"); doc.Save(ArtifactsDir + "PlainTextDocument.CustomDocumentProperties.docx"); PlainTextDocument plaintext = new PlainTextDocument(ArtifactsDir + "PlainTextDocument.CustomDocumentProperties.docx"); Assert.AreEqual("Hello world!", plaintext.Text.Trim()); Assert.AreEqual("123 Main St, London, UK", plaintext.CustomDocumentProperties["Location of writing"].Value); //ExEnd }
public void BuiltInProperties() { //ExStart //ExFor:PlainTextDocument.BuiltInDocumentProperties //ExSummary:Shows how to load the contents of a Microsoft Word document in plaintext and then access the original document's built-in properties. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Writeln("Hello world!"); doc.BuiltInDocumentProperties.Author = "John Doe"; doc.Save(ArtifactsDir + "PlainTextDocument.BuiltInProperties.docx"); PlainTextDocument plaintext = new PlainTextDocument(ArtifactsDir + "PlainTextDocument.BuiltInProperties.docx"); Assert.AreEqual("Hello world!", plaintext.Text.Trim()); Assert.AreEqual("John Doe", plaintext.BuiltInDocumentProperties.Author); //ExEnd }
public void BuiltInProperties() { //ExStart //ExFor:PlainTextDocument.BuiltInDocumentProperties //ExSummary:Shows how to load a plaintext version of a document, and also access its built in properties. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Writeln("Hello world!"); doc.BuiltInDocumentProperties.Author = "John Doe"; doc.Save(ArtifactsDir + "PlainTextDocument.BuiltInProperties.docx"); PlainTextDocument plaintext = new PlainTextDocument(ArtifactsDir + "PlainTextDocument.BuiltInProperties.docx"); Assert.AreEqual("Hello world!", plaintext.Text.Trim()); Assert.AreEqual("John Doe", plaintext.BuiltInDocumentProperties.Author); //ExEnd }
TextChunkView <PlainTextDocument> CreateChunk(int?start = null, int?end = null, string text = null) { var doc = new PlainTextDocument(); doc.InsertAt(0, text ?? "Hello World, Here I am. Can you see me? This is on the next line."); var node = doc.Root[0]; var startOffset = start ?? node.Offset; var endOffset = end ?? node.EndOffset; var chunk = new TextChunkView <PlainTextDocument>( new TextProcessingRules(), node, textStyle, node.Document.CreatePosition(startOffset, Bias.Forward), node.Document.CreatePosition(endOffset, Bias.Backward)); chunk.Initialize(); return(chunk); }
public void ExtractPlainTextFromStream() { //ExStart //ExFor:Document.ExtractText(Stream) //ExFor:Document.ExtractText(Stream, LoadOptions) //ExSummary: Stream docStream = new FileStream(MyDir + "Bookmark.doc", FileMode.Open); PlainTextDocument plaintext = new PlainTextDocument(docStream); Assert.AreEqual("This is a bookmarked text.\f", plaintext.Text); docStream.Close(); docStream = new FileStream(MyDir + "Bookmark.doc", FileMode.Open); LoadOptions loadOptions = new LoadOptions(); loadOptions.AllowTrailingWhitespaceForListItems = false; plaintext = new PlainTextDocument(docStream, loadOptions); Assert.AreEqual("This is a bookmarked text.\f", plaintext.Text); docStream.Close(); //ExEnd }
public void ExtractPlainTextFromDocument() { //ExStart //ExFor:Document.ExtractText(string) //ExFor:Document.ExtractText(string, LoadOptions) //ExFor:PlaintextDocument.Text //ExFor:PlaintextDocument.BuiltInDocumentProperties //ExFor:PlaintextDocument.CustomDocumentProperties //ExSummary:Shows how to extract plain text from the document and get it properties PlainTextDocument plaintext = new PlainTextDocument(MyDir + "Bookmark.docx"); Assert.AreEqual("This is a bookmarked text.\f", plaintext.Text); //in .doc there is other result "This is a bookmarked text.\r\r\r\r\r\r\r\f"" LoadOptions loadOptions = new LoadOptions(); loadOptions.AllowTrailingWhitespaceForListItems = false; plaintext = new PlainTextDocument(MyDir + "Bookmark.doc", loadOptions); Assert.AreEqual("This is a bookmarked text.\f", plaintext.Text); BuiltInDocumentProperties builtInDocumentProperties = plaintext.BuiltInDocumentProperties; Assert.AreEqual("Aspose", builtInDocumentProperties.Company); CustomDocumentProperties customDocumentProperties = plaintext.CustomDocumentProperties; Assert.IsEmpty(customDocumentProperties); //ExEnd }