Replace List of Texts in PDFs via .NET SDK
Replacing List of Texts in PDF Documents using server-side .NET API
Get StartedHow to replace list of texts in PDF document via Cloud .NET SDK
In order to massive replacement texts in PDF documents via Cloud .NET SDK , we’ll use Aspose.PDF Cloud .NET SDK This Cloud SDK allows you to easily build cloud-based PDF creator, editor & converter apps in C#, ASP.NET, or other .NET languages for various cloud platforms. Open NuGet package manager, search for Aspose.PDF Cloud and install. You may also use the following command from the Package Manager Console.
Package Manager Console Command
PM> Install-Package Aspose.Pdf-Cloud
Steps to mass replacement texts in PDF document via .NET SDK
Aspose.PDF Cloud developers can easily load & replace list of texts in PDF in just a few lines of code.
- Upload the File to Cloud Storage
- Initializes the PdfApi with the provided credentials (Application ID and Application Key).
- Reads the local PDF file and uploads it to the Aspose Cloud storage.
- Call API to mass replacement texts in PDF.
- Downloads the updated file for local use.
This sample code shows replacing list of texts in PDF documents
public static async Task TextReplaceList()
{
const string localImageFileName = @"C:\Samples\sample.pdf";
const string storageFileName = "sample.pdf";
const string localFolder = @"C:\Samples";
const string resultFileName = "output_list_replace_text.pdf";
const string storageTempFolder = "YourTempFolder";
// Get your AppSid and AppSecret from https://dashboard.aspose.cloud (free registration required).
var pdfApi = new PdfApi(AppSecret, AppSid);
using var file = File.OpenRead(localImageFileName);
var uploadResult = await pdfApi.UploadFileAsync(Path.Combine(storageTempFolder, storageFileName), file);
Console.WriteLine(uploadResult.Uploaded[0]);
TextReplaceListRequest textReplaceList = new TextReplaceListRequest(
new List<TextReplace> {
new TextReplace(OldValue: "Your-Document-Text-1", NewValue: "New-Document-Text-1", Regex: true),
new TextReplace(OldValue: "Your-Document-Text-2", NewValue: "New-Document-Text-2", Regex: true),
}
);
var response = await pdfApi.PostDocumentTextReplaceAsync(storageFileName, textReplaceList, folder: storageTempFolder);
using Stream downloadStream = await pdfApi.DownloadFileAsync(Path.Combine(storageTempFolder, storageFileName));
using FileStream localStream = File.Create(Path.Combine(localFolder, resultFileName));
downloadStream.CopyTo(localStream);
Console.WriteLine($"AddText(): {response.Matches} text occurencies successfully replaced in PDF document {resultFileName}.");
}
Work with Text in PDF
Mass replacement of texts in a PDF document can be easily implemented by the user, for example when correcting errors in the text or replacing identical fragments of text. This is often used in marketing materials or for personalized reports. Replacing text with specific fonts, colors and alignments can make some sections more clear and visually appealing, creating a better user experience. Text replacement can help to keep the information sequence in different PDF versions, avoiding manual editing and ensuring that key information remains in place. Replacement Texts in PDF documents with Aspose.PDF Cloud .NET SDK.
With our .NET library you can:
- Combine PDF documents.
- Split PDF Files.
- Convert PDF to other formats, and vice versa.
- Manipulate Annotations.
- Work with Images in PDF, etc.
- You can try out our free App to replace text in PDF files online and test the functionality.