Skip to content

Commit ef14738

Browse files
committed
Fixes fill form guide
1 parent 9e940bb commit ef14738

1 file changed

Lines changed: 69 additions & 62 deletions

File tree

  • fern/pages/help_center/pdf-forms

fern/pages/help_center/pdf-forms/fill.mdx

Lines changed: 69 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -15,84 +15,91 @@ Ensure you have the following:
1515

1616
### Prepare the form data as a list of object as follows
1717

18+
Note: if you don't know what the field names are, you should use the [mark form fields](/help_center/pdf-forms/mark) or [detect form fields](/help_center/pdf-forms/fill) API endpoints to get the field names.
19+
20+
Here are the most common fields and supported types:
21+
22+
| Field Type | Options |
23+
| --------------- | ------------------ |
24+
| PDFTextField | `value: string` |
25+
| PDFOptionList | `selected: string` |
26+
| PDFDropdownList | `selected: string` |
27+
| PDFCheckBox | `checked: boolean` |
28+
| PDFRadioGroup | `selected: string` |
29+
1830
```typescript
1931
[
20-
{
21-
name: "Producer Name",
22-
type: "PDFTextField",
23-
value: "Titouan Launay", // fills a text field
24-
},
25-
{
26-
name: "Check Box4",
27-
type: "PDFCheckBox",
28-
checked: false, // unchecks a box
29-
},
30-
]
32+
{
33+
name: "Producer Name",
34+
type: "PDFTextField",
35+
value: "Titouan Launay", // fills a text field
36+
},
37+
{
38+
name: "Check Box4",
39+
type: "PDFCheckBox",
40+
checked: false, // unchecks a box
41+
},
42+
];
3143
```
3244

33-
### Mark form fields from the PDF and retrieve a modified PDF
45+
### Fill form fields from the PDF and retrieve a modified PDF
3446

3547
```typescript
3648
import { FileforgeClient } from "@fileforge/client";
3749
import * as fs from "fs";
38-
import { pipeline } from 'stream';
39-
import { promisify } from 'util';
50+
import { pipeline } from "stream";
51+
import { promisify } from "util";
4052

4153
const pipelineAsync = promisify(pipeline);
4254

4355
(async () => {
44-
const ff = new FileforgeClient({
45-
apiKey: process.env.FILEFORGE_API_KEY,
46-
});
47-
48-
try {
49-
const formFillRequest = {
50-
options: {
51-
fields: [
52-
{
53-
name: "Producer Name",
54-
type: "PDFTextField",
55-
value: "Pierre Dorge"
56-
},
57-
{
58-
name:"Check Box4",
59-
type:"PDFCheckBox",
60-
checked: false
61-
},
62-
],
63-
},
64-
};
65-
const requestOptions = {
66-
timeoutInSeconds: 60,
67-
maxRetries: 3,
68-
};
69-
const filledPdfStream = await ff.pdf.form.fill(
70-
new File(
71-
[fs.readFileSync(__dirname + "/form.pdf")],
72-
"form.pdf",
56+
const ff = new FileforgeClient({
57+
apiKey: process.env.FILEFORGE_API_KEY,
58+
});
59+
60+
try {
61+
const formFillRequest = {
62+
options: {
63+
fields: [
7364
{
74-
type: "application/pdf",
65+
name: "Producer Name",
66+
type: "PDFTextField",
67+
value: "Pierre Dorge",
7568
},
76-
),
77-
formFillRequest,
78-
requestOptions,
79-
);
80-
81-
82-
await pipelineAsync(filledPdfStream, fs.createWriteStream("./result_filled.pdf")); // ensures the whole file is written before the stream is closed
83-
84-
console.log("PDF form filling successful. Stream ready.");
85-
} catch (error) {
86-
console.error("Error during PDF form filling:", error);
87-
}
88-
})();
69+
{
70+
name: "Check Box4",
71+
type: "PDFCheckBox",
72+
checked: false,
73+
},
74+
],
75+
},
76+
};
77+
const requestOptions = {
78+
timeoutInSeconds: 60,
79+
maxRetries: 3,
80+
};
81+
const filledPdfStream = await ff.pdf.form.fill(
82+
new File([fs.readFileSync(__dirname + "/form.pdf")], "form.pdf", {
83+
type: "application/pdf",
84+
}),
85+
formFillRequest,
86+
requestOptions
87+
);
88+
89+
await pipelineAsync(
90+
filledPdfStream,
91+
fs.createWriteStream("./result_filled.pdf")
92+
); // ensures the whole file is written before the stream is closed
93+
94+
console.log("PDF form filling successful. Stream ready.");
95+
} catch (error) {
96+
console.error("Error during PDF form filling:", error);
97+
}
98+
})();
8999
```
90100

91101
### Get a modified PDF
92-
The reponse is stream of the modified PDF with form fields marked with a green border, and hover text showing the field name.
93-
94-
![sample marked pdf file](../../../assets/form-pdf-marked.png)
95-
96102

103+
The reponse is stream of the filled PDF document.
97104

98-
</Steps>
105+
</Steps>

0 commit comments

Comments
 (0)