How can I help you?
Flattening PDFs Using Syncfusion Web API
24 Mar 20265 minutes to read
The Syncfusion Flatten PDF Web API enables you to permanently embed annotations and form field data into the PDF content. All interactive elements—such as form fields, comments, and highlights—are converted into static, non‑editable content while preserving the document’s appearance. This ensures consistent viewing across devices and makes the PDF suitable for final distribution, archiving, and compliance with workflows.
Flatten PDF Documents
To flatten a PDF document, send a request to the /v1/edit-pdf/flatten endpoint with the input PDF and its options as shown below.
curl --location 'http://localhost:8003/v1/edit-pdf/flatten' \
--form 'file=@Input.pdf' \
--form 'settings={
"File": "file",
"Password": null,
"FlattenFormFields": true,
"FlattenAnnotations": true
}'const formdata = new FormData();
formdata.append("file", fileInput.files[0], "Form.pdf");
formdata.append(
"settings",
JSON.stringify({
File: "file",
Password: null,
FlattenFormFields: true,
FlattenAnnotations: true
})
);
const requestOptions = {
method: "POST",
body: formdata,
redirect: "follow"
};
fetch("http://localhost:8003/v1/edit-pdf/flatten", requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.error(error));var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost:8003/v1/edit-pdf/flatten");
var content = new MultipartFormDataContent();
content.Add(new StreamContent(File.OpenRead("Input.pdf")), "file1", "Input.pdf");
var settings = new
{
File = "file",
Password = (string?)null,
FlattenFormFields = true,
FlattenAnnotations = true
};
var json = JsonSerializer.Serialize(settings);
var settingsContent = new StringContent(json, Encoding.UTF8, "application/json");
// When sending JSON as a field inside multipart, you can still name the part:
content.Add(settingsContent, "settings");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());Flatten PDFs settings
Password
Specifies the password required to open and process a protected PDF file.
FlattenFormFields
Converts interactive form fields into static content, making them non‑editable in the output PDF.
FlattenAnnotations
Converts annotations (such as comments, highlights, and stamps) into permanent, non‑editable content in the PDF.
Flatten PDF Job Response
Once the request is sent, it will create a flatten job to flatten the PDF and return the job details as follows:
{
"jobID": "6be827c5-d86d-4fe5-9bd5-c8fd5887a455",
"status": "requested",
"createdAt": "2024-05-06T09:39:13.9505828Z"
}
Check Flatten PDF Job Status
Next, you can retrieve the job status by sending a request to the /v1/edit-pdf/status/{jobID} endpoint with the job ID.
curl --location 'http://localhost:8003/v1/edit-pdf/status/f58c9739-622e-41d4-9dd2-57a901dc13c3' \
--output Output.pdf
--header 'Authorization: Bearer 'const requestOptions = {
method: "GET",
redirect: "follow"
};
fetch("http://localhost:8003/v1/edit-pdf/status/4413bbb5-6b26-4c07-9af2-c26cd2c42fe3", requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.error(error));var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost:8003/v1/edit-pdf/status/ef0766ab-bc74-456c-8143-782e730a89df");
request.Headers.Add("Authorization", "Bearer ");
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());You will receive one of the following statuses until the job is completed. Upon completion, you will receive the actual output file.
Job Statuses:
- Queued:
{
"jobID": "4b2782b2-9f08-478b-98fc-4464bd219ca0",
"status": "queued"
}
- In Progress:
{
"jobID": "ef0766ab-bc74-456c-8143-782e730a89df",
"status": "in progress"
}
- Error:
{
"jobID": "ef0766ab-bc74-456c-8143-782e730a89df",
"status": "errror",
"code": "500",
"message": "Failed to convert the document to PDF"
}
NOTE
The Syncfusion Document Processing API is now available as a Docker-based solution. Try it out