PDF Rendering with SuiteScript 2.x for Seamless Reports
SuiteScript 2.x allows seamless PDF rendering via server scripts, enhancing report generation efficiency and customization options.
The method described here allows developers to generate and render PDFs directly within their NetSuite applications using SuiteScript 2.x. This feature is essential for producing custom reports and documents that meet specific business needs, ensuring a streamlined output for various processes.
Method Overview
The method generates and sends a PDF directly to the response. This functionality is crucial for scenarios where visual reports are required, allowing users to download or view PDF files instantly in their workflows.
Returns
- void: This method does not return any value upon completion.
Supported Script Types
- Server scripts: Specifically designed to run on the server side, these scripts are pivotal in executing tasks that require backend support.
Governance
- 10 units: The operation deducts governance units from your account, so use it judiciously to stay within your limits.
Parent Object
- http.ServerResponse: This method is a member of the
http.ServerResponseobject, which encapsulates the HTTP response elements relevant to Suitelet scripts.
Parameter Details
The method accepts a single parameter, options, which must be an object containing specific properties:
| Parameter | Type | Required | Description |
|---|---|---|---|
options.xmlString | string | Yes | The XML content for the PDF document. |
Error Handling
If the required parameter is not provided, the following error is thrown:
- Error Code:
SSS_MISSING_REQD_ARGUMENT - Message: Missing a required argument: {param name}.
For instance, if options.xmlString is not specified, this error will occur.
Syntax Example
Below is a syntax example illustrating how to generate a PDF in a Suitelet script. Note that the define function must be used for scripting entry points.
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\">11" +12 "<head>\n" +13 "<link name=\"russianfont\" type=\"font\" subtype=\"opentype\" " +14 "src=\"NetSuiteFonts/verdana.ttf\" " +15 "src-bold=\"NetSuiteFonts/verdanab.ttf\" " +16 "src-italic=\"NetSuiteFonts/verdanai.ttf\" " +17 "src-bolditalic=\"NetSuiteFonts/verdanabi.ttf\" " +18 "bytes=\"2\"/>19" +20 "</head>\n" +21 "<body font-family=\"russianfont\" font-size=\"18\">\nРусский текст</body>\n" +22 "</pdf>";23 context.response.renderPdf(xml);24 }25 };26});Conclusion
Employing PDF rendering capabilities in SuiteScript 2.x leverages the flexibility of XML to create customized reports, ensuring users get the output needed in a format they can utilize effectively.
Frequently Asked Questions (4)
What script types support PDF rendering in SuiteScript 2.x?
What happens if the required parameter 'options.xmlString' is not provided?
How many governance units does the PDF rendering operation consume?
What permissions or prerequisites are required to render PDFs using SuiteScript 2.x?
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.
