A simple contact form that generates a downloadable PDF confirmation. When users submit the form, they'll see a "Download Confirmation" button that creates a professional PDF document with all their submission details.
Real-world use case: A customer fills out a support request. After submitting, they can download a PDF receipt showing exactly what they submitted and when - perfect for their records.
configurePdf()addField() and addText()allowUserDownloadEvery code snippet below is fully editable! Feel free to modify the code, experiment with different values, and see your changes reflected instantly in the live preview on the right.
Use the play button to run different snippets, or the refresh button to restore the original example.
Let's add PDF generation to our contact form. The magic happens with form.configurePdf(). This tells the system "I want to create a PDF document from this form."
'confirmation' is a unique ID for this PDF. You can have multiple PDFs per form (we'll cover that in a later tutorial). The second parameter is a builder function where you'll configure everything. When users download the PDF, what should the file be called? Use filename to set a meaningful name.
Every professional document needs a header. Add a title and optional subtitle that appear at the top of your PDF.
title for the document name and the subtitle for additional context like dates or reference numbers. Now the important part - showing the actual form data! Use addSection() to create a titled section, then add rows with addField() to display label-value pairs.
form.textbox('name')?.value() to get the current value of a field. The ?. handles cases where the field might not exist, and ?? '' provides a fallback empty string. Time to put it all together! Add allowUserDownload: true to show the download button, customize its label, and add a footer message.
You've created your first PDF! In the next tutorial, you'll learn how to make it look more professional with advanced styling, headers, footers, and page layouts.
Continue to Professional StylingKey concepts learned:
configurePdf(id, builder) - Enable PDF generationpdf.configure(...) - Set filename, header, footerpdf.addSection(title, builder) - Create titled sectionssection.addRow() and row.addField() - Display dataallowUserDownload: true - Show download button