PdfContentEditor.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 для нового текста.

// open document
Document doc = new Document(inFile);

// Create font and mark it to be embedded
Aspose.Pdf.Text.Font font = FontRepository.FindFont("Courier New");
font.IsEmbedded = true;

// create PdfContentEditor object to edit text
PdfContentEditor editor = new PdfContentEditor();
editor.BindPdf(doc);

// create textState object
TextState textState = new TextState();
textState.Font = font;
textState.FontSize = 17;
textState.FontStyle = FontStyle.Bold | FontStyle.Italic;
textState.ForegroundColor = Color.Red;

// change text with specified font
editor.ReplaceText("hello world", 1, "hi world", textState);

// save document
doc.Save(outFile);

См. также


ReplaceText(string, string)

Заменяет текст в PDF-файле.

public bool ReplaceText(string srcString, string destString)
ПараметрТипОписание
srcStringStringСтрока, которую нужно заменить.
destStringStringЗаменяющая строка.

Возвращаемое значение

Возвращает true, если замена была выполнена.

Примеры

Пример демонстрирует, как заменить текст в PDF-документе.

// open document
Document doc = new Document(inFile);

// create PdfContentEditor object to edit text
PdfContentEditor editor = new PdfContentEditor();
editor.BindPdf(doc);

// change text 
editor.ReplaceText("hello world", "hi world");

// save document
doc.Save(outFile);

См. также


ReplaceText(string, int, string)

Заменяет текст в PDF-файле на указанной странице.

public bool ReplaceText(string srcString, int thePage, string destString)
ПараметрТипОписание
srcStringStringСтрока, которую нужно заменить.
thePageInt32Номер страницы (0 для всех страниц)
destStringStringЗаменяющая строка.

Возвращаемое значение

Возвращает true, если замена была выполнена.

Примеры

Пример демонстрирует, как заменить текст в PDF-документе на указанной странице.

// open document
Document doc = new Document(inFile);

// create PdfContentEditor object to edit text
PdfContentEditor editor = new PdfContentEditor();
editor.BindPdf(doc);

// change text 
editor.ReplaceText("hello world", 1, "hi world");

// save document
doc.Save(outFile);

См. также


ReplaceText(string, string, TextState)

Заменяет текст в PDF-файле, используя указанный объект TextState.

public bool ReplaceText(string srcString, string destString, TextState textState)
ПараметрТипОписание
srcStringStringСтрока, которую нужно заменить
destStringStringЗаменяющая строка
textStateTextStateСостояние текста (цвет текста, шрифт и т.д.)

Возвращаемое значение

Возвращает true, если замена была выполнена.

Примеры

Пример демонстрирует, как заменить текст и установить свойства текста TextState для нового текста.

// open document
Document doc = new Document(inFile);

// Create font and mark it to be embedded
Aspose.Pdf.Text.Font font = FontRepository.FindFont("Courier New");
font.IsEmbedded = true;

// create PdfContentEditor object to edit text
PdfContentEditor editor = new PdfContentEditor();
editor.BindPdf(doc);

// create textState object
TextState textState = new TextState();
textState.Font = font;
textState.FontStyle = FontStyle.Bold | FontStyle.Italic;

// change text with specified font
editor.ReplaceText("hello world", "hi world", textState);

// save document
doc.Save(outFile);

См. также


ReplaceText(string, string, int)

Заменяет текст в PDF-файле и устанавливает размер шрифта.

public bool ReplaceText(string srcString, string destString, int fontSize)
ПараметрТипОписание
srcStringStringСтрока, которую нужно заменить.
destStringStringЗаменяющая строка.
fontSizeInt32Размер шрифта.

Возвращаемое значение

Возвращает true, если замена была выполнена.

Примеры

Пример демонстрирует, как заменить текст и установить размер шрифта для нового текста.

// open document
Document doc = new Document(inFile);

// Create font and mark it to be embedded
Aspose.Pdf.Text.Font font = FontRepository.FindFont("Courier New");
font.IsEmbedded = true;

// create PdfContentEditor object to edit text
PdfContentEditor editor = new PdfContentEditor();
editor.BindPdf(doc);

// change text with specified font
editor.ReplaceText("hello world", "hi world", 14);

// save document
doc.Save(outFile);

См. также