PdfContentEditor.ReplaceText

ReplaceText(string, int, string, TextState)

Replaces text in the PDF file on the specified page. TextState object (font family, color) can be specified to replaced text.

public bool ReplaceText(string srcString, int thePage, string destString, TextState textState)
ParameterTypeDescription
srcStringStringThe string to be replaced.
thePageInt32Page number (0 means “all pages”).
destStringStringThe replaced string.
textStateTextStateText state (Text Color, Font etc).

Return Value

Returns true if replacement was made.

Examples

The example demonstrates how to replace text on the first page of the PDF document and set TextState text properties for the new text.

// 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);

See Also


ReplaceText(string, string)

Replaces text in the PDF file.

public bool ReplaceText(string srcString, string destString)
ParameterTypeDescription
srcStringStringThe string to be replaced.
destStringStringReplacing string.

Return Value

Returns true if replacement was made.

Examples

The example demonstrates how to replace text in PDF document.

// 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);

See Also


ReplaceText(string, int, string)

Replaces text in the PDF file on the specified page.

public bool ReplaceText(string srcString, int thePage, string destString)
ParameterTypeDescription
srcStringStringThe sting to be replaced.
thePageInt32Page number (0 for all pages)
destStringStringReplacing string.

Return Value

Returns true if replacement was made.

Examples

The example demonstrates how to replace text in PDF document on the specified page.

// 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);

See Also


ReplaceText(string, string, TextState)

Replaces text in the PDF file using specified TextState object.

public bool ReplaceText(string srcString, string destString, TextState textState)
ParameterTypeDescription
srcStringStringString to be replaced
destStringStringReplacing string
textStateTextStateText state (Text Color, Font etc)

Return Value

Returns true if replacement was made.

Examples

The example demonstrates how to replace text and set TextState text properties for the new text.

// 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);

See Also


ReplaceText(string, string, int)

Replaces text in the PDF file and sets font size.

public bool ReplaceText(string srcString, string destString, int fontSize)
ParameterTypeDescription
srcStringStringString to be replaced.
destStringStringReplacing string.
fontSizeInt32Font size.

Return Value

Returns true if replacement was made.

Examples

The example demonstrates how to replace text and set font size for the new text.

// 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);

See Also