Render PDF Documents with SuiteScript 2.x in NetSuite
Generate and render PDF documents using SuiteScript 2.x functionality within NetSuite. Generating and rendering PDF documents directly from scripts is essential
Generating and rendering PDF documents directly from scripts is essential for creating customized responses in applications. SuiteScript 2.x provides a straightforward method for achieving this through the N/http module.
How Does PDF Rendering Work?
The PDF rendering function allows developers to generate PDFs by sending XML content directly to the response stream. This is typically utilized in scripts that require producing formatted documents based on dynamic data.
Method Description
The renderPdf method specifically generates a PDF directly to the server's response.
Returns
- void: This method does not return any value after execution.
Supported Script Types
- Server Scripts: This method can only be used in server-side scripts, such as Suitelets.
Governance
- 10 units: Each call to this method incurs a governance unit cost.
Module Information
- Module: This function resides within the N/http Module.
Parameters
The options parameter must be a JavaScript object containing:
| Parameter | Type | Required | Description |
|---|---|---|---|
options.xmlString | string | Required | The XML content to be rendered in the PDF. |
Errors
When using this function, the following error might occur:
SSS_MISSING_REQD_ARGUMENT: This error is thrown if theoptions.xmlStringparameter is missing.
Sample Syntax
The following code illustrates how to render a PDF in a Suitelet. This example uses the define function, which is critical for defining an entry point script. If you are testing it in the SuiteScript Debugger, remember to use the require function instead.
1/**2 * @NApiVersion 2.x3 * @NScriptType Suitelet4 */5define(['N/xml'], function(xml) {6 return {7 onRequest: function(context) {8 var xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +9 "<!DOCTYPE pdf PUBLIC \"-//big.faceless.org//report\" \"report-1.1.dtd\">\n" +10 "<pdf lang=\"ru-RU\" xml:lang=\"ru-RU\">\n" +11 "<head>\n" +12 "<link name=\"russianfont\" type=\"font\" subtype=\"opentype\" " +13 "src=\"NetSuiteFonts/verdana.ttf\" " +14 "src-bold=\"NetSuiteFonts/verdanab.ttf\" " +15 "src-italic=\"NetSuiteFonts/verdanai.ttf\" " +16 "src-bolditalic=\"NetSuiteFonts/verdanabi.ttf\" " +17 "bytes=\"2\"/>\n" +18 "</head>\n" +19 "<body font-family=\"russianfont\" font-size=\"18\">\nРусский текст</body>\n" +20 "</pdf>";21 context.response.renderPdf(xml);22 }23 };24});This code defines a Suitelet that generates a PDF with embedded Russian text and custom fonts.
Related Topics
- http.ServerResponse
- N/http Module
- SuiteScript 2.x Modules
- SuiteScript 2.x
Key Takeaways
- Use
renderPdfmethod from theN/httpmodule for PDF generation. - Ensure the
options.xmlStringparameter is specified to avoid errors. - The method can only be executed within server-side scripts like Suitelets.
Frequently Asked Questions (4)
Can the renderPdf method be used in client-side scripts in NetSuite?
What happens if I do not provide the options.xmlString parameter when calling the renderPdf method?
What governance cost is incurred when calling the renderPdf method in SuiteScript 2.x?
Is it necessary to use the define function for testing the renderPdf method in the SuiteScript Debugger?
Was this article helpful?
More in SuiteScript
- SuiteScript 2.1 Enhancements in NetSuite February Updates
SuiteScript 2.1 now supports async features and PATCH method. Discover the latest API and SuiteProcurement improvements.
- Scheduling Map/Reduce Script Deployments in NetSuite
Learn to schedule map/reduce script submissions, including one-time and recurring options in NetSuite.
- Binary File Support in N/https Module for SuiteScript
SuiteScript enhances capabilities with binary file support in the N/https module, allowing improved data handling in external communications.
- API Governance Units Calculation in NetSuite 2026.1
NetSuite 2026.1 introduces examples illustrating API governance unit calculations for both user event and scheduled scripts.
