Class Processor

Class Processor

Namespace: Aspose.Words.LowCode
Assembly: Aspose.Words.dll (25.12.0)

Processor class for performing different document processing actions.

public class Processor

Inheritance

object Processor

Derived

Comparer , Converter , MailMerger , Merger , Replacer , ReportBuilder , Splitter , Watermarker

Inherited Members

object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()

Examples

Shows how to convert documents with a single line of code using context.

string doc = MyDir + "Big document.docx";

                                                                                   Converter.Create(new ConverterContext())
                                                                                       .From(doc)
                                                                                       .To(ArtifactsDir + "LowCode.ConvertContext.1.pdf")
                                                                                       .Execute();

                                                                                   Converter.Create(new ConverterContext())
                                                                                       .From(doc)
                                                                                       .To(ArtifactsDir + "LowCode.ConvertContext.2.pdf", SaveFormat.Rtf)
                                                                                       .Execute();

                                                                                   OoxmlSaveOptions saveOptions = new OoxmlSaveOptions { Password = "Aspose.Words" };
                                                                                   LoadOptions loadOptions = new LoadOptions() { IgnoreOleData = true };
                                                                                   Converter.Create(new ConverterContext())
                                                                                       .From(doc, loadOptions)
                                                                                       .To(ArtifactsDir + "LowCode.ConvertContext.3.docx", saveOptions)
                                                                                       .Execute();

                                                                                   Converter.Create(new ConverterContext())
                                                                                       .From(doc)
                                                                                       .To(ArtifactsDir + "LowCode.ConvertContext.4.png", new ImageSaveOptions(SaveFormat.Png))
                                                                                       .Execute();

Shows how to do mail merge operation from a DataTable using documents from the stream using context.

// There is a several ways to do mail merge operation from a DataTable using documents from the stream:
                                                                                                               DataTable dataTable = new DataTable();
                                                                                                               dataTable.Columns.Add("FirstName");
                                                                                                               dataTable.Columns.Add("Location");
                                                                                                               dataTable.Columns.Add("SpecialCharsInName()");

                                                                                                               DataRow dataRow = dataTable.Rows.Add(new string[] { "James Bond", "London", "Classified" });

                                                                                                               using (FileStream streamIn = new FileStream(MyDir + "Mail merge.doc", FileMode.Open, FileAccess.Read))
                                                                                                               {
                                                                                                                   MailMergerContext mailMergerContext = new MailMergerContext();
                                                                                                                   mailMergerContext.SetSimpleDataSource(dataTable);
                                                                                                                   mailMergerContext.MailMergeOptions.TrimWhitespaces = true;

                                                                                                                   using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MailMergeContextStreamDataTable.docx", FileMode.Create, FileAccess.ReadWrite))
                                                                                                                       MailMerger.Create(mailMergerContext)
                                                                                                                           .From(streamIn)
                                                                                                                           .To(streamOut, SaveFormat.Docx)
                                                                                                                           .Execute();
                                                                                                               }

Shows how to convert documents from a stream with a single line of code using context.

string doc = MyDir + "Document.docx";
                                                                                                 using (FileStream streamIn = new FileStream(MyDir + "Big document.docx", FileMode.Open, FileAccess.Read))
                                                                                                 {
                                                                                                     using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.ConvertContextStream.1.docx", FileMode.Create, FileAccess.ReadWrite))
                                                                                                         Converter.Create(new ConverterContext())
                                                                                                             .From(streamIn)
                                                                                                             .To(streamOut, SaveFormat.Rtf)
                                                                                                             .Execute();

                                                                                                     OoxmlSaveOptions saveOptions = new OoxmlSaveOptions { Password = "Aspose.Words" };
                                                                                                     LoadOptions loadOptions = new LoadOptions() { IgnoreOleData = true };
                                                                                                     using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.ConvertContextStream.2.docx", FileMode.Create, FileAccess.ReadWrite))
                                                                                                         Converter.Create(new ConverterContext())
                                                                                                             .From(streamIn, loadOptions)
                                                                                                             .To(streamOut, saveOptions)
                                                                                                             .Execute();

                                                                                                     List<Stream> pages = new List<Stream>();
                                                                                                     Converter.Create(new ConverterContext())
                                                                                                         .From(doc)
                                                                                                         .To(pages, new ImageSaveOptions(SaveFormat.Png))
                                                                                                         .Execute();
                                                                                                 }

Shows how to merge documents into a single output document using context.

//There is a several ways to merge documents:
                                                                                    string inputDoc1 = MyDir + "Big document.docx";
                                                                                    string inputDoc2 = MyDir + "Tables.docx";

                                                                                    Merger.Create(new MergerContext() { MergeFormatMode = MergeFormatMode.KeepSourceFormatting })
                                                                                        .From(inputDoc1)
                                                                                        .From(inputDoc2)
                                                                                        .To(ArtifactsDir + "LowCode.MergeContextDocuments.1.docx")
                                                                                        .Execute();

                                                                                    LoadOptions firstLoadOptions = new LoadOptions() { IgnoreOleData = true };
                                                                                    LoadOptions secondLoadOptions = new LoadOptions() { IgnoreOleData = false };
                                                                                    Merger.Create(new MergerContext() { MergeFormatMode = MergeFormatMode.KeepSourceFormatting })
                                                                                        .From(inputDoc1, firstLoadOptions)
                                                                                        .From(inputDoc2, secondLoadOptions)
                                                                                        .To(ArtifactsDir + "LowCode.MergeContextDocuments.2.docx", SaveFormat.Docx)
                                                                                        .Execute();

                                                                                    OoxmlSaveOptions saveOptions = new OoxmlSaveOptions { Password = "Aspose.Words" };
                                                                                    Merger.Create(new MergerContext() { MergeFormatMode = MergeFormatMode.KeepSourceFormatting })
                                                                                        .From(inputDoc1)
                                                                                        .From(inputDoc2)
                                                                                        .To(ArtifactsDir + "LowCode.MergeContextDocuments.3.docx", saveOptions)
                                                                                        .Execute();

Shows how to merge documents from stream into a single output document using context.

//There is a several ways to merge documents:
                                                                                                string inputDoc1 = MyDir + "Big document.docx";
                                                                                                string inputDoc2 = MyDir + "Tables.docx";

                                                                                                using (FileStream firstStreamIn = new FileStream(MyDir + "Big document.docx", FileMode.Open, FileAccess.Read))
                                                                                                {
                                                                                                    using (FileStream secondStreamIn = new FileStream(MyDir + "Tables.docx", FileMode.Open, FileAccess.Read))
                                                                                                    {
                                                                                                        OoxmlSaveOptions saveOptions = new OoxmlSaveOptions { Password = "Aspose.Words" };
                                                                                                        using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MergeStreamContextDocuments.1.docx", FileMode.Create, FileAccess.ReadWrite))
                                                                                                            Merger.Create(new MergerContext() { MergeFormatMode = MergeFormatMode.KeepSourceFormatting })
                                                                                                            .From(firstStreamIn)
                                                                                                            .From(secondStreamIn)
                                                                                                            .To(streamOut, saveOptions)
                                                                                                            .Execute();

                                                                                                        LoadOptions firstLoadOptions = new LoadOptions() { IgnoreOleData = true };
                                                                                                        LoadOptions secondLoadOptions = new LoadOptions() { IgnoreOleData = false };
                                                                                                        using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MergeStreamContextDocuments.2.docx", FileMode.Create, FileAccess.ReadWrite))
                                                                                                            Merger.Create(new MergerContext() { MergeFormatMode = MergeFormatMode.KeepSourceFormatting })
                                                                                                            .From(firstStreamIn, firstLoadOptions)
                                                                                                            .From(secondStreamIn, secondLoadOptions)
                                                                                                            .To(streamOut, SaveFormat.Docx)
                                                                                                            .Execute();
                                                                                                    }
                                                                                                }

Fields

mResultDocument

protected Document mResultDocument

Field Value

Document

Methods

CheckArgumentsSet()

protected virtual void CheckArgumentsSet()

Execute()

Execute the processor action.

public void Execute()

Examples

Shows how to convert documents with a single line of code using context.

string doc = MyDir + "Big document.docx";

                                                                                   Converter.Create(new ConverterContext())
                                                                                       .From(doc)
                                                                                       .To(ArtifactsDir + "LowCode.ConvertContext.1.pdf")
                                                                                       .Execute();

                                                                                   Converter.Create(new ConverterContext())
                                                                                       .From(doc)
                                                                                       .To(ArtifactsDir + "LowCode.ConvertContext.2.pdf", SaveFormat.Rtf)
                                                                                       .Execute();

                                                                                   OoxmlSaveOptions saveOptions = new OoxmlSaveOptions { Password = "Aspose.Words" };
                                                                                   LoadOptions loadOptions = new LoadOptions() { IgnoreOleData = true };
                                                                                   Converter.Create(new ConverterContext())
                                                                                       .From(doc, loadOptions)
                                                                                       .To(ArtifactsDir + "LowCode.ConvertContext.3.docx", saveOptions)
                                                                                       .Execute();

                                                                                   Converter.Create(new ConverterContext())
                                                                                       .From(doc)
                                                                                       .To(ArtifactsDir + "LowCode.ConvertContext.4.png", new ImageSaveOptions(SaveFormat.Png))
                                                                                       .Execute();

Shows how to convert documents from a stream with a single line of code using context.

string doc = MyDir + "Document.docx";
                                                                                                 using (FileStream streamIn = new FileStream(MyDir + "Big document.docx", FileMode.Open, FileAccess.Read))
                                                                                                 {
                                                                                                     using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.ConvertContextStream.1.docx", FileMode.Create, FileAccess.ReadWrite))
                                                                                                         Converter.Create(new ConverterContext())
                                                                                                             .From(streamIn)
                                                                                                             .To(streamOut, SaveFormat.Rtf)
                                                                                                             .Execute();

                                                                                                     OoxmlSaveOptions saveOptions = new OoxmlSaveOptions { Password = "Aspose.Words" };
                                                                                                     LoadOptions loadOptions = new LoadOptions() { IgnoreOleData = true };
                                                                                                     using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.ConvertContextStream.2.docx", FileMode.Create, FileAccess.ReadWrite))
                                                                                                         Converter.Create(new ConverterContext())
                                                                                                             .From(streamIn, loadOptions)
                                                                                                             .To(streamOut, saveOptions)
                                                                                                             .Execute();

                                                                                                     List<Stream> pages = new List<Stream>();
                                                                                                     Converter.Create(new ConverterContext())
                                                                                                         .From(doc)
                                                                                                         .To(pages, new ImageSaveOptions(SaveFormat.Png))
                                                                                                         .Execute();
                                                                                                 }

Shows how to merge documents into a single output document using context.

//There is a several ways to merge documents:
                                                                                    string inputDoc1 = MyDir + "Big document.docx";
                                                                                    string inputDoc2 = MyDir + "Tables.docx";

                                                                                    Merger.Create(new MergerContext() { MergeFormatMode = MergeFormatMode.KeepSourceFormatting })
                                                                                        .From(inputDoc1)
                                                                                        .From(inputDoc2)
                                                                                        .To(ArtifactsDir + "LowCode.MergeContextDocuments.1.docx")
                                                                                        .Execute();

                                                                                    LoadOptions firstLoadOptions = new LoadOptions() { IgnoreOleData = true };
                                                                                    LoadOptions secondLoadOptions = new LoadOptions() { IgnoreOleData = false };
                                                                                    Merger.Create(new MergerContext() { MergeFormatMode = MergeFormatMode.KeepSourceFormatting })
                                                                                        .From(inputDoc1, firstLoadOptions)
                                                                                        .From(inputDoc2, secondLoadOptions)
                                                                                        .To(ArtifactsDir + "LowCode.MergeContextDocuments.2.docx", SaveFormat.Docx)
                                                                                        .Execute();

                                                                                    OoxmlSaveOptions saveOptions = new OoxmlSaveOptions { Password = "Aspose.Words" };
                                                                                    Merger.Create(new MergerContext() { MergeFormatMode = MergeFormatMode.KeepSourceFormatting })
                                                                                        .From(inputDoc1)
                                                                                        .From(inputDoc2)
                                                                                        .To(ArtifactsDir + "LowCode.MergeContextDocuments.3.docx", saveOptions)
                                                                                        .Execute();

Shows how to merge documents from stream into a single output document using context.

//There is a several ways to merge documents:
                                                                                                string inputDoc1 = MyDir + "Big document.docx";
                                                                                                string inputDoc2 = MyDir + "Tables.docx";

                                                                                                using (FileStream firstStreamIn = new FileStream(MyDir + "Big document.docx", FileMode.Open, FileAccess.Read))
                                                                                                {
                                                                                                    using (FileStream secondStreamIn = new FileStream(MyDir + "Tables.docx", FileMode.Open, FileAccess.Read))
                                                                                                    {
                                                                                                        OoxmlSaveOptions saveOptions = new OoxmlSaveOptions { Password = "Aspose.Words" };
                                                                                                        using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MergeStreamContextDocuments.1.docx", FileMode.Create, FileAccess.ReadWrite))
                                                                                                            Merger.Create(new MergerContext() { MergeFormatMode = MergeFormatMode.KeepSourceFormatting })
                                                                                                            .From(firstStreamIn)
                                                                                                            .From(secondStreamIn)
                                                                                                            .To(streamOut, saveOptions)
                                                                                                            .Execute();

                                                                                                        LoadOptions firstLoadOptions = new LoadOptions() { IgnoreOleData = true };
                                                                                                        LoadOptions secondLoadOptions = new LoadOptions() { IgnoreOleData = false };
                                                                                                        using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MergeStreamContextDocuments.2.docx", FileMode.Create, FileAccess.ReadWrite))
                                                                                                            Merger.Create(new MergerContext() { MergeFormatMode = MergeFormatMode.KeepSourceFormatting })
                                                                                                            .From(firstStreamIn, firstLoadOptions)
                                                                                                            .From(secondStreamIn, secondLoadOptions)
                                                                                                            .To(streamOut, SaveFormat.Docx)
                                                                                                            .Execute();
                                                                                                    }
                                                                                                }

Execute(CancellationToken)

Execute the processor action allowing canceling document processing task using specified cancellation token.

public void Execute(CancellationToken token)

Parameters

token CancellationToken

Exceptions

OperationCanceledException

Thrown when a cancellation request is detected.

ExecuteCore()

protected virtual void ExecuteCore()

From(string)

Specifies input document for processing.

public Processor From(string input)

Parameters

input string

Input document file name.

Returns

Processor

Returns processor with specified input file.

Remarks

If the processor accepts only one file as an input, only the last specified file will be processed. Aspose.Words.LowCode.Merger processor accepts multiple files as an input, as the result all the specified documents will be merged. Aspose.Words.LowCode.Converter processor accepts only one file as an input, so only the last specified file will be converted.

From(string, LoadOptions)

Specifies input document for processing.

public Processor From(string input, LoadOptions loadOptions)

Parameters

input string

Input document file name.

loadOptions LoadOptions

Optional load options used to load the document.

Returns

Processor

Returns processor with specified input file.

Examples

Shows how to convert documents with a single line of code using context.

string doc = MyDir + "Big document.docx";

                                                                                   Converter.Create(new ConverterContext())
                                                                                       .From(doc)
                                                                                       .To(ArtifactsDir + "LowCode.ConvertContext.1.pdf")
                                                                                       .Execute();

                                                                                   Converter.Create(new ConverterContext())
                                                                                       .From(doc)
                                                                                       .To(ArtifactsDir + "LowCode.ConvertContext.2.pdf", SaveFormat.Rtf)
                                                                                       .Execute();

                                                                                   OoxmlSaveOptions saveOptions = new OoxmlSaveOptions { Password = "Aspose.Words" };
                                                                                   LoadOptions loadOptions = new LoadOptions() { IgnoreOleData = true };
                                                                                   Converter.Create(new ConverterContext())
                                                                                       .From(doc, loadOptions)
                                                                                       .To(ArtifactsDir + "LowCode.ConvertContext.3.docx", saveOptions)
                                                                                       .Execute();

                                                                                   Converter.Create(new ConverterContext())
                                                                                       .From(doc)
                                                                                       .To(ArtifactsDir + "LowCode.ConvertContext.4.png", new ImageSaveOptions(SaveFormat.Png))
                                                                                       .Execute();

Shows how to merge documents into a single output document using context.

//There is a several ways to merge documents:
                                                                                    string inputDoc1 = MyDir + "Big document.docx";
                                                                                    string inputDoc2 = MyDir + "Tables.docx";

                                                                                    Merger.Create(new MergerContext() { MergeFormatMode = MergeFormatMode.KeepSourceFormatting })
                                                                                        .From(inputDoc1)
                                                                                        .From(inputDoc2)
                                                                                        .To(ArtifactsDir + "LowCode.MergeContextDocuments.1.docx")
                                                                                        .Execute();

                                                                                    LoadOptions firstLoadOptions = new LoadOptions() { IgnoreOleData = true };
                                                                                    LoadOptions secondLoadOptions = new LoadOptions() { IgnoreOleData = false };
                                                                                    Merger.Create(new MergerContext() { MergeFormatMode = MergeFormatMode.KeepSourceFormatting })
                                                                                        .From(inputDoc1, firstLoadOptions)
                                                                                        .From(inputDoc2, secondLoadOptions)
                                                                                        .To(ArtifactsDir + "LowCode.MergeContextDocuments.2.docx", SaveFormat.Docx)
                                                                                        .Execute();

                                                                                    OoxmlSaveOptions saveOptions = new OoxmlSaveOptions { Password = "Aspose.Words" };
                                                                                    Merger.Create(new MergerContext() { MergeFormatMode = MergeFormatMode.KeepSourceFormatting })
                                                                                        .From(inputDoc1)
                                                                                        .From(inputDoc2)
                                                                                        .To(ArtifactsDir + "LowCode.MergeContextDocuments.3.docx", saveOptions)
                                                                                        .Execute();

Remarks

If the processor accepts only one file as an input, only the last specified file will be processed. Aspose.Words.LowCode.Merger processor accepts multiple files as an input, as the result all the specified documents will be merged. Aspose.Words.LowCode.Converter processor accepts only one file as an input, so only the last specified file will be converted.

From(Stream)

Specifies input document for processing.

public Processor From(Stream input)

Parameters

input Stream

Input document stream.

Returns

Processor

Returns processor with specified input file stream.

Remarks

If the processor accepts only one file as an input, only the last specified file will be processed. Aspose.Words.LowCode.Merger processor accepts multiple files as an input, as the result all the specified documents will be merged. Aspose.Words.LowCode.Converter processor accepts only one file as an input, so only the last specified file will be converted.

From(Stream, LoadOptions)

Specifies input document for processing.

public Processor From(Stream input, LoadOptions loadOptions)

Parameters

input Stream

Input document stream.

loadOptions LoadOptions

Optional load options used to load the document.

Returns

Processor

Returns processor with specified input file stream.

Examples

Shows how to convert documents from a stream with a single line of code using context.

string doc = MyDir + "Document.docx";
                                                                                                 using (FileStream streamIn = new FileStream(MyDir + "Big document.docx", FileMode.Open, FileAccess.Read))
                                                                                                 {
                                                                                                     using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.ConvertContextStream.1.docx", FileMode.Create, FileAccess.ReadWrite))
                                                                                                         Converter.Create(new ConverterContext())
                                                                                                             .From(streamIn)
                                                                                                             .To(streamOut, SaveFormat.Rtf)
                                                                                                             .Execute();

                                                                                                     OoxmlSaveOptions saveOptions = new OoxmlSaveOptions { Password = "Aspose.Words" };
                                                                                                     LoadOptions loadOptions = new LoadOptions() { IgnoreOleData = true };
                                                                                                     using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.ConvertContextStream.2.docx", FileMode.Create, FileAccess.ReadWrite))
                                                                                                         Converter.Create(new ConverterContext())
                                                                                                             .From(streamIn, loadOptions)
                                                                                                             .To(streamOut, saveOptions)
                                                                                                             .Execute();

                                                                                                     List<Stream> pages = new List<Stream>();
                                                                                                     Converter.Create(new ConverterContext())
                                                                                                         .From(doc)
                                                                                                         .To(pages, new ImageSaveOptions(SaveFormat.Png))
                                                                                                         .Execute();
                                                                                                 }

Shows how to merge documents from stream into a single output document using context.

//There is a several ways to merge documents:
                                                                                                string inputDoc1 = MyDir + "Big document.docx";
                                                                                                string inputDoc2 = MyDir + "Tables.docx";

                                                                                                using (FileStream firstStreamIn = new FileStream(MyDir + "Big document.docx", FileMode.Open, FileAccess.Read))
                                                                                                {
                                                                                                    using (FileStream secondStreamIn = new FileStream(MyDir + "Tables.docx", FileMode.Open, FileAccess.Read))
                                                                                                    {
                                                                                                        OoxmlSaveOptions saveOptions = new OoxmlSaveOptions { Password = "Aspose.Words" };
                                                                                                        using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MergeStreamContextDocuments.1.docx", FileMode.Create, FileAccess.ReadWrite))
                                                                                                            Merger.Create(new MergerContext() { MergeFormatMode = MergeFormatMode.KeepSourceFormatting })
                                                                                                            .From(firstStreamIn)
                                                                                                            .From(secondStreamIn)
                                                                                                            .To(streamOut, saveOptions)
                                                                                                            .Execute();

                                                                                                        LoadOptions firstLoadOptions = new LoadOptions() { IgnoreOleData = true };
                                                                                                        LoadOptions secondLoadOptions = new LoadOptions() { IgnoreOleData = false };
                                                                                                        using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MergeStreamContextDocuments.2.docx", FileMode.Create, FileAccess.ReadWrite))
                                                                                                            Merger.Create(new MergerContext() { MergeFormatMode = MergeFormatMode.KeepSourceFormatting })
                                                                                                            .From(firstStreamIn, firstLoadOptions)
                                                                                                            .From(secondStreamIn, secondLoadOptions)
                                                                                                            .To(streamOut, SaveFormat.Docx)
                                                                                                            .Execute();
                                                                                                    }
                                                                                                }

Remarks

If the processor accepts only one file as an input, only the last specified file will be processed. Aspose.Words.LowCode.Merger processor accepts multiple files as an input, as the result all the specified documents will be merged. Aspose.Words.LowCode.Converter processor accepts only one file as an input, so only the last specified file will be converted.

GetPartFileName(string, int, SaveFormat)

protected static string GetPartFileName(string fileName, int partIndex, SaveFormat saveFormat)

Parameters

fileName string

partIndex int

saveFormat SaveFormat

Returns

string

To(string)

Specifies output file for the processor.

public Processor To(string output)

Parameters

output string

Output file name.

Returns

Processor

Returns processor with specified output file.

Remarks

If the output consists of multiple files, the specified output file name is used to generate the file name for each part following the rule: ‘outputFile_partIndex.extension’.

To(string, SaveOptions)

Specifies output file for the processor.

public Processor To(string output, SaveOptions saveOptions)

Parameters

output string

Output file name.

saveOptions SaveOptions

Optional save options. If not specified, save format is determined by the file extension.

Returns

Processor

Returns processor with specified output file.

Examples

Shows how to convert documents with a single line of code using context.

string doc = MyDir + "Big document.docx";

                                                                                   Converter.Create(new ConverterContext())
                                                                                       .From(doc)
                                                                                       .To(ArtifactsDir + "LowCode.ConvertContext.1.pdf")
                                                                                       .Execute();

                                                                                   Converter.Create(new ConverterContext())
                                                                                       .From(doc)
                                                                                       .To(ArtifactsDir + "LowCode.ConvertContext.2.pdf", SaveFormat.Rtf)
                                                                                       .Execute();

                                                                                   OoxmlSaveOptions saveOptions = new OoxmlSaveOptions { Password = "Aspose.Words" };
                                                                                   LoadOptions loadOptions = new LoadOptions() { IgnoreOleData = true };
                                                                                   Converter.Create(new ConverterContext())
                                                                                       .From(doc, loadOptions)
                                                                                       .To(ArtifactsDir + "LowCode.ConvertContext.3.docx", saveOptions)
                                                                                       .Execute();

                                                                                   Converter.Create(new ConverterContext())
                                                                                       .From(doc)
                                                                                       .To(ArtifactsDir + "LowCode.ConvertContext.4.png", new ImageSaveOptions(SaveFormat.Png))
                                                                                       .Execute();

Shows how to merge documents into a single output document using context.

//There is a several ways to merge documents:
                                                                                    string inputDoc1 = MyDir + "Big document.docx";
                                                                                    string inputDoc2 = MyDir + "Tables.docx";

                                                                                    Merger.Create(new MergerContext() { MergeFormatMode = MergeFormatMode.KeepSourceFormatting })
                                                                                        .From(inputDoc1)
                                                                                        .From(inputDoc2)
                                                                                        .To(ArtifactsDir + "LowCode.MergeContextDocuments.1.docx")
                                                                                        .Execute();

                                                                                    LoadOptions firstLoadOptions = new LoadOptions() { IgnoreOleData = true };
                                                                                    LoadOptions secondLoadOptions = new LoadOptions() { IgnoreOleData = false };
                                                                                    Merger.Create(new MergerContext() { MergeFormatMode = MergeFormatMode.KeepSourceFormatting })
                                                                                        .From(inputDoc1, firstLoadOptions)
                                                                                        .From(inputDoc2, secondLoadOptions)
                                                                                        .To(ArtifactsDir + "LowCode.MergeContextDocuments.2.docx", SaveFormat.Docx)
                                                                                        .Execute();

                                                                                    OoxmlSaveOptions saveOptions = new OoxmlSaveOptions { Password = "Aspose.Words" };
                                                                                    Merger.Create(new MergerContext() { MergeFormatMode = MergeFormatMode.KeepSourceFormatting })
                                                                                        .From(inputDoc1)
                                                                                        .From(inputDoc2)
                                                                                        .To(ArtifactsDir + "LowCode.MergeContextDocuments.3.docx", saveOptions)
                                                                                        .Execute();

Remarks

If the output consists of multiple files, the specified output file name is used to generate the file name for each part following the rule: ‘outputFile_partIndex.extension’.

To(string, SaveFormat)

Specifies output file for the processor.

public Processor To(string output, SaveFormat saveFormat)

Parameters

output string

Output file name.

saveFormat SaveFormat

Save format. If not specified, save format is determined by the file extension.

Returns

Processor

Returns processor with specified output file.

Examples

Shows how to merge documents into a single output document using context.

//There is a several ways to merge documents:
                                                                                    string inputDoc1 = MyDir + "Big document.docx";
                                                                                    string inputDoc2 = MyDir + "Tables.docx";

                                                                                    Merger.Create(new MergerContext() { MergeFormatMode = MergeFormatMode.KeepSourceFormatting })
                                                                                        .From(inputDoc1)
                                                                                        .From(inputDoc2)
                                                                                        .To(ArtifactsDir + "LowCode.MergeContextDocuments.1.docx")
                                                                                        .Execute();

                                                                                    LoadOptions firstLoadOptions = new LoadOptions() { IgnoreOleData = true };
                                                                                    LoadOptions secondLoadOptions = new LoadOptions() { IgnoreOleData = false };
                                                                                    Merger.Create(new MergerContext() { MergeFormatMode = MergeFormatMode.KeepSourceFormatting })
                                                                                        .From(inputDoc1, firstLoadOptions)
                                                                                        .From(inputDoc2, secondLoadOptions)
                                                                                        .To(ArtifactsDir + "LowCode.MergeContextDocuments.2.docx", SaveFormat.Docx)
                                                                                        .Execute();

                                                                                    OoxmlSaveOptions saveOptions = new OoxmlSaveOptions { Password = "Aspose.Words" };
                                                                                    Merger.Create(new MergerContext() { MergeFormatMode = MergeFormatMode.KeepSourceFormatting })
                                                                                        .From(inputDoc1)
                                                                                        .From(inputDoc2)
                                                                                        .To(ArtifactsDir + "LowCode.MergeContextDocuments.3.docx", saveOptions)
                                                                                        .Execute();

Remarks

If the output consists of multiple files, the specified output file name is used to generate the file name for each part following the rule: ‘outputFile_partIndex.extension’.

To(Stream, SaveOptions)

Specifies output stream for the processor.

public Processor To(Stream output, SaveOptions saveOptions)

Parameters

output Stream

Output stream.

saveOptions SaveOptions

Save options.

Returns

Processor

Returns processor with specified output stream.

Examples

Shows how to convert documents from a stream with a single line of code using context.

string doc = MyDir + "Document.docx";
                                                                                                 using (FileStream streamIn = new FileStream(MyDir + "Big document.docx", FileMode.Open, FileAccess.Read))
                                                                                                 {
                                                                                                     using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.ConvertContextStream.1.docx", FileMode.Create, FileAccess.ReadWrite))
                                                                                                         Converter.Create(new ConverterContext())
                                                                                                             .From(streamIn)
                                                                                                             .To(streamOut, SaveFormat.Rtf)
                                                                                                             .Execute();

                                                                                                     OoxmlSaveOptions saveOptions = new OoxmlSaveOptions { Password = "Aspose.Words" };
                                                                                                     LoadOptions loadOptions = new LoadOptions() { IgnoreOleData = true };
                                                                                                     using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.ConvertContextStream.2.docx", FileMode.Create, FileAccess.ReadWrite))
                                                                                                         Converter.Create(new ConverterContext())
                                                                                                             .From(streamIn, loadOptions)
                                                                                                             .To(streamOut, saveOptions)
                                                                                                             .Execute();

                                                                                                     List<Stream> pages = new List<Stream>();
                                                                                                     Converter.Create(new ConverterContext())
                                                                                                         .From(doc)
                                                                                                         .To(pages, new ImageSaveOptions(SaveFormat.Png))
                                                                                                         .Execute();
                                                                                                 }

Shows how to merge documents from stream into a single output document using context.

//There is a several ways to merge documents:
                                                                                                string inputDoc1 = MyDir + "Big document.docx";
                                                                                                string inputDoc2 = MyDir + "Tables.docx";

                                                                                                using (FileStream firstStreamIn = new FileStream(MyDir + "Big document.docx", FileMode.Open, FileAccess.Read))
                                                                                                {
                                                                                                    using (FileStream secondStreamIn = new FileStream(MyDir + "Tables.docx", FileMode.Open, FileAccess.Read))
                                                                                                    {
                                                                                                        OoxmlSaveOptions saveOptions = new OoxmlSaveOptions { Password = "Aspose.Words" };
                                                                                                        using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MergeStreamContextDocuments.1.docx", FileMode.Create, FileAccess.ReadWrite))
                                                                                                            Merger.Create(new MergerContext() { MergeFormatMode = MergeFormatMode.KeepSourceFormatting })
                                                                                                            .From(firstStreamIn)
                                                                                                            .From(secondStreamIn)
                                                                                                            .To(streamOut, saveOptions)
                                                                                                            .Execute();

                                                                                                        LoadOptions firstLoadOptions = new LoadOptions() { IgnoreOleData = true };
                                                                                                        LoadOptions secondLoadOptions = new LoadOptions() { IgnoreOleData = false };
                                                                                                        using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MergeStreamContextDocuments.2.docx", FileMode.Create, FileAccess.ReadWrite))
                                                                                                            Merger.Create(new MergerContext() { MergeFormatMode = MergeFormatMode.KeepSourceFormatting })
                                                                                                            .From(firstStreamIn, firstLoadOptions)
                                                                                                            .From(secondStreamIn, secondLoadOptions)
                                                                                                            .To(streamOut, SaveFormat.Docx)
                                                                                                            .Execute();
                                                                                                    }
                                                                                                }

Remarks

If the output consists of multiple files, only the first part will be saved to the specified stream.

To(Stream, SaveFormat)

Specifies output stream for the processor.

public Processor To(Stream output, SaveFormat saveFormat)

Parameters

output Stream

Output stream.

saveFormat SaveFormat

Save format.

Returns

Processor

Returns processor with specified output stream.

Examples

Shows how to convert documents from a stream with a single line of code using context.

string doc = MyDir + "Document.docx";
                                                                                                 using (FileStream streamIn = new FileStream(MyDir + "Big document.docx", FileMode.Open, FileAccess.Read))
                                                                                                 {
                                                                                                     using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.ConvertContextStream.1.docx", FileMode.Create, FileAccess.ReadWrite))
                                                                                                         Converter.Create(new ConverterContext())
                                                                                                             .From(streamIn)
                                                                                                             .To(streamOut, SaveFormat.Rtf)
                                                                                                             .Execute();

                                                                                                     OoxmlSaveOptions saveOptions = new OoxmlSaveOptions { Password = "Aspose.Words" };
                                                                                                     LoadOptions loadOptions = new LoadOptions() { IgnoreOleData = true };
                                                                                                     using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.ConvertContextStream.2.docx", FileMode.Create, FileAccess.ReadWrite))
                                                                                                         Converter.Create(new ConverterContext())
                                                                                                             .From(streamIn, loadOptions)
                                                                                                             .To(streamOut, saveOptions)
                                                                                                             .Execute();

                                                                                                     List<Stream> pages = new List<Stream>();
                                                                                                     Converter.Create(new ConverterContext())
                                                                                                         .From(doc)
                                                                                                         .To(pages, new ImageSaveOptions(SaveFormat.Png))
                                                                                                         .Execute();
                                                                                                 }

Shows how to merge documents from stream into a single output document using context.

//There is a several ways to merge documents:
                                                                                                string inputDoc1 = MyDir + "Big document.docx";
                                                                                                string inputDoc2 = MyDir + "Tables.docx";

                                                                                                using (FileStream firstStreamIn = new FileStream(MyDir + "Big document.docx", FileMode.Open, FileAccess.Read))
                                                                                                {
                                                                                                    using (FileStream secondStreamIn = new FileStream(MyDir + "Tables.docx", FileMode.Open, FileAccess.Read))
                                                                                                    {
                                                                                                        OoxmlSaveOptions saveOptions = new OoxmlSaveOptions { Password = "Aspose.Words" };
                                                                                                        using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MergeStreamContextDocuments.1.docx", FileMode.Create, FileAccess.ReadWrite))
                                                                                                            Merger.Create(new MergerContext() { MergeFormatMode = MergeFormatMode.KeepSourceFormatting })
                                                                                                            .From(firstStreamIn)
                                                                                                            .From(secondStreamIn)
                                                                                                            .To(streamOut, saveOptions)
                                                                                                            .Execute();

                                                                                                        LoadOptions firstLoadOptions = new LoadOptions() { IgnoreOleData = true };
                                                                                                        LoadOptions secondLoadOptions = new LoadOptions() { IgnoreOleData = false };
                                                                                                        using (FileStream streamOut = new FileStream(ArtifactsDir + "LowCode.MergeStreamContextDocuments.2.docx", FileMode.Create, FileAccess.ReadWrite))
                                                                                                            Merger.Create(new MergerContext() { MergeFormatMode = MergeFormatMode.KeepSourceFormatting })
                                                                                                            .From(firstStreamIn, firstLoadOptions)
                                                                                                            .From(secondStreamIn, secondLoadOptions)
                                                                                                            .To(streamOut, SaveFormat.Docx)
                                                                                                            .Execute();
                                                                                                    }
                                                                                                }

Remarks

If the output consists of multiple files, only the first part will be saved to the specified stream.

To(List<Stream>, SaveOptions)

Specifies output Document streams list.

public Processor To(List<Stream> output, SaveOptions saveOptions)

Parameters

output List < Stream >

Output document streams list.

saveOptions SaveOptions

Save options.

Returns

Processor

Returns processor with specified output document streams list.

Remarks

If the output consists of multiple files (such as images or split document parts), a stream for each part is added to the specified list. If the output is a single file, only one stream is added to the list. It is the end user’s responsibility to dispose of the created streams.

To(List<Stream>, SaveFormat)

Specifies output Document streams list.

public Processor To(List<Stream> output, SaveFormat saveFormat)

Parameters

output List < Stream >

Output document streams list.

saveFormat SaveFormat

Save format.

Returns

Processor

Returns processor with specified output document streams list.

Remarks

If the output consists of multiple files (such as images or split document parts), a stream for each part is added to the specified list. If the output is a single file, only one stream is added to the list. It is the end user’s responsibility to dispose of the created streams.

 English