PdfContentEditor.ReplaceText

ReplaceText(string, int, string, TextState)

Sostituisce il testo nel file PDF nella pagina specificata. L’oggetto TextState (famiglia di caratteri, colore) può essere specificato per il testo sostituito.

public bool ReplaceText(string srcString, int thePage, string destString, TextState textState)
ParametroTipoDescrizione
srcStringStringLa stringa da sostituire.
thePageInt32Numero di pagina (0 significa “tutte le pagine”).
destStringStringLa stringa sostituita.
textStateTextStateStato del testo (Colore del testo, Font, ecc.).

Valore di ritorno

Restituisce true se la sostituzione è stata effettuata.

Esempi

L’esempio dimostra come sostituire il testo nella prima pagina del documento PDF e impostare le proprietà del testo TextState per il nuovo testo.

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

Vedi anche


ReplaceText(string, string)

Sostituisce il testo nel file PDF.

public bool ReplaceText(string srcString, string destString)
ParametroTipoDescrizione
srcStringStringLa stringa da sostituire.
destStringStringStringa di sostituzione.

Valore di ritorno

Restituisce true se la sostituzione è stata effettuata.

Esempi

L’esempio dimostra come sostituire il testo nel 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);

Vedi anche


ReplaceText(string, int, string)

Sostituisce il testo nel file PDF nella pagina specificata.

public bool ReplaceText(string srcString, int thePage, string destString)
ParametroTipoDescrizione
srcStringStringLa stringa da sostituire.
thePageInt32Numero di pagina (0 per tutte le pagine)
destStringStringStringa di sostituzione.

Valore di ritorno

Restituisce true se la sostituzione è stata effettuata.

Esempi

L’esempio dimostra come sostituire il testo nel documento PDF nella pagina specificata.

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

Vedi anche


ReplaceText(string, string, TextState)

Sostituisce il testo nel file PDF utilizzando l’oggetto TextState specificato.

public bool ReplaceText(string srcString, string destString, TextState textState)
ParametroTipoDescrizione
srcStringStringStringa da sostituire
destStringStringStringa di sostituzione
textStateTextStateStato del testo (Colore del testo, Font, ecc.)

Valore di ritorno

Restituisce true se la sostituzione è stata effettuata.

Esempi

L’esempio dimostra come sostituire il testo e impostare le proprietà del testo TextState per il nuovo testo.

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

Vedi anche


ReplaceText(string, string, int)

Sostituisce il testo nel file PDF e imposta la dimensione del carattere.

public bool ReplaceText(string srcString, string destString, int fontSize)
ParametroTipoDescrizione
srcStringStringStringa da sostituire.
destStringStringStringa di sostituzione.
fontSizeInt32Dimensione del carattere.

Valore di ritorno

Restituisce true se la sostituzione è stata effettuata.

Esempi

L’esempio dimostra come sostituire il testo e impostare la dimensione del carattere per il nuovo testo.

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

Vedi anche