How to add Text into PDF via Cloud .NET SDK
In order to add Text into PDF 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 add Text into PDF via .NET SDK
Aspose.PDF Cloud developers can easily load & add Text to 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.
- Calls the postSplitDocument method of the PdfApi to split the uploaded PDF document.
- Downloads each split PDF page and saves it to the local file system.
This sample code shows adding Text to PDF documents
public static void Add()
{
const string localImageFileName = @"C:\Samples\Sample-Document-01.pdf";
const string storageFileName = "Sample-Document-01.pdf";
const string resultFileName = "Sample-Document-01.pdf";
// Get your AppSid and AppSecret from https://dashboard.aspose.cloud (free registration required).
var pdfApi = new PdfApi(AppSecret, AppSid);
if (pdfApi.GetFilesList(".").Value.All(f => f.Name != storageFileName))
{
using var file = File.OpenRead(localImageFileName);
var uploadResult = pdfApi.UploadFile(storageFileName, file);
Console.WriteLine(uploadResult.Uploaded[0]);
}
Paragraph paragraph = new()
{
Lines =
[
new TextLine() {
Segments = [
new Segment("Lorem ipsum",
new TextState() {
FontSize = 20,
Font = "Arial",
ForegroundColor = new Color(255, 0, 0, 255),
BackgroundColor = new Color(255, 255, 255, 0),
FontStyle = FontStyles.Regular,
Underline = true
})
]
}
],
HorizontalAlignment = TextHorizontalAlignment.Justify,
VerticalAlignment = VerticalAlignment.Center,
};
pdfApi.PutAddText(storageFileName, 1, paragraph);
pdfApi.DownloadFile(storageFileName)
.CopyTo(File.Create(resultFileName));
}
Work with Text in PDF
Text can be dynamically added to customize a PDF for a specific user, such as adding their name or personalized message. This is often used in marketing materials or for personalized reports. Adding text in specific fonts, colors, and alignments can make certain sections more readable and visually appealing, creating a better user experience. Text additions can help maintain consistent information across different PDF versions, avoiding manual edits and ensuring that key information remains in place. Add the Text into 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 add the text into PDF files online and test the functionality.