This documentation provides an example of how to use the FileforgeClient to mark form fields in a PDF document. This endpoint returns modified version of the PDF you submit with form fields marked with a green border, and hover text showing the field name.

Prerequisites

Ensure you have the following:

  • An API key for Fileforge as an environment variable: process.env.FILEFORGE_API_KEY
  • Node.js and npm installed.
  • The Fileforge Client installed.

Guide

1

Mark form fields from the PDF and retrieve a modified PDF

1import { FileforgeClient } from "@fileforge/client";
2import * as fs from "fs";
3
4(async () => {
5 const ff = new FileforgeClient({
6 apiKey: process.env.FILEFORGE_API_KEY,
7 });
8
9 try {
10 const pdfStream = await ff.pdf.form.mark(
11 new File(
12 [fs.readFileSync(__dirname + "/samples/form.pdf")],
13 "form.pdf",
14 {
15 type: "application/pdf",
16 },
17 ),
18 { options: {} },
19 );
20
21 pdfStream.pipe(fs.createWriteStream("./result_mark.pdf"));
22 } catch (error) {
23 console.error("Error during PDF form mark:", error);
24 throw error;
25 }
26 })();
2

Get a modified PDF

The reponse is stream of the modified PDF with form fields marked with a green border, and hover text showing the field name.

sample marked pdf file