ReplaceToImages

ReplaceToImages(string, ImageSaveOptions, string, string, FindReplaceOptions)

Replaces all occurrences of a specified character string pattern with a replacement string in the input file. Renders output to images.

public static Stream[] ReplaceToImages(string inputFileName, ImageSaveOptions saveOptions, 
    string pattern, string replacement, FindReplaceOptions options = null)
ParameterTypeDescription
inputFileNameStringThe input file name.
saveOptionsImageSaveOptionsThe save options.
patternStringA string to be replaced.
replacementStringA string to replace all occurrences of pattern.
optionsFindReplaceOptionsFindReplaceOptions object to specify additional options.

Examples

Shows how to replace string in the document and save result to images.

// There is a several ways to replace string in the document:
string doc = MyDir + "Footer.docx";
string pattern = "(C)2006 Aspose Pty Ltd.";
string replacement = "Copyright (C) 2024 by Aspose Pty Ltd.";

Stream[] images = Replacer.ReplaceToImages(doc, new ImageSaveOptions(SaveFormat.Png), pattern, replacement);

FindReplaceOptions options = new FindReplaceOptions();
options.FindWholeWordsOnly = false;
images = Replacer.ReplaceToImages(doc, new ImageSaveOptions(SaveFormat.Png), pattern, replacement, options);

See Also


ReplaceToImages(Stream, ImageSaveOptions, string, string, FindReplaceOptions)

Replaces all occurrences of a specified character string pattern with a replacement string in the input file. Renders output to images.

public static Stream[] ReplaceToImages(Stream inputStream, ImageSaveOptions saveOptions, 
    string pattern, string replacement, FindReplaceOptions options = null)
ParameterTypeDescription
inputStreamStreamThe input file stream.
saveOptionsImageSaveOptionsThe save options.
patternStringA string to be replaced.
replacementStringA string to replace all occurrences of pattern.
optionsFindReplaceOptionsFindReplaceOptions object to specify additional options.

Examples

Shows how to replace string in the document using documents from the stream and save result to images.

// There is a several ways to replace string in the document using documents from the stream:
string pattern = "(C)2006 Aspose Pty Ltd.";
string replacement = "Copyright (C) 2024 by Aspose Pty Ltd.";

using (FileStream streamIn = new FileStream(MyDir + "Footer.docx", FileMode.Open, FileAccess.Read))
{
    Stream[] images = Replacer.ReplaceToImages(streamIn, new ImageSaveOptions(SaveFormat.Png), pattern, replacement);

    FindReplaceOptions options = new FindReplaceOptions();
    options.FindWholeWordsOnly = false;
    images = Replacer.ReplaceToImages(streamIn, new ImageSaveOptions(SaveFormat.Png), pattern, replacement, options);
}

See Also


ReplaceToImages(string, ImageSaveOptions, Regex, string, FindReplaceOptions)

Replaces all occurrences of a specified regular expression pattern with a replacement string in the input file. Renders output to images.

public static Stream[] ReplaceToImages(string inputFileName, ImageSaveOptions saveOptions, 
    Regex pattern, string replacement, FindReplaceOptions options = null)
ParameterTypeDescription
inputFileNameStringThe input file name.
saveOptionsImageSaveOptionsThe save options.
patternRegexA regular expression pattern used to find matches.
replacementStringA string to replace all occurrences of pattern.
optionsFindReplaceOptionsFindReplaceOptions object to specify additional options.

Examples

Shows how to replace string with regex in the document and save result to images.

// There is a several ways to replace string with regex in the document:
string doc = MyDir + "Footer.docx";
Regex pattern = new Regex("gr(a|e)y");
string replacement = "lavender";

Stream[] images = Replacer.ReplaceToImages(doc, new ImageSaveOptions(SaveFormat.Png), pattern, replacement);
images = Replacer.ReplaceToImages(doc, new ImageSaveOptions(SaveFormat.Png), pattern, replacement, new FindReplaceOptions() { FindWholeWordsOnly = false });

See Also


ReplaceToImages(Stream, ImageSaveOptions, Regex, string, FindReplaceOptions)

Replaces all occurrences of a specified regular expression pattern with a replacement string in the input file. Renders output to images.

public static Stream[] ReplaceToImages(Stream inputStream, ImageSaveOptions saveOptions, 
    Regex pattern, string replacement, FindReplaceOptions options = null)
ParameterTypeDescription
inputStreamStreamThe input file stream.
saveOptionsImageSaveOptionsThe save options.
patternRegexA regular expression pattern used to find matches.
replacementStringA string to replace all occurrences of pattern.
optionsFindReplaceOptionsFindReplaceOptions object to specify additional options.

Examples

Shows how to replace string with regex in the document using documents from the stream and save result to images.

// There is a several ways to replace string with regex in the document using documents from the stream:
Regex pattern = new Regex("gr(a|e)y");
string replacement = "lavender";

using (FileStream streamIn = new FileStream(MyDir + "Replace regex.docx", FileMode.Open, FileAccess.Read))
{
    Stream[] images = Replacer.ReplaceToImages(streamIn, new ImageSaveOptions(SaveFormat.Png), pattern, replacement);
    images = Replacer.ReplaceToImages(streamIn, new ImageSaveOptions(SaveFormat.Png), pattern, replacement, new FindReplaceOptions() { FindWholeWordsOnly = false });
}

See Also