search/mag_sel search/close
Aspose::Words::PlainTextDocument Class Reference

Allows to extract plain-text representation of the document's content.

Examples

Shows how to load the contents of a Microsoft Word document in plaintext.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Hello world!");
doc->Save(ArtifactsDir + u"PlainTextDocument.Load.docx");
auto plaintext = MakeObject<PlainTextDocument>(ArtifactsDir + u"PlainTextDocument.Load.docx");
ASSERT_EQ(u"Hello world!", plaintext->get_Text().Trim());

#include <Aspose.Words.Cpp/PlainTextDocument.h>

+ Inheritance diagram for Aspose::Words::PlainTextDocument:

Public Member Functions

 PlainTextDocument (SharedPtr< Stream > stream)
 Creates a plain text document from a stream. Automatically detects the file format. More...
 
 PlainTextDocument (SharedPtr< Stream > stream, SharedPtr< LoadOptions > loadOptions)
 Creates a plain text document from a stream. Allows to specify additional options such as an encryption password. More...
 
 PlainTextDocument (String fileName)
 Creates a plain text document from a file. Automatically detects the file format. More...
 
 PlainTextDocument (String fileName, SharedPtr< LoadOptions > loadOptions)
 Creates a plain text document from a file. Allows to specify additional options such as an encryption password. More...
 
SharedPtr< BuiltInDocumentPropertiesget_BuiltInDocumentProperties () const
 Gets BuiltInDocumentProperties of the document. More...
 
SharedPtr< CustomDocumentPropertiesget_CustomDocumentProperties () const
 Gets CustomDocumentProperties of the document. More...
 
String get_Text () const
 Gets textual content of the document concatenated as a string. More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 

Static Public Member Functions

static const TypeInfoType ()
 

Constructor & Destructor Documentation

◆ PlainTextDocument() [1/4]

Aspose::Words::PlainTextDocument::PlainTextDocument ( System::String  fileName)

Creates a plain text document from a file. Automatically detects the file format.

Parameters
fileNameName of the file to extract the text from.
Exceptions
Aspose::Words::UnsupportedFileFormatExceptionThe document format is not recognized or not supported.
Aspose::Words::FileCorruptedExceptionThe document appears to be corrupted and cannot be loaded.
System::ExceptionThere is a problem with the document and it should be reported to Aspose.Words developers.
System::IO::IOExceptionThere is an input/output exception.
Aspose::Words::IncorrectPasswordExceptionThe document is encrypted and requires a password to open, but you supplied an incorrect password.
System::ArgumentExceptionThe name of the file cannot be null or empty string.
Examples

Shows how to load the contents of a Microsoft Word document in plaintext.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Hello world!");
doc->Save(ArtifactsDir + u"PlainTextDocument.Load.docx");
auto plaintext = MakeObject<PlainTextDocument>(ArtifactsDir + u"PlainTextDocument.Load.docx");
ASSERT_EQ(u"Hello world!", plaintext->get_Text().Trim());

◆ PlainTextDocument() [2/4]

Aspose::Words::PlainTextDocument::PlainTextDocument ( System::String  fileName,
System::SharedPtr< Aspose::Words::Loading::LoadOptions loadOptions 
)

Creates a plain text document from a file. Allows to specify additional options such as an encryption password.

Parameters
fileNameName of the file to extract the text from.
loadOptionsAdditional options to use when loading a document. Can be null.
Exceptions
Aspose::Words::UnsupportedFileFormatExceptionThe document format is not recognized or not supported.
Aspose::Words::FileCorruptedExceptionThe document appears to be corrupted and cannot be loaded.
System::ExceptionThere is a problem with the document and it should be reported to Aspose.Words developers.
System::IO::IOExceptionThere is an input/output exception.
Aspose::Words::IncorrectPasswordExceptionThe document is encrypted and requires a password to open, but you supplied an incorrect password.
System::ArgumentExceptionThe name of the file cannot be null or empty string.
Examples

Shows how to load the contents of an encrypted Microsoft Word document in plaintext.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Hello world!");
auto saveOptions = MakeObject<OoxmlSaveOptions>();
saveOptions->set_Password(u"MyPassword");
doc->Save(ArtifactsDir + u"PlainTextDocument.LoadEncrypted.docx", saveOptions);
auto loadOptions = MakeObject<LoadOptions>();
loadOptions->set_Password(u"MyPassword");
auto plaintext = MakeObject<PlainTextDocument>(ArtifactsDir + u"PlainTextDocument.LoadEncrypted.docx", loadOptions);
ASSERT_EQ(u"Hello world!", plaintext->get_Text().Trim());

◆ PlainTextDocument() [3/4]

Aspose::Words::PlainTextDocument::PlainTextDocument ( System::SharedPtr< System::IO::Stream stream)

Creates a plain text document from a stream. Automatically detects the file format.

The document must be stored at the beginning of the stream. The stream must support random positioning.

Parameters
streamThe stream where to extract the text from.
Exceptions
Aspose::Words::UnsupportedFileFormatExceptionThe document format is not recognized or not supported.
Aspose::Words::FileCorruptedExceptionThe document appears to be corrupted and cannot be loaded.
System::ExceptionThere is a problem with the document and it should be reported to Aspose.Words developers.
System::IO::IOExceptionThere is an input/output exception.
Aspose::Words::IncorrectPasswordExceptionThe document is encrypted and requires a password to open, but you supplied an incorrect password.
System::ArgumentNullExceptionThe stream cannot be null.
System::NotSupportedExceptionThe stream does not support reading or seeking.
System::ObjectDisposedExceptionThe stream is a disposed object.
Examples

Shows how to load the contents of a Microsoft Word document in plaintext using stream.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Hello world!");
doc->Save(ArtifactsDir + u"PlainTextDocument.LoadFromStream.docx");
{
auto stream = MakeObject<System::IO::FileStream>(ArtifactsDir + u"PlainTextDocument.LoadFromStream.docx", System::IO::FileMode::Open);
auto plaintext = MakeObject<PlainTextDocument>(stream);
ASSERT_EQ(u"Hello world!", plaintext->get_Text().Trim());
}

◆ PlainTextDocument() [4/4]

Aspose::Words::PlainTextDocument::PlainTextDocument ( System::SharedPtr< System::IO::Stream stream,
System::SharedPtr< Aspose::Words::Loading::LoadOptions loadOptions 
)

Creates a plain text document from a stream. Allows to specify additional options such as an encryption password.

The document must be stored at the beginning of the stream. The stream must support random positioning.

Parameters
streamThe stream where to extract the text from.
loadOptionsAdditional options to use when loading a document. Can be null.
Exceptions
Aspose::Words::UnsupportedFileFormatExceptionThe document format is not recognized or not supported.
Aspose::Words::FileCorruptedExceptionThe document appears to be corrupted and cannot be loaded.
System::ExceptionThere is a problem with the document and it should be reported to Aspose.Words developers.
System::IO::IOExceptionThere is an input/output exception.
Aspose::Words::IncorrectPasswordExceptionThe document is encrypted and requires a password to open, but you supplied an incorrect password.
System::ArgumentNullExceptionThe stream cannot be null.
System::NotSupportedExceptionThe stream does not support reading or seeking.
System::ObjectDisposedExceptionThe stream is a disposed object.
Examples

Shows how to load the contents of an encrypted Microsoft Word document in plaintext using stream.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Hello world!");
auto saveOptions = MakeObject<OoxmlSaveOptions>();
saveOptions->set_Password(u"MyPassword");
doc->Save(ArtifactsDir + u"PlainTextDocument.LoadFromStreamWithOptions.docx", saveOptions);
auto loadOptions = MakeObject<LoadOptions>();
loadOptions->set_Password(u"MyPassword");
{
auto stream = MakeObject<System::IO::FileStream>(ArtifactsDir + u"PlainTextDocument.LoadFromStreamWithOptions.docx", System::IO::FileMode::Open);
auto plaintext = MakeObject<PlainTextDocument>(stream, loadOptions);
ASSERT_EQ(u"Hello world!", plaintext->get_Text().Trim());
}

Member Function Documentation

◆ get_BuiltInDocumentProperties()

System::SharedPtr<Aspose::Words::Properties::BuiltInDocumentProperties> Aspose::Words::PlainTextDocument::get_BuiltInDocumentProperties ( ) const

Gets BuiltInDocumentProperties of the document.

Examples

Shows how to load the contents of a Microsoft Word document in plaintext and then access the original document's built-in properties.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Hello world!");
doc->get_BuiltInDocumentProperties()->set_Author(u"John Doe");
doc->Save(ArtifactsDir + u"PlainTextDocument.BuiltInProperties.docx");
auto plaintext = MakeObject<PlainTextDocument>(ArtifactsDir + u"PlainTextDocument.BuiltInProperties.docx");
ASSERT_EQ(u"Hello world!", plaintext->get_Text().Trim());
ASSERT_EQ(u"John Doe", plaintext->get_BuiltInDocumentProperties()->get_Author());

◆ get_CustomDocumentProperties()

System::SharedPtr<Aspose::Words::Properties::CustomDocumentProperties> Aspose::Words::PlainTextDocument::get_CustomDocumentProperties ( ) const

Gets CustomDocumentProperties of the document.

Examples

Shows how to load the contents of a Microsoft Word document in plaintext and then access the original document's custom properties.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Hello world!");
doc->get_CustomDocumentProperties()->Add(u"Location of writing", String(u"123 Main St, London, UK"));
doc->Save(ArtifactsDir + u"PlainTextDocument.CustomDocumentProperties.docx");
auto plaintext = MakeObject<PlainTextDocument>(ArtifactsDir + u"PlainTextDocument.CustomDocumentProperties.docx");
ASSERT_EQ(u"Hello world!", plaintext->get_Text().Trim());
ASPOSE_ASSERT_EQ(u"123 Main St, London, UK", plaintext->get_CustomDocumentProperties()->idx_get(u"Location of writing")->get_Value());

◆ get_Text()

System::String Aspose::Words::PlainTextDocument::get_Text ( ) const

Gets textual content of the document concatenated as a string.

Examples

Shows how to load the contents of a Microsoft Word document in plaintext.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Writeln(u"Hello world!");
doc->Save(ArtifactsDir + u"PlainTextDocument.Load.docx");
auto plaintext = MakeObject<PlainTextDocument>(ArtifactsDir + u"PlainTextDocument.Load.docx");
ASSERT_EQ(u"Hello world!", plaintext->get_Text().Trim());

◆ GetType()

virtual const System::TypeInfo& Aspose::Words::PlainTextDocument::GetType ( ) const
overridevirtual

Reimplemented from System::Object.

◆ Is()

virtual bool Aspose::Words::PlainTextDocument::Is ( const System::TypeInfo target) const
overridevirtual

Reimplemented from System::Object.

◆ Type()

static const System::TypeInfo& Aspose::Words::PlainTextDocument::Type ( )
static