ReplaceText

ReplaceText(string, int, string, TextState)

替换指定页面上 PDF 文件中的文本。TextState可以指定对象(字体系列,颜色)来替换文本。

public bool ReplaceText(string srcString, int thePage, string destString, TextState textState)
范围类型描述
srcStringString要替换的字符串。
thePageInt32页码(0 表示“所有页面”)。
destStringString被替换的字符串。
textStateTextState文本状态(文本颜色、字体等)。

返回值

如果进行了替换,则返回 true。

例子

示例演示如何替换PDF文档第一页的文本并设置TextState新文本的文本属性。

// 打开文档
Document doc = new Document(inFile);

// 创建字体并将其标记为嵌入
Aspose.Pdf.Text.Font font = FontRepository.FindFont("Courier New");
font.IsEmbedded = true;

// 创建 PdfContentEditor 对象来编辑文本
PdfContentEditor editor = new PdfContentEditor();
editor.BindPdf(doc);

// 创建文本状态对象
TextState textState = new TextState();
textState.Font = font;
textState.FontSize = 17;
textState.FontStyle = FontStyle.Bold | FontStyle.Italic;
textState.ForegroundColor = Color.Red;

// 改变指定字体的文本
editor.ReplaceText("hello world", 1, "hi world", textState);

// 保存文档
doc.Save(outFile);

也可以看看


ReplaceText(string, string)

替换 PDF 文件中的文本。

public bool ReplaceText(string srcString, string destString)
范围类型描述
srcStringString要替换的字符串。
destStringString替换字符串。

返回值

如果进行了替换,则返回 true。

例子

该示例演示如何替换 PDF 文档中的文本。

// 打开文档
Document doc = new Document(inFile);

// 创建 PdfContentEditor 对象来编辑文本
PdfContentEditor editor = new PdfContentEditor();
editor.BindPdf(doc);

// 改变文本 
editor.ReplaceText("hello world", "hi world");

// 保存文档
doc.Save(outFile);

也可以看看


ReplaceText(string, int, string)

替换指定页面上 PDF 文件中的文本。

public bool ReplaceText(string srcString, int thePage, string destString)
范围类型描述
srcStringString要更换的刺。
thePageInt32页码(所有页为 0)
destStringString替换字符串。

返回值

如果进行了替换,则返回 true。

例子

该示例演示了如何在指定页面上替换PDF文档中的文本。

// 打开文档
Document doc = new Document(inFile);

// 创建 PdfContentEditor 对象来编辑文本
PdfContentEditor editor = new PdfContentEditor();
editor.BindPdf(doc);

// 改变文本 
editor.ReplaceText("hello world", 1, "hi world");

// 保存文档
doc.Save(outFile);

也可以看看


ReplaceText(string, string, TextState)

使用指定的替换 PDF 文件中的文本TextState对象.

public bool ReplaceText(string srcString, string destString, TextState textState)
范围类型描述
srcStringString要替换的字符串
destStringString替换字符串
textStateTextState文本状态(文本颜色、字体等)

返回值

如果进行了替换,则返回 true。

例子

示例演示如何替换文本并设置TextState新文本的文本属性。

// 打开文档
Document doc = new Document(inFile);

// 创建字体并将其标记为嵌入
Aspose.Pdf.Text.Font font = FontRepository.FindFont("Courier New");
font.IsEmbedded = true;

// 创建 PdfContentEditor 对象来编辑文本
PdfContentEditor editor = new PdfContentEditor();
editor.BindPdf(doc);

// 创建文本状态对象
TextState textState = new TextState();
textState.Font = font;
textState.FontStyle = FontStyle.Bold | FontStyle.Italic;

// 改变指定字体的文本
editor.ReplaceText("hello world", "hi world", textState);

// 保存文档
doc.Save(outFile);

也可以看看


ReplaceText(string, string, int)

替换 PDF 文件中的文本并设置字体大小。

public bool ReplaceText(string srcString, string destString, int fontSize)
范围类型描述
srcStringString要替换的字符串。
destStringString替换字符串。
fontSizeInt32字体大小。

返回值

如果进行了替换,则返回 true。

例子

该示例演示了如何替换文本并为新文本设置字体大小。

// 打开文档
Document doc = new Document(inFile);

// 创建字体并将其标记为嵌入
Aspose.Pdf.Text.Font font = FontRepository.FindFont("Courier New");
font.IsEmbedded = true;

// 创建 PdfContentEditor 对象来编辑文本
PdfContentEditor editor = new PdfContentEditor();
editor.BindPdf(doc);

// 改变指定字体的文本
editor.ReplaceText("hello world", "hi world", 14);

// 保存文档
doc.Save(outFile);

也可以看看