Converter
Inheritance: java.lang.Object, com.aspose.words.Processor
public class Converter extends Processor
Represents a group of methods intended to convert a variety of different types of documents using a single line of code.
Remarks:
The specified input and output files or streams, along with the desired save format, are used to convert the given input document of the one format into the output document of the other specified format.
The convert functionality supports over 35+ different file formats.
The M:Aspose.Words.LowCode.Converter.ConvertToImages(System.String,Aspose.Words.SaveFormat) group of methods are designed to transform documents into images, with each page being converted into a separate image file. These methods also convert PDF documents directly to fixed-page formats without loading them into the document model, which enhances both performance and accuracy.
With ImageSaveOptions.getPageSet() / ImageSaveOptions.setPageSet(com.aspose.words.PageSet), you can specify a particular set of pages to convert into images.
Methods
convert(InputStream inputStream, LoadOptions loadOptions, OutputStream outputStream, SaveOptions saveOptions)
public static void convert(InputStream inputStream, LoadOptions loadOptions, OutputStream outputStream, SaveOptions saveOptions)
Parameters:
Parameter | Type | Description |
---|---|---|
inputStream | java.io.InputStream | |
loadOptions | LoadOptions | |
outputStream | java.io.OutputStream | |
saveOptions | SaveOptions |
convert(InputStream inputStream, OutputStream outputStream, SaveOptions saveOptions)
public static void convert(InputStream inputStream, OutputStream outputStream, SaveOptions saveOptions)
Parameters:
Parameter | Type | Description |
---|---|---|
inputStream | java.io.InputStream | |
outputStream | java.io.OutputStream | |
saveOptions | SaveOptions |
convert(InputStream inputStream, OutputStream outputStream, int saveFormat)
public static void convert(InputStream inputStream, OutputStream outputStream, int saveFormat)
Parameters:
Parameter | Type | Description |
---|---|---|
inputStream | java.io.InputStream | |
outputStream | java.io.OutputStream | |
saveFormat | int |
convert(String inputFile, LoadOptions loadOptions, String outputFile, SaveOptions saveOptions)
public static void convert(String inputFile, LoadOptions loadOptions, String outputFile, SaveOptions saveOptions)
Converts the given input document into the output document using specified input output file names its load/save options.
Remarks:
If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), each page of the output will be saved as a separate file. The specified output file name will be used to generate file names for each part following the rule: outputFile_partIndex.extension.
If the output format is TIFF, the output will be saved as a single multi-frame TIFF file.
Examples:
Shows how to convert documents with a single line of code.
String doc = getMyDir() + "Document.docx";
Converter.convert(doc, getArtifactsDir() + "LowCode.Convert.pdf");
Converter.convert(doc, getArtifactsDir() + "LowCode.Convert.SaveFormat.rtf", SaveFormat.RTF);
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
{
saveOptions.setPassword("Aspose.Words");
}
LoadOptions loadOptions = new LoadOptions();
{
loadOptions.setIgnoreOleData(true);
}
Converter.convert(doc, loadOptions, getArtifactsDir() + "LowCode.Convert.LoadOptions.docx", saveOptions);
Converter.convert(doc, getArtifactsDir() + "LowCode.Convert.SaveOptions.docx", saveOptions);
Parameters:
Parameter | Type | Description |
---|---|---|
inputFile | java.lang.String | The input file name. |
loadOptions | LoadOptions | The input document load options. |
outputFile | java.lang.String | The output file name. |
saveOptions | SaveOptions | The save options. |
convert(String inputFile, String outputFile)
public static void convert(String inputFile, String outputFile)
Converts the given input document into the output document using specified input output file names and its extensions.
Remarks:
If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), each page of the output will be saved as a separate file. The specified output file name will be used to generate file names for each part following the rule: outputFile_partIndex.extension.
If the output format is TIFF, the output will be saved as a single multi-frame TIFF file.
Examples:
Shows how to convert documents with a single line of code.
String doc = getMyDir() + "Document.docx";
Converter.convert(doc, getArtifactsDir() + "LowCode.Convert.pdf");
Converter.convert(doc, getArtifactsDir() + "LowCode.Convert.SaveFormat.rtf", SaveFormat.RTF);
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
{
saveOptions.setPassword("Aspose.Words");
}
LoadOptions loadOptions = new LoadOptions();
{
loadOptions.setIgnoreOleData(true);
}
Converter.convert(doc, loadOptions, getArtifactsDir() + "LowCode.Convert.LoadOptions.docx", saveOptions);
Converter.convert(doc, getArtifactsDir() + "LowCode.Convert.SaveOptions.docx", saveOptions);
Parameters:
Parameter | Type | Description |
---|---|---|
inputFile | java.lang.String | The input file name. |
outputFile | java.lang.String | The output file name. |
convert(String inputFile, String outputFile, SaveOptions saveOptions)
public static void convert(String inputFile, String outputFile, SaveOptions saveOptions)
Converts the given input document into the output document using specified input output file names and save options.
Remarks:
If the output format is an image (BMP, EMF, EPS, GIF, JPEG, PNG, or WebP), each page of the output will be saved as a separate file. The specified output file name will be used to generate file names for each part following the rule: outputFile_partIndex.extension.
If the output format is TIFF, the output will be saved as a single multi-frame TIFF file.
Examples:
Shows how to convert documents with a single line of code.
String doc = getMyDir() + "Document.docx";
Converter.convert(doc, getArtifactsDir() + "LowCode.Convert.pdf");
Converter.convert(doc, getArtifactsDir() + "LowCode.Convert.SaveFormat.rtf", SaveFormat.RTF);
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
{
saveOptions.setPassword("Aspose.Words");
}
LoadOptions loadOptions = new LoadOptions();
{
loadOptions.setIgnoreOleData(true);
}
Converter.convert(doc, loadOptions, getArtifactsDir() + "LowCode.Convert.LoadOptions.docx", saveOptions);
Converter.convert(doc, getArtifactsDir() + "LowCode.Convert.SaveOptions.docx", saveOptions);
Parameters:
Parameter | Type | Description |
---|---|---|
inputFile | java.lang.String | The input file name. |
outputFile | java.lang.String | The output file name. |
saveOptions | SaveOptions | The save options. |
convert(String inputFile, String outputFile, int saveFormat)
public static void convert(String inputFile, String outputFile, int saveFormat)
Parameters:
Parameter | Type | Description |
---|---|---|
inputFile | java.lang.String | |
outputFile | java.lang.String | |
saveFormat | int |
convertToImages(Document doc, ImageSaveOptions saveOptions)
public static OutputStream[] convertToImages(Document doc, ImageSaveOptions saveOptions)
Converts the pages of the specified document to images using the specified save options and returns an array of streams containing the images.
Examples:
Shows how to convert document to images stream.
String doc = getMyDir() + "Big document.docx";
OutputStream[] streams = Converter.convertToImages(doc, SaveFormat.PNG);
ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.PNG);
imageSaveOptions.setPageSet(new PageSet(1));
streams = Converter.convertToImages(doc, imageSaveOptions);
streams = Converter.convertToImages(new Document(doc), SaveFormat.PNG);
streams = Converter.convertToImages(new Document(doc), imageSaveOptions);
Parameters:
Parameter | Type | Description |
---|---|---|
doc | Document | The input document. |
saveOptions | ImageSaveOptions | Image save options. |
Returns: java.io.OutputStream[] - Returns array of image streams. The streams should be disposed by the end user.
convertToImages(Document doc, int saveFormat)
public static OutputStream[] convertToImages(Document doc, int saveFormat)
Parameters:
Parameter | Type | Description |
---|---|---|
doc | Document | |
saveFormat | int |
Returns: java.io.OutputStream[]
convertToImages(InputStream inputStream, ImageSaveOptions saveOptions)
public static OutputStream[] convertToImages(InputStream inputStream, ImageSaveOptions saveOptions)
Converts the pages of the specified input stream to images using the specified save options and returns an array of streams containing the images.
Examples:
Shows how to convert document to images from stream.
try (FileInputStream streamIn = new FileInputStream(getMyDir() + "Big document.docx")) {
OutputStream[] streams = Converter.convertToImages(streamIn, SaveFormat.JPEG);
ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.PNG);
imageSaveOptions.setPageSet(new PageSet(1));
streams = Converter.convertToImages(streamIn, imageSaveOptions);
LoadOptions loadOptions = new LoadOptions();
{
loadOptions.setIgnoreOleData(false);
}
Converter.convertToImages(streamIn, loadOptions, imageSaveOptions);
}
Parameters:
Parameter | Type | Description |
---|---|---|
inputStream | java.io.InputStream | The input stream. |
saveOptions | ImageSaveOptions | Image save options. |
Returns: java.io.OutputStream[] - Returns array of image streams. The streams should be disposed by the end user.
convertToImages(InputStream inputStream, LoadOptions loadOptions, ImageSaveOptions saveOptions)
public static OutputStream[] convertToImages(InputStream inputStream, LoadOptions loadOptions, ImageSaveOptions saveOptions)
Converts the pages of the specified input stream to images using the provided load and save options, and returns an array of streams containing the images.
Examples:
Shows how to convert document to images from stream.
try (FileInputStream streamIn = new FileInputStream(getMyDir() + "Big document.docx")) {
OutputStream[] streams = Converter.convertToImages(streamIn, SaveFormat.JPEG);
ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.PNG);
imageSaveOptions.setPageSet(new PageSet(1));
streams = Converter.convertToImages(streamIn, imageSaveOptions);
LoadOptions loadOptions = new LoadOptions();
{
loadOptions.setIgnoreOleData(false);
}
Converter.convertToImages(streamIn, loadOptions, imageSaveOptions);
}
Parameters:
Parameter | Type | Description |
---|---|---|
inputStream | java.io.InputStream | The input stream. |
loadOptions | LoadOptions | The input document load options. |
saveOptions | ImageSaveOptions | Image save options. |
Returns: java.io.OutputStream[] - Returns array of image streams. The streams should be disposed by the end user.
convertToImages(InputStream inputStream, int saveFormat)
public static OutputStream[] convertToImages(InputStream inputStream, int saveFormat)
Parameters:
Parameter | Type | Description |
---|---|---|
inputStream | java.io.InputStream | |
saveFormat | int |
Returns: java.io.OutputStream[]
convertToImages(String inputFile, ImageSaveOptions saveOptions)
public static OutputStream[] convertToImages(String inputFile, ImageSaveOptions saveOptions)
Converts the pages of the specified input file to images using the specified save options and returns an array of streams containing the images.
Examples:
Shows how to convert document to images stream.
String doc = getMyDir() + "Big document.docx";
OutputStream[] streams = Converter.convertToImages(doc, SaveFormat.PNG);
ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.PNG);
imageSaveOptions.setPageSet(new PageSet(1));
streams = Converter.convertToImages(doc, imageSaveOptions);
streams = Converter.convertToImages(new Document(doc), SaveFormat.PNG);
streams = Converter.convertToImages(new Document(doc), imageSaveOptions);
Parameters:
Parameter | Type | Description |
---|---|---|
inputFile | java.lang.String | The input file name. |
saveOptions | ImageSaveOptions | Image save options. |
Returns: java.io.OutputStream[] - Returns array of image streams. The streams should be disposed by the end user.
convertToImages(String inputFile, LoadOptions loadOptions, String outputFile, ImageSaveOptions saveOptions)
public static void convertToImages(String inputFile, LoadOptions loadOptions, String outputFile, ImageSaveOptions saveOptions)
Converts the pages of the specified input file to image files using the provided load and save options.
Examples:
Shows how to convert document to images.
String doc = getMyDir() + "Big document.docx";
Converter.convertToImages(doc, getArtifactsDir() + "LowCode.ConvertToImages.1.png");
Converter.convertToImages(doc, getArtifactsDir() + "LowCode.ConvertToImages.2.jpeg", SaveFormat.JPEG);
LoadOptions loadOptions = new LoadOptions();
{
loadOptions.setIgnoreOleData(false);
}
ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.PNG);
imageSaveOptions.setPageSet(new PageSet(1));
Converter.convertToImages(doc, loadOptions, getArtifactsDir() + "LowCode.ConvertToImages.3.png", imageSaveOptions);
Converter.convertToImages(doc, getArtifactsDir() + "LowCode.ConvertToImages.4.png", imageSaveOptions);
Parameters:
Parameter | Type | Description |
---|---|---|
inputFile | java.lang.String | The input file name. |
loadOptions | LoadOptions | The input document load options. |
outputFile | java.lang.String | The output file name used to generate file name for page images using rule “outputFile_pageIndex.extension” |
saveOptions | ImageSaveOptions | Image save options. |
convertToImages(String inputFile, int saveFormat)
public static OutputStream[] convertToImages(String inputFile, int saveFormat)
Parameters:
Parameter | Type | Description |
---|---|---|
inputFile | java.lang.String | |
saveFormat | int |
Returns: java.io.OutputStream[]
convertToImages(String inputFile, String outputFile)
public static void convertToImages(String inputFile, String outputFile)
Converts the pages of the specified input file to image files.
Examples:
Shows how to convert document to images.
String doc = getMyDir() + "Big document.docx";
Converter.convertToImages(doc, getArtifactsDir() + "LowCode.ConvertToImages.1.png");
Converter.convertToImages(doc, getArtifactsDir() + "LowCode.ConvertToImages.2.jpeg", SaveFormat.JPEG);
LoadOptions loadOptions = new LoadOptions();
{
loadOptions.setIgnoreOleData(false);
}
ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.PNG);
imageSaveOptions.setPageSet(new PageSet(1));
Converter.convertToImages(doc, loadOptions, getArtifactsDir() + "LowCode.ConvertToImages.3.png", imageSaveOptions);
Converter.convertToImages(doc, getArtifactsDir() + "LowCode.ConvertToImages.4.png", imageSaveOptions);
Parameters:
Parameter | Type | Description |
---|---|---|
inputFile | java.lang.String | The input file name. |
outputFile | java.lang.String | The output file name used to generate file name for page images using rule “outputFile_pageIndex.extension” |
convertToImages(String inputFile, String outputFile, ImageSaveOptions saveOptions)
public static void convertToImages(String inputFile, String outputFile, ImageSaveOptions saveOptions)
Converts the pages of the specified input file to image files using the specified save options.
Examples:
Shows how to convert document to images.
String doc = getMyDir() + "Big document.docx";
Converter.convertToImages(doc, getArtifactsDir() + "LowCode.ConvertToImages.1.png");
Converter.convertToImages(doc, getArtifactsDir() + "LowCode.ConvertToImages.2.jpeg", SaveFormat.JPEG);
LoadOptions loadOptions = new LoadOptions();
{
loadOptions.setIgnoreOleData(false);
}
ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.PNG);
imageSaveOptions.setPageSet(new PageSet(1));
Converter.convertToImages(doc, loadOptions, getArtifactsDir() + "LowCode.ConvertToImages.3.png", imageSaveOptions);
Converter.convertToImages(doc, getArtifactsDir() + "LowCode.ConvertToImages.4.png", imageSaveOptions);
Parameters:
Parameter | Type | Description |
---|---|---|
inputFile | java.lang.String | The input file name. |
outputFile | java.lang.String | The output file name used to generate file name for page images using rule “outputFile_pageIndex.extension” |
saveOptions | ImageSaveOptions | Image save options. |
convertToImages(String inputFile, String outputFile, int saveFormat)
public static void convertToImages(String inputFile, String outputFile, int saveFormat)
Parameters:
Parameter | Type | Description |
---|---|---|
inputFile | java.lang.String | |
outputFile | java.lang.String | |
saveFormat | int |
create()
public static Converter create()
Creates new instance of the converter processor.
Returns: Converter
create(ConverterContext context)
public static Converter create(ConverterContext context)
Creates new instance of the converter processor.
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();
}
}
Parameters:
Parameter | Type | Description |
---|---|---|
context | ConverterContext |
Returns: Converter
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