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)
Parameter | Type | Description |
---|---|---|
srcString | String | The string to be replaced. |
thePage | Int32 | Page number (0 means “all pages”). |
destString | String | The replaced string. |
textState | TextState | Text 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
- class TextState
- class PdfContentEditor
- namespace Aspose.Pdf.Facades
- assembly Aspose.PDF
ReplaceText(string, string)
Replaces text in the PDF file.
public bool ReplaceText(string srcString, string destString)
Parameter | Type | Description |
---|---|---|
srcString | String | The string to be replaced. |
destString | String | Replacing 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
- class PdfContentEditor
- namespace Aspose.Pdf.Facades
- assembly Aspose.PDF
ReplaceText(string, int, string)
Replaces text in the PDF file on the specified page.
public bool ReplaceText(string srcString, int thePage, string destString)
Parameter | Type | Description |
---|---|---|
srcString | String | The sting to be replaced. |
thePage | Int32 | Page number (0 for all pages) |
destString | String | Replacing 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
- class PdfContentEditor
- namespace Aspose.Pdf.Facades
- assembly Aspose.PDF
ReplaceText(string, string, TextState)
Replaces text in the PDF file using specified TextState
object.
public bool ReplaceText(string srcString, string destString, TextState textState)
Parameter | Type | Description |
---|---|---|
srcString | String | String to be replaced |
destString | String | Replacing string |
textState | TextState | Text 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
- class TextState
- class PdfContentEditor
- namespace Aspose.Pdf.Facades
- assembly Aspose.PDF
ReplaceText(string, string, int)
Replaces text in the PDF file and sets font size.
public bool ReplaceText(string srcString, string destString, int fontSize)
Parameter | Type | Description |
---|---|---|
srcString | String | String to be replaced. |
destString | String | Replacing string. |
fontSize | Int32 | Font 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
- class PdfContentEditor
- namespace Aspose.Pdf.Facades
- assembly Aspose.PDF