Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Thu May 22, 2025 7:58 am

PdfTextReplaceOptions textReplaceOptions = new PdfTextReplaceOptions();

// Specify the options for text replacement
textReplaceOptions.setReplaceType(EnumSet.of(ReplaceActionType.IgnoreCase));
textReplaceOptions.setReplaceType(EnumSet.of(ReplaceActionType.WholeWord));


for (int i = 0; i < doc.getPages().getCount(); i++) {

// Get a specific page
PdfPageBase page = doc.getPages().get(i);

// Create a PdfTextReplacer object based on the page
PdfTextReplacer textReplacer = new PdfTextReplacer(page);

// Set the replace options
textReplacer.setOptions(textReplaceOptions);

// Replace all instances of target text with new text
textReplacer.replaceAllText("ghost?", "boss");
}
how to make ghost and replace word boss keep the same font and style? or other methods can make this work。replace word and keep the word style same!!!

shenmegui
 
Posts: 2
Joined: Fri Jul 14, 2023 7:04 am

Thu May 22, 2025 10:25 am

Hello,

Thanks for your inquiry.
The PdfTextReplacer interface is by default designed to keep the original text's font style unchanged, and my initial testing also confirms that the style is preserved. To help us conduct a more accurate investigation, please provide us with your PDF document. You can upload your file here or send to my email [email protected]. Thanks in advance.

Sincerely,
Tommy
E-iceblue support team
User avatar

Tommy.Tang
 
Posts: 85
Joined: Mon Apr 21, 2025 7:05 am

Return to Spire.PDF

cron