@@ -138,33 +138,7 @@ formApi.post('/forms/:formId', async (ctx) => {
138
138
139
139
## Step 3: Generate PDF Receipts
140
140
141
- Listen for submitted events and generate a formatted PDF receipt from the stored data.
142
-
143
- ``` ts title:services/pdfs.ts
144
- import { receipts , submissions , output } from ' ../resources/resources'
145
- import { buildReceipt } from ' ../form/receipt'
146
-
147
- receipts .subscribe (async (ctx ) => {
148
- const { id, formId } = ctx .req .json ()
149
- const submission = await submissions .get (id )
150
-
151
- if (! submission ) {
152
- console .error (` No submission found for ID: ${id } ` )
153
- return
154
- }
155
-
156
- // Build the PDF buffer from the submission data
157
- const buffer = await buildReceipt (submission , formId )
158
-
159
- // Store the PDF file in the bucket
160
- const file = output .file (` ${id }.pdf ` )
161
- await file .write (buffer )
162
-
163
- console .log (` Receipt stored for ${id } ` )
164
- })
165
- ```
166
-
167
- ### Build the PDF Receipt
141
+ Build a PDF receipt from the submission data using ` pdfkit ` .
168
142
169
143
``` ts title:form/receipt.ts
170
144
import PDFDocument from ' pdfkit'
@@ -235,6 +209,32 @@ Guests: ${guests}`,
235
209
}
236
210
```
237
211
212
+ Listen for submitted events and generate a formatted PDF receipt from the stored data.
213
+
214
+ ``` ts title:services/pdfs.ts
215
+ import { receipts , submissions , output } from ' ../resources/resources'
216
+ import { buildReceipt } from ' ../form/receipt'
217
+
218
+ receipts .subscribe (async (ctx ) => {
219
+ const { id, formId } = ctx .req .json ()
220
+ const submission = await submissions .get (id )
221
+
222
+ if (! submission ) {
223
+ console .error (` No submission found for ID: ${id } ` )
224
+ return
225
+ }
226
+
227
+ // Build the PDF buffer from the submission data
228
+ const buffer = await buildReceipt (submission , formId )
229
+
230
+ // Store the PDF file in the bucket
231
+ const file = output .file (` ${id }.pdf ` )
232
+ await file .write (buffer )
233
+
234
+ console .log (` Receipt stored for ${id } ` )
235
+ })
236
+ ```
237
+
238
238
This PDF output is fairly plain, you can enhance it further using layout templates or branding.
239
239
240
240
## Step 4: Delivery Logic
0 commit comments