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 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
Source: This article is based on Oracle's official NetSuite documentation.
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 General
- Payment Date Prediction Feature in NetSuite
Payment Date Prediction in NetSuite utilizes machine learning to enhance financial planning by predicting invoice payment dates.
- NetSuite Ship Central Enhancements for Packing & Shipping
NetSuite Ship Central features enhance packing and shipping operations for improved efficiency and accuracy.
- New Role Setup for NetSuite AI Connector Service in 2026.1
The 2026.1 release adds a new role requirement for the NetSuite AI Connector Service, streamlining custom tool development.
- Generative AI Features in NetSuite 2026.1
Discover new generative AI features in NetSuite 2026.1, enhancing reporting, search, predictions, and development productivity.
Advertising
Reach General Professionals
Put your product in front of NetSuite experts who work with General every day.
Sponsor This Category