PDF Customization
Generate customized PDF documents for invoices, reports, and custom outputs.
PDF Generation Approaches
THREE APPROACHES TO PDF GENERATION
-------------------------------------------------------------------------------
1. ADVANCED PDF TEMPLATES (Built-in)
+-----------------------------------------------------------------------------+
| What: Template-based PDF customization |
| How: XML/FreeMarker templates in NetSuite UI |
| Best for: Transaction documents (invoices, POs, statements) |
| Requires: Template knowledge, XML/HTML |
+-----------------------------------------------------------------------------+
2. SUITELET PDF GENERATION (Script-Driven)
+-----------------------------------------------------------------------------+
| What: Generate PDFs programmatically via SuiteScript |
| How: N/render module creates PDFs from templates or HTML |
| Best for: Custom reports, user-triggered exports, dynamic documents |
| Requires: SuiteScript knowledge |
+-----------------------------------------------------------------------------+
3. BULK PDF (Map/Reduce)
+-----------------------------------------------------------------------------+
| What: High-volume batch PDF generation |
| How: Map/Reduce script processes thousands of records |
| Best for: Monthly statements, bulk invoices, mass document generation |
| Requires: SuiteScript, Map/Reduce pattern |
+-----------------------------------------------------------------------------+
Choosing the Right Approach
| Scenario | Recommended Approach |
|---|---|
| Custom invoice layout | Advanced PDF Template |
| Custom packing slip | Advanced PDF Template |
| Sales order form | Advanced PDF Template |
| Custom report from Suitelet | Suitelet PDF Generation |
| User-triggered export | Suitelet PDF Generation |
| Print 1,000+ invoices | Bulk PDF (Map/Reduce) |
| Monthly statement batch | Bulk PDF (Map/Reduce) |
Quick Comparison
FEATURE COMPARISON
-------------------------------------------------------------------------------
Feature | Advanced PDF | Suitelet PDF | Bulk PDF
------------------------+-----------------+-----------------+----------------
Template Location | NetSuite UI | File Cabinet | File Cabinet
------------------------+-----------------+-----------------+----------------
Coding Required | XML/HTML | SuiteScript | SuiteScript
------------------------+-----------------+-----------------+----------------
Volume | Single record | Low-Medium | High (1000+)
------------------------+-----------------+-----------------+----------------
Trigger | Print button | Script/Suitelet | Scheduled
------------------------+-----------------+-----------------+----------------
Best Use Case | Transactions | Reports/Forms | Bulk exports
Architecture Overview
PDF GENERATION FLOW
-------------------------------------------------------------------------------
ADVANCED PDF TEMPLATE:
+-----------------------------------------------------------------------------+
| Transaction Record --> Template Engine --> PDF Output |
| (Invoice) (BFO/FreeMarker) (Download/Email) |
+-----------------------------------------------------------------------------+
SUITELET PDF:
+-----------------------------------------------------------------------------+
| Suitelet Script --> N/render Module --> PDF File --> Response |
| (User Request) (mergeEmail/xmlToPdf) (File Cabinet) (Download) |
+-----------------------------------------------------------------------------+
BULK PDF (MAP/REDUCE):
+-----------------------------------------------------------------------------+
| Scheduled/On-Demand --> Map: Load Records --> Reduce: Create PDFs |
| (Transaction List) (Save to Cabinet/Email) |
+-----------------------------------------------------------------------------+
Template Basics
All PDF approaches share common concepts:
1. Document Structure
<?xml version="1.0"?>
<!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">
<pdf>
<head>
<style type="text/css">
/* CSS styles here */
</style>
</head>
<body size="Letter">
<!-- Content here -->
</body>
</pdf>
2. Data Access
Accessing Record Data:
${record.field} - Standard field
${record.custbody_xxx} - Custom body field
${item.custcol_xxx} - Custom column field (in loop)
Accessing Related Records:
${record.field@subfield} - Field from linked record
${record.recmachfield} - Child records (Record is Parent)
3. Output Options
OUTPUT OPTIONS
-------------------------------------------------------------------------------
DISPLAY IN BROWSER:
+-----------------------------------------------------------------------------+
| context.response.writeFile({ |
| file: pdfFile, |
| isInline: true // Display in browser |
| }); |
+-----------------------------------------------------------------------------+
FORCE DOWNLOAD:
+-----------------------------------------------------------------------------+
| context.response.writeFile({ |
| file: pdfFile, |
| isInline: false // Force download |
| }); |
+-----------------------------------------------------------------------------+
SAVE TO FILE CABINET:
+-----------------------------------------------------------------------------+
| var pdfFile = render.xmlToPdf({ xmlString: pdfContent }); |
| pdfFile.folder = 123; // File Cabinet folder ID |
| pdfFile.name = 'Invoice-' + invoiceId + '.pdf'; |
| var fileId = pdfFile.save(); |
| |
| // Optionally attach to record |
| record.attach({ |
| record: {type: 'file', id: fileId}, |
| to: {type: 'invoice', id: invoiceId} |
| }); |
+-----------------------------------------------------------------------------+
EMAIL ATTACHMENT:
+-----------------------------------------------------------------------------+
| email.send({ |
| author: employeeId, |
| recipients: [customerId], |
| subject: 'Your Invoice', |
| body: 'Please find attached...', |
| attachments: [pdfFile] |
| }); |
+-----------------------------------------------------------------------------+
PDF Topics
| Topic | Description |
|---|---|
| Advanced PDF Templates → | Built-in template customization with step-by-step tutorials |
| Suitelet PDF Generation → | Script-driven PDF creation |
| Bulk PDF Generation → | High-volume batch processing |
Common Use Cases
ADVANCED PDF TEMPLATES:
+-----------------------------------------------------------------------------+
| - Custom branded invoices |
| - Purchase orders with company logo |
| - Packing slips with warehouse instructions |
| - Statements with payment history |
| - Sales orders with terms |
| - Return authorizations |
+-----------------------------------------------------------------------------+
SUITELET PDF:
+-----------------------------------------------------------------------------+
| - Custom reports (sales summaries, inventory reports) |
| - Employee documents (offer letters, contracts) |
| - User-requested exports |
| - Dashboard PDF exports |
| - Certificate generation |
+-----------------------------------------------------------------------------+
BULK PDF (MAP/REDUCE):
+-----------------------------------------------------------------------------+
| - Monthly customer statements (1000+ customers) |
| - Mass invoice printing |
| - End-of-year tax documents |
| - Archival document generation |
| - Scheduled report distribution |
+-----------------------------------------------------------------------------+
Getting Started Checklist
| Step | Advanced PDF | Suitelet PDF | Bulk PDF |
|---|---|---|---|
| 1 | Navigate to Templates | Create Suitelet script | Create Map/Reduce script |
| 2 | Create new template | Define HTML/XML template | Query records in getInputData |
| 3 | Add XML/FreeMarker code | Use N/render module | Generate PDFs in map/reduce |
| 4 | Link to transaction form | Deploy Suitelet | Deploy script + schedule |
| 5 | Test with Print button | Test via URL | Monitor script execution |
References
- SuiteScript N/render Module - Official documentation
- BFO Report Generator - Template engine documentation
- FreeMarker Manual - Template language reference