Spire.PDF 11.2.4 supports replacing text in specific areas using PdfTextReplacer

Spire.PDF 11.2.4 supports replacing text in specific areas using PdfTextReplacer

2025-02-13 09:11:04

We are excited to announce the release of Spire.PDF 11.2.4. This version supports replacing text in specific areas using PdfTextReplacer, retrieving bookmark information from Action links, and returning the count of replacements made by PdfTextReplacer.ReplaceAllText. It also enhances the conversion from PDF to HTML and images. Moreover, a lot of known issues are fixed successfully in this version, such as the issue that the PDF printing effect was incorrect. More details are listed below.

Here is a list of changes made in this release

Category ID Description
New feature SPIREPDF-7255 Supports replacing text in specific areas using PdfTextReplacer.
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile(inputFile);
for (int i = 0; i < pdf.Pages.Count; i++)
{
	PdfPageBase page = pdf.Pages[i] ;
	PdfTextReplacer replacer = new PdfTextReplacer(page);
	PdfTextReplaceOptions replaceOptions = new PdfTextReplaceOptions();
	RectangleF rectangle = new RectangleF(10, 0, 841, 150);
	replaceOptions.SetReplacementArea(rectangle);
	replaceOptions.ReplaceType = PdfTextReplaceOptions.ReplaceActionType.IgnoreCase;
	replacer.Options = replaceOptions;
	replacer.ReplaceAllText("sql", "123456");
}
pdf.SaveToFile(outputFile);
pdf.Dispose();
New feature SPIREPDF-7292 Supports retrieving bookmark information from Action links.
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(inputFile);
PdfFormWidget formWidget = (PdfFormWidget)doc.Form;
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("btnAction:");
for (int i = 0; i < formWidget.FieldsWidget.Count; ++i)
{
	var field = formWidget.FieldsWidget[i] as PdfButtonWidgetFieldWidget;
	if (field.Actions.MouseUp != null && field.Actions.MouseUp is PdfNamedAction)
	{
		var aaa = (PdfNamedAction)field.Actions.MouseUp;
		stringBuilder.AppendLine(formWidget.FieldsWidget[i].Name + "-MouseUp-" + aaa.Destination.ToString());
	}
	else if (field.Actions.MouseDown != null && field.Actions.MouseDown is PdfNamedAction)
	{

		var aaa = (PdfNamedAction)field.Actions.MouseDown;
		stringBuilder.AppendLine(formWidget.FieldsWidget[i].Name + "-MouseDown--" + aaa.Destination.ToString());
	}
	else if (field.Actions.MouseDown != null && field.Actions.MouseDown is PdfUriAction)
	{

		var aaa = (PdfUriAction)field.Actions.MouseDown;
		stringBuilder.AppendLine(formWidget.FieldsWidget[i].Name + "-MouseDown--" + aaa.Uri.ToString());
	}
	else if (field.Actions.MouseUp != null && field.Actions.MouseUp is PdfUriAction)
	{
		var aaa = (PdfUriAction)field.Actions.MouseUp;
		stringBuilder.AppendLine(formWidget.FieldsWidget[i].Name + "-MouseUp-" + aaa.Uri.ToString());
	}
	else if (field.Actions.MouseDown != null && field.Actions.MouseDown is PdfGotoNameAction) 
	{
		var aaa = (PdfGotoNameAction)field.Actions.MouseDown;
		stringBuilder.AppendLine(formWidget.FieldsWidget[i].Name + "-MouseDown-" + aaa.Destination.ToString());
	}

}
File.WriteAllText(outputFile, stringBuilder.ToString());
doc.Dispose();
New feature SPIREPDF-7345 Supports returning the count of replacements made by PdfTextReplacer.ReplaceAllText.
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile(inputFile);
PdfPageBase page = pdf.Pages[0];
PdfTextReplacer replacer = new PdfTextReplacer(page);
int count = replacer.ReplaceAllText("SQL", "ABC");
Bug SPIREPDF-6551 Optimizes the PDF compression function of PdfCompressor.
Bug SPIREPDF-7061
SPIREPDF-7082
Fixes the issue that the PDF printing effect was incorrect.
Bug SPIREPDF-7313 Fixes the issue that the display effect of multi-line text in PdfTextBoxField was incorrect.
Bug SPIREPDF-7320 Fixes the issue that the PDF-to-image conversion effect was incorrect.
Bug SPIREPDF-7325 Fixes the issue that characters overlapped after converting PDF to HTML.
Bug SPIREPDF-7342 Fixes the issue that the exception “System.NullReferenceException” was thrown when merging documents.
Click the link to download Spire.PDF 11.2.4:
More information of Spire.PDF new release or hotfix: