The pdfRest Flatten Annotations API Tool is designed to take annotations in a PDF and make them a permanent part of the document. This process is known as "flattening." Flattening annotations is useful in scenarios where you want to prevent further modifications to the annotations or ensure that they are displayed correctly across all PDF viewers. For instance, if you're sending a contract with comments to a client, you might want to flatten these comments so that they can't be altered before signing.
This tutorial will guide you through the process of sending an API call to Flatten Annotations using C#. By the end of this tutorial, you will understand how to integrate this functionality into your C# applications.
using System.Text; using (var httpClient = new HttpClient { BaseAddress = new Uri("https://api.pdfrest.com") }) { using (var request = new HttpRequestMessage(HttpMethod.Post, "flattened-annotations-pdf")) { request.Headers.TryAddWithoutValidation("Api-Key", "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"); request.Headers.Accept.Add(new("application/json")); var multipartContent = new MultipartFormDataContent(); var byteArray = File.ReadAllBytes("/path/to/file_name.pdf"); var byteAryContent = new ByteArrayContent(byteArray); multipartContent.Add(byteAryContent, "file", "file_name.pdf"); byteAryContent.Headers.TryAddWithoutValidation("Content-Type", "application/pdf"); request.Content = multipartContent; var response = await httpClient.SendAsync(request); var apiResult = await response.Content.ReadAsStringAsync(); Console.WriteLine("API response received."); Console.WriteLine(apiResult); } }
Reference: pdfRest API C# Sample Code
The provided code snippet demonstrates how to make a multipart/form-data POST request to the pdfRest Flatten Annotations API endpoint using C#.
HttpClient
is initialized with the base address of the pdfRest API.HttpRequestMessage
is created for the POST request to the "flattened-annotations-pdf" endpoint.MultipartFormDataContent
is created to hold the file content.Content-Type
header for the file part is set to "application/pdf".By following the tutorial above, you have learned how to make a call to the pdfRest Flatten Annotations API using C#. This allows you to integrate PDF annotation flattening into your applications seamlessly. You can now ensure that annotations in your PDFs are displayed consistently and cannot be altered by the end users.
To explore and demo all of the pdfRest API Tools, visit the API Lab at https://pdfrest.com/apilab/. For more detailed information about the API, refer to the API Reference documentation at https://pdfrest.com/documentation/.
Note: This is an example of a multipart API call. Code samples using JSON payloads can be found at https://github.com/datalogics/pdf-rest-api-samples/tree/main/DotNET/Endpoint%20Examples/JSON%20Payload/flattened-annotations-pdf.cs.
Create your FREE API Key to start processing PDFs in seconds, only possible with pdfRest.