ReplaceToImages

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

用替换字符串替换输入文件中所有出现的指定字符串模式。 将输出渲染为图像。

public static Stream[] ReplaceToImages(string inputFileName, ImageSaveOptions saveOptions, 
    string pattern, string replacement, FindReplaceOptions options = null)
范围类型描述
inputFileNameString输入文件名。
saveOptionsImageSaveOptions保存选项。
patternString要替换的字符串。
replacementString用于替换所有出现的模式的字符串。
optionsFindReplaceOptionsFindReplaceOptions对象来指定附加选项。

例子

展示如何替换文档中的字符串并将结果保存为图像。

// 有几种方法可以替换文档中的字符串:
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);

也可以看看


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

用替换字符串替换输入文件中所有出现的指定字符串模式。 将输出渲染为图像。

public static Stream[] ReplaceToImages(Stream inputStream, ImageSaveOptions saveOptions, 
    string pattern, string replacement, FindReplaceOptions options = null)
范围类型描述
inputStreamStream输入文件流。
saveOptionsImageSaveOptions保存选项。
patternString要替换的字符串。
replacementString用于替换所有出现的模式的字符串。
optionsFindReplaceOptionsFindReplaceOptions对象来指定附加选项。

例子

展示如何使用流中的文档替换文档中的字符串并将结果保存为图像。

// 有几种方法可以使用流中的文档替换文档中的字符串:
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);
}

也可以看看


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

用替换字符串替换输入文件中所有出现的指定正则表达式模式。 将输出呈现为图像。

public static Stream[] ReplaceToImages(string inputFileName, ImageSaveOptions saveOptions, 
    Regex pattern, string replacement, FindReplaceOptions options = null)
范围类型描述
inputFileNameString输入文件名。
saveOptionsImageSaveOptions保存选项。
patternRegex用于查找匹配项的正则表达式模式。
replacementString用于替换所有出现的模式的字符串。
optionsFindReplaceOptionsFindReplaceOptions对象来指定附加选项。

例子

展示如何在文档中用正则表达式替换字符串并将结果保存为图像。

// 有几种方法可以在文档中使用正则表达式替换字符串:
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 });

也可以看看


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

用替换字符串替换输入文件中所有出现的指定正则表达式模式。 将输出呈现为图像。

public static Stream[] ReplaceToImages(Stream inputStream, ImageSaveOptions saveOptions, 
    Regex pattern, string replacement, FindReplaceOptions options = null)
范围类型描述
inputStreamStream输入文件流。
saveOptionsImageSaveOptions保存选项。
patternRegex用于查找匹配项的正则表达式模式。
replacementString用于替换所有出现的模式的字符串。
optionsFindReplaceOptionsFindReplaceOptions对象来指定附加选项。

例子

展示如何使用流中的文档用正则表达式替换文档中的字符串并将结果保存为图像。

// 有几种方法可以使用流中的文档将文档中的字符串替换为正则表达式:
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 });
}

也可以看看