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.
Source: This article is based on Oracle's official NetSuite documentation.
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 Platform
- Style Object Members for Workbook API in NetSuite
The Style object provides customizable properties for workbook formatting in NetSuite, enhancing report and visualization functionality.
- Asynchronous HTTP Requests with SuiteScript Promises
Use SuiteScript to send asynchronous HTTP requests with promises for efficient error handling and response processing.
- Setting Sublist Field Values in SuiteScript
Set values for sublist fields in SuiteScript using the setSublistValue method. Understand required parameters and error handling.
- In This Help Topic
Explore N/log module guidelines, log levels, and script execution logs for efficient logging in SuiteScript.
Advertising
Reach Platform Professionals
Put your product in front of NetSuite experts who work with Platform every day.
Sponsor This Category