A product order form that generates a PDF with a tabular breakdown of items, quantities, prices, and a calculated grand total. The table updates dynamically based on what the customer orders.
Real-world use case: A customer selects products and quantities. They receive an order confirmation PDF showing a professional table with Product | Quantity | Price | Total - just like a real invoice.
addTable(headers, rows)Every code snippet below is fully editable! Try changing the quantities in the form and watch the PDF table update dynamically.
Use the play button to run different snippets, or the refresh button to restore the original example.
Tables are perfect for showing line items. Use addTable(headers, rows) where headers is an array of column names and rows is a 2D array of cell values.
['Product', 'Quantity', 'Price', 'Total']. The second is an array of row arrays, where each inner array represents one row of data. Static data is boring! Let's build the table rows dynamically from form values. We'll also only show products that were actually ordered (quantity > 0).
formatCurrency() to format numbers as currency strings. Use form.integer('qty1')?.value() to get field values. push() rows conditionally. This way, if someone orders 0 of something, it won't appear in the PDF. Tables need context! Add a customer info section and some introductory text before the table using addText().
section.addText() to add descriptive text. Combine with addSpacer() to create visual breathing room before the table. Every order needs a grand total! Calculate the sum and display it prominently after the table using a divider for visual separation.
grandTotal by summing individual line totals. Use addDivider() and addSpacer() to visually separate the summary from the table. Time to finalize! Add footer, page numbers, item count, and helpful next-step messages for the customer.
addRow() to show "Total Items" and "Grand Total" side by side. This creates a professional summary layout. You've mastered tables! In the next tutorial, you'll learn how to make your PDF content dynamic - showing different sections based on user choices.
Continue to Dynamic PDF ContentKey concepts learned:
addTable(headers, rows) - Creating tables with headers and data rowsaddText()