PdfContentEditor.ReplaceText

ReplaceText(string, int, string, TextState)

Reemplaza texto en el archivo PDF en la página especificada. Se puede especificar el objeto TextState (familia de fuentes, color) para el texto reemplazado.

public bool ReplaceText(string srcString, int thePage, string destString, TextState textState)
ParámetroTipoDescripción
srcStringStringLa cadena a ser reemplazada.
thePageInt32Número de página (0 significa “todas las páginas”).
destStringStringLa cadena reemplazada.
textStateTextStateEstado del texto (Color del texto, Fuente, etc.).

Valor de Retorno

Devuelve verdadero si se realizó el reemplazo.

Ejemplos

El ejemplo demuestra cómo reemplazar texto en la primera página del documento PDF y establecer propiedades de texto TextState para el nuevo texto.

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

Véase También


ReplaceText(string, string)

Reemplaza texto en el archivo PDF.

public bool ReplaceText(string srcString, string destString)
ParámetroTipoDescripción
srcStringStringLa cadena a ser reemplazada.
destStringStringCadena de reemplazo.

Valor de Retorno

Devuelve verdadero si se realizó el reemplazo.

Ejemplos

El ejemplo demuestra cómo reemplazar texto en el documento 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);

Véase También


ReplaceText(string, int, string)

Reemplaza texto en el archivo PDF en la página especificada.

public bool ReplaceText(string srcString, int thePage, string destString)
ParámetroTipoDescripción
srcStringStringLa cadena a ser reemplazada.
thePageInt32Número de página (0 para todas las páginas)
destStringStringCadena de reemplazo.

Valor de Retorno

Devuelve verdadero si se realizó el reemplazo.

Ejemplos

El ejemplo demuestra cómo reemplazar texto en el documento PDF en la página especificada.

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

Véase También


ReplaceText(string, string, TextState)

Reemplaza texto en el archivo PDF utilizando el objeto TextState especificado.

public bool ReplaceText(string srcString, string destString, TextState textState)
ParámetroTipoDescripción
srcStringStringCadena a ser reemplazada
destStringStringCadena de reemplazo
textStateTextStateEstado del texto (Color del texto, Fuente, etc.)

Valor de Retorno

Devuelve verdadero si se realizó el reemplazo.

Ejemplos

El ejemplo demuestra cómo reemplazar texto y establecer propiedades de texto TextState para el nuevo texto.

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

Véase También


ReplaceText(string, string, int)

Reemplaza texto en el archivo PDF y establece el tamaño de fuente.

public bool ReplaceText(string srcString, string destString, int fontSize)
ParámetroTipoDescripción
srcStringStringCadena a ser reemplazada.
destStringStringCadena de reemplazo.
fontSizeInt32Tamaño de fuente.

Valor de Retorno

Devuelve verdadero si se realizó el reemplazo.

Ejemplos

El ejemplo demuestra cómo reemplazar texto y establecer el tamaño de fuente para el nuevo texto.

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

Véase También