Processor
Inheritance: java.lang.Object
public class Processor
Processor class for performing different document processing actions.
Examples:
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.getColumns().add("FirstName");
dataTable.getColumns().add("Location");
dataTable.getColumns().add("SpecialCharsInName()");
dataTable.getRows().add(new String[]{"James Bond", "London", "Classified"});
try (FileInputStream streamIn = new FileInputStream(getMyDir() + "Mail merge.doc")) {
MailMergerContext mailMergerContext = new MailMergerContext();
mailMergerContext.setSimpleDataSource(dataTable);
mailMergerContext.getMailMergeOptions().setTrimWhitespaces(true);
try (FileOutputStream streamOut = new FileOutputStream(getArtifactsDir() + "LowCode.MailMergeContextStreamDataTable.docx")) {
MailMerger.create(mailMergerContext)
.from(streamIn)
.to(streamOut, SaveFormat.DOCX)
.execute();
}
}
Shows how to convert documents with a single line of code using context.
String doc = getMyDir() + "Big document.docx";
ConverterContext converterContext = new ConverterContext();
Converter.create(converterContext)
.from(doc)
.to(getArtifactsDir() + "LowCode.ConvertContext.1.pdf")
.execute();
Converter.create(converterContext)
.from(doc)
.to(getArtifactsDir() + "LowCode.ConvertContext.2.pdf", SaveFormat.RTF)
.execute();
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
{
saveOptions.setPassword("Aspose.Words");
}
LoadOptions loadOptions = new LoadOptions();
{
loadOptions.setIgnoreOleData(true);
}
Converter.create(converterContext)
.from(doc, loadOptions)
.to(getArtifactsDir() + "LowCode.ConvertContext.3.docx", saveOptions)
.execute();
Converter.create(converterContext)
.from(doc)
.to(getArtifactsDir() + "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 = getMyDir() + "Document.docx";
ConverterContext converterContext = new ConverterContext();
try (FileInputStream streamIn = new FileInputStream(doc)) {
try (FileOutputStream streamOut = new FileOutputStream(getArtifactsDir() + "LowCode.ConvertContextStream.1.docx")) {
Converter.create(converterContext)
.from(streamIn)
.to(streamOut, SaveFormat.RTF)
.execute();
}
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
{
saveOptions.setPassword("Aspose.Words");
}
LoadOptions loadOptions = new LoadOptions();
{
loadOptions.setIgnoreOleData(true);
}
try (FileOutputStream streamOut1 = new FileOutputStream(getArtifactsDir() + "LowCode.ConvertContextStream.2.docx")) {
Converter.create(converterContext)
.from(streamIn, loadOptions)
.to(streamOut1, saveOptions)
.execute();
}
}
Shows how to merge documents into a single output document using context.
//There is a several ways to merge documents:
String inputDoc1 = getMyDir() + "Big document.docx";
String inputDoc2 = getMyDir() + "Tables.docx";
MergerContext mergerContext = new MergerContext();
mergerContext.setMergeFormatMode(MergeFormatMode.KEEP_SOURCE_FORMATTING);
Merger.create(mergerContext)
.from(inputDoc1)
.from(inputDoc2)
.to(getArtifactsDir() + "LowCode.MergeContextDocuments.1.docx")
.execute();
LoadOptions firstLoadOptions = new LoadOptions();
{
firstLoadOptions.setIgnoreOleData(true);
}
LoadOptions secondLoadOptions = new LoadOptions();
{
secondLoadOptions.setIgnoreOleData(false);
}
Merger.create(mergerContext)
.from(inputDoc1, firstLoadOptions)
.from(inputDoc2, secondLoadOptions)
.to(getArtifactsDir() + "LowCode.MergeContextDocuments.2.docx", SaveFormat.DOCX)
.execute();
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
{
saveOptions.setPassword("Aspose.Words");
}
Merger.create(mergerContext)
.from(inputDoc1)
.from(inputDoc2)
.to(getArtifactsDir() + "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 = getMyDir() + "Big document.docx";
String inputDoc2 = getMyDir() + "Tables.docx";
MergerContext mergerContext = new MergerContext();
mergerContext.setMergeFormatMode(MergeFormatMode.KEEP_SOURCE_FORMATTING);
try (FileInputStream firstStreamIn = new FileInputStream(inputDoc1)) {
try (FileInputStream secondStreamIn = new FileInputStream(inputDoc2)) {
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
{
saveOptions.setPassword("Aspose.Words");
}
try (FileOutputStream streamOut = new FileOutputStream(getArtifactsDir() + "LowCode.MergeStreamContextDocuments.1.docx")) {
Merger.create(mergerContext)
.from(firstStreamIn)
.from(secondStreamIn)
.to(streamOut, saveOptions)
.execute();
}
LoadOptions firstLoadOptions = new LoadOptions();
{
firstLoadOptions.setIgnoreOleData(true);
}
LoadOptions secondLoadOptions = new LoadOptions();
{
secondLoadOptions.setIgnoreOleData(false);
}
try (FileOutputStream streamOut1 = new FileOutputStream(getArtifactsDir() + "LowCode.MergeStreamContextDocuments.2.docx")) {
Merger.create(mergerContext)
.from(firstStreamIn, firstLoadOptions)
.from(secondStreamIn, secondLoadOptions)
.to(streamOut1, SaveFormat.DOCX)
.execute();
}
}
}
Methods
Method | Description |
---|---|
execute() | Execute the processor action. |
from(InputStream input) | |
from(InputStream input, LoadOptions loadOptions) | Specifies input document for processing. |
from(String input) | |
from(String input, LoadOptions loadOptions) | Specifies input document for processing. |
to(OutputStream output, SaveOptions saveOptions) | |
to(OutputStream output, int saveFormat) | |
to(String output) | |
to(String output, SaveOptions saveOptions) | Specifies output file for the processor. |
to(String output, int saveFormat) | |
to(ArrayList output, SaveOptions saveOptions) | |
to(ArrayList output, int saveFormat) | |
toOutput(ArrayList output, SaveOptions saveOptions) | |
toOutput(ArrayList output, int saveFormat) |
execute()
public void execute()
Execute the processor action.
Examples:
Shows how to convert documents with a single line of code using context.
String doc = getMyDir() + "Big document.docx";
ConverterContext converterContext = new ConverterContext();
Converter.create(converterContext)
.from(doc)
.to(getArtifactsDir() + "LowCode.ConvertContext.1.pdf")
.execute();
Converter.create(converterContext)
.from(doc)
.to(getArtifactsDir() + "LowCode.ConvertContext.2.pdf", SaveFormat.RTF)
.execute();
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
{
saveOptions.setPassword("Aspose.Words");
}
LoadOptions loadOptions = new LoadOptions();
{
loadOptions.setIgnoreOleData(true);
}
Converter.create(converterContext)
.from(doc, loadOptions)
.to(getArtifactsDir() + "LowCode.ConvertContext.3.docx", saveOptions)
.execute();
Converter.create(converterContext)
.from(doc)
.to(getArtifactsDir() + "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 = getMyDir() + "Document.docx";
ConverterContext converterContext = new ConverterContext();
try (FileInputStream streamIn = new FileInputStream(doc)) {
try (FileOutputStream streamOut = new FileOutputStream(getArtifactsDir() + "LowCode.ConvertContextStream.1.docx")) {
Converter.create(converterContext)
.from(streamIn)
.to(streamOut, SaveFormat.RTF)
.execute();
}
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
{
saveOptions.setPassword("Aspose.Words");
}
LoadOptions loadOptions = new LoadOptions();
{
loadOptions.setIgnoreOleData(true);
}
try (FileOutputStream streamOut1 = new FileOutputStream(getArtifactsDir() + "LowCode.ConvertContextStream.2.docx")) {
Converter.create(converterContext)
.from(streamIn, loadOptions)
.to(streamOut1, saveOptions)
.execute();
}
}
Shows how to merge documents into a single output document using context.
//There is a several ways to merge documents:
String inputDoc1 = getMyDir() + "Big document.docx";
String inputDoc2 = getMyDir() + "Tables.docx";
MergerContext mergerContext = new MergerContext();
mergerContext.setMergeFormatMode(MergeFormatMode.KEEP_SOURCE_FORMATTING);
Merger.create(mergerContext)
.from(inputDoc1)
.from(inputDoc2)
.to(getArtifactsDir() + "LowCode.MergeContextDocuments.1.docx")
.execute();
LoadOptions firstLoadOptions = new LoadOptions();
{
firstLoadOptions.setIgnoreOleData(true);
}
LoadOptions secondLoadOptions = new LoadOptions();
{
secondLoadOptions.setIgnoreOleData(false);
}
Merger.create(mergerContext)
.from(inputDoc1, firstLoadOptions)
.from(inputDoc2, secondLoadOptions)
.to(getArtifactsDir() + "LowCode.MergeContextDocuments.2.docx", SaveFormat.DOCX)
.execute();
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
{
saveOptions.setPassword("Aspose.Words");
}
Merger.create(mergerContext)
.from(inputDoc1)
.from(inputDoc2)
.to(getArtifactsDir() + "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 = getMyDir() + "Big document.docx";
String inputDoc2 = getMyDir() + "Tables.docx";
MergerContext mergerContext = new MergerContext();
mergerContext.setMergeFormatMode(MergeFormatMode.KEEP_SOURCE_FORMATTING);
try (FileInputStream firstStreamIn = new FileInputStream(inputDoc1)) {
try (FileInputStream secondStreamIn = new FileInputStream(inputDoc2)) {
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
{
saveOptions.setPassword("Aspose.Words");
}
try (FileOutputStream streamOut = new FileOutputStream(getArtifactsDir() + "LowCode.MergeStreamContextDocuments.1.docx")) {
Merger.create(mergerContext)
.from(firstStreamIn)
.from(secondStreamIn)
.to(streamOut, saveOptions)
.execute();
}
LoadOptions firstLoadOptions = new LoadOptions();
{
firstLoadOptions.setIgnoreOleData(true);
}
LoadOptions secondLoadOptions = new LoadOptions();
{
secondLoadOptions.setIgnoreOleData(false);
}
try (FileOutputStream streamOut1 = new FileOutputStream(getArtifactsDir() + "LowCode.MergeStreamContextDocuments.2.docx")) {
Merger.create(mergerContext)
.from(firstStreamIn, firstLoadOptions)
.from(secondStreamIn, secondLoadOptions)
.to(streamOut1, SaveFormat.DOCX)
.execute();
}
}
}
from(InputStream input)
public Processor from(InputStream input)
Parameters:
Parameter | Type | Description |
---|---|---|
input | java.io.InputStream |
Returns: Processor
from(InputStream input, LoadOptions loadOptions)
public Processor from(InputStream input, LoadOptions loadOptions)
Specifies input document for processing.
Remarks:
If the processor accepts only one file as an input, only the last specified file will be processed. Merger processor accepts multiple files as an input, as the result all the specified documents will be merged. Converter processor accepts only one file as an input, so only the last specified file will be converted.
Examples:
Shows how to convert documents from a stream with a single line of code using context.
String doc = getMyDir() + "Document.docx";
ConverterContext converterContext = new ConverterContext();
try (FileInputStream streamIn = new FileInputStream(doc)) {
try (FileOutputStream streamOut = new FileOutputStream(getArtifactsDir() + "LowCode.ConvertContextStream.1.docx")) {
Converter.create(converterContext)
.from(streamIn)
.to(streamOut, SaveFormat.RTF)
.execute();
}
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
{
saveOptions.setPassword("Aspose.Words");
}
LoadOptions loadOptions = new LoadOptions();
{
loadOptions.setIgnoreOleData(true);
}
try (FileOutputStream streamOut1 = new FileOutputStream(getArtifactsDir() + "LowCode.ConvertContextStream.2.docx")) {
Converter.create(converterContext)
.from(streamIn, loadOptions)
.to(streamOut1, 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 = getMyDir() + "Big document.docx";
String inputDoc2 = getMyDir() + "Tables.docx";
MergerContext mergerContext = new MergerContext();
mergerContext.setMergeFormatMode(MergeFormatMode.KEEP_SOURCE_FORMATTING);
try (FileInputStream firstStreamIn = new FileInputStream(inputDoc1)) {
try (FileInputStream secondStreamIn = new FileInputStream(inputDoc2)) {
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
{
saveOptions.setPassword("Aspose.Words");
}
try (FileOutputStream streamOut = new FileOutputStream(getArtifactsDir() + "LowCode.MergeStreamContextDocuments.1.docx")) {
Merger.create(mergerContext)
.from(firstStreamIn)
.from(secondStreamIn)
.to(streamOut, saveOptions)
.execute();
}
LoadOptions firstLoadOptions = new LoadOptions();
{
firstLoadOptions.setIgnoreOleData(true);
}
LoadOptions secondLoadOptions = new LoadOptions();
{
secondLoadOptions.setIgnoreOleData(false);
}
try (FileOutputStream streamOut1 = new FileOutputStream(getArtifactsDir() + "LowCode.MergeStreamContextDocuments.2.docx")) {
Merger.create(mergerContext)
.from(firstStreamIn, firstLoadOptions)
.from(secondStreamIn, secondLoadOptions)
.to(streamOut1, SaveFormat.DOCX)
.execute();
}
}
}
Parameters:
Parameter | Type | Description |
---|---|---|
input | java.io.InputStream | Input document stream. |
loadOptions | LoadOptions | Optional load options used to load the document. |
Returns: Processor - Returns processor with specified input file stream.
from(String input)
public Processor from(String input)
Parameters:
Parameter | Type | Description |
---|---|---|
input | java.lang.String |
Returns: Processor
from(String input, LoadOptions loadOptions)
public Processor from(String input, LoadOptions loadOptions)
Specifies input document for processing.
Remarks:
If the processor accepts only one file as an input, only the last specified file will be processed. Merger processor accepts multiple files as an input, as the result all the specified documents will be merged. Converter processor accepts only one file as an input, so only the last specified file will be converted.
Examples:
Shows how to convert documents with a single line of code using context.
String doc = getMyDir() + "Big document.docx";
ConverterContext converterContext = new ConverterContext();
Converter.create(converterContext)
.from(doc)
.to(getArtifactsDir() + "LowCode.ConvertContext.1.pdf")
.execute();
Converter.create(converterContext)
.from(doc)
.to(getArtifactsDir() + "LowCode.ConvertContext.2.pdf", SaveFormat.RTF)
.execute();
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
{
saveOptions.setPassword("Aspose.Words");
}
LoadOptions loadOptions = new LoadOptions();
{
loadOptions.setIgnoreOleData(true);
}
Converter.create(converterContext)
.from(doc, loadOptions)
.to(getArtifactsDir() + "LowCode.ConvertContext.3.docx", saveOptions)
.execute();
Converter.create(converterContext)
.from(doc)
.to(getArtifactsDir() + "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 = getMyDir() + "Big document.docx";
String inputDoc2 = getMyDir() + "Tables.docx";
MergerContext mergerContext = new MergerContext();
mergerContext.setMergeFormatMode(MergeFormatMode.KEEP_SOURCE_FORMATTING);
Merger.create(mergerContext)
.from(inputDoc1)
.from(inputDoc2)
.to(getArtifactsDir() + "LowCode.MergeContextDocuments.1.docx")
.execute();
LoadOptions firstLoadOptions = new LoadOptions();
{
firstLoadOptions.setIgnoreOleData(true);
}
LoadOptions secondLoadOptions = new LoadOptions();
{
secondLoadOptions.setIgnoreOleData(false);
}
Merger.create(mergerContext)
.from(inputDoc1, firstLoadOptions)
.from(inputDoc2, secondLoadOptions)
.to(getArtifactsDir() + "LowCode.MergeContextDocuments.2.docx", SaveFormat.DOCX)
.execute();
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
{
saveOptions.setPassword("Aspose.Words");
}
Merger.create(mergerContext)
.from(inputDoc1)
.from(inputDoc2)
.to(getArtifactsDir() + "LowCode.MergeContextDocuments.3.docx", saveOptions)
.execute();
Parameters:
Parameter | Type | Description |
---|---|---|
input | java.lang.String | Input document file name. |
loadOptions | LoadOptions | Optional load options used to load the document. |
Returns: Processor - Returns processor with specified input file.
to(OutputStream output, SaveOptions saveOptions)
public Processor to(OutputStream output, SaveOptions saveOptions)
Parameters:
Parameter | Type | Description |
---|---|---|
output | java.io.OutputStream | |
saveOptions | SaveOptions |
Returns: Processor
to(OutputStream output, int saveFormat)
public Processor to(OutputStream output, int saveFormat)
Parameters:
Parameter | Type | Description |
---|---|---|
output | java.io.OutputStream | |
saveFormat | int |
Returns: Processor
to(String output)
public Processor to(String output)
Parameters:
Parameter | Type | Description |
---|---|---|
output | java.lang.String |
Returns: Processor
to(String output, SaveOptions saveOptions)
public Processor to(String output, SaveOptions saveOptions)
Specifies output file for the processor.
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’.
Examples:
Shows how to convert documents with a single line of code using context.
String doc = getMyDir() + "Big document.docx";
ConverterContext converterContext = new ConverterContext();
Converter.create(converterContext)
.from(doc)
.to(getArtifactsDir() + "LowCode.ConvertContext.1.pdf")
.execute();
Converter.create(converterContext)
.from(doc)
.to(getArtifactsDir() + "LowCode.ConvertContext.2.pdf", SaveFormat.RTF)
.execute();
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
{
saveOptions.setPassword("Aspose.Words");
}
LoadOptions loadOptions = new LoadOptions();
{
loadOptions.setIgnoreOleData(true);
}
Converter.create(converterContext)
.from(doc, loadOptions)
.to(getArtifactsDir() + "LowCode.ConvertContext.3.docx", saveOptions)
.execute();
Converter.create(converterContext)
.from(doc)
.to(getArtifactsDir() + "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 = getMyDir() + "Big document.docx";
String inputDoc2 = getMyDir() + "Tables.docx";
MergerContext mergerContext = new MergerContext();
mergerContext.setMergeFormatMode(MergeFormatMode.KEEP_SOURCE_FORMATTING);
Merger.create(mergerContext)
.from(inputDoc1)
.from(inputDoc2)
.to(getArtifactsDir() + "LowCode.MergeContextDocuments.1.docx")
.execute();
LoadOptions firstLoadOptions = new LoadOptions();
{
firstLoadOptions.setIgnoreOleData(true);
}
LoadOptions secondLoadOptions = new LoadOptions();
{
secondLoadOptions.setIgnoreOleData(false);
}
Merger.create(mergerContext)
.from(inputDoc1, firstLoadOptions)
.from(inputDoc2, secondLoadOptions)
.to(getArtifactsDir() + "LowCode.MergeContextDocuments.2.docx", SaveFormat.DOCX)
.execute();
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
{
saveOptions.setPassword("Aspose.Words");
}
Merger.create(mergerContext)
.from(inputDoc1)
.from(inputDoc2)
.to(getArtifactsDir() + "LowCode.MergeContextDocuments.3.docx", saveOptions)
.execute();
Parameters:
Parameter | Type | Description |
---|---|---|
output | java.lang.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.
to(String output, int saveFormat)
public Processor to(String output, int saveFormat)
Parameters:
Parameter | Type | Description |
---|---|---|
output | java.lang.String | |
saveFormat | int |
Returns: Processor
to(ArrayList output, SaveOptions saveOptions)
public Processor to(ArrayList output, SaveOptions saveOptions)
Parameters:
Parameter | Type | Description |
---|---|---|
output | java.util.ArrayList | |
saveOptions | SaveOptions |
Returns: Processor
to(ArrayList output, int saveFormat)
public Processor to(ArrayList output, int saveFormat)
Parameters:
Parameter | Type | Description |
---|---|---|
output | java.util.ArrayList | |
saveFormat | int |
Returns: Processor
toOutput(ArrayList output, SaveOptions saveOptions)
public Processor toOutput(ArrayList output, SaveOptions saveOptions)
Parameters:
Parameter | Type | Description |
---|---|---|
output | java.util.ArrayList | |
saveOptions | SaveOptions |
Returns: Processor
toOutput(ArrayList output, int saveFormat)
public Processor toOutput(ArrayList output, int saveFormat)
Parameters:
Parameter | Type | Description |
---|---|---|
output | java.util.ArrayList | |
saveFormat | int |
Returns: Processor