Render PDF Documents Using SuiteScript 2.x in NetSuite
Generate PDF documents using SuiteScript 2.x renderPdf method in NetSuite. Generating and rendering PDF documents directly from scripts is essential for
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
- Common SuiteScript Errors and Solutions for NetSuite
Common NetSuite script errors include INVALID_SCRIPT_DEPLOYMENT_ID and SSS_AUTHORIZATION_HEADER_NOT_ALLOWED. Learn effective solutions.
- Set Sublist Field Values in SuiteScript 2.x for Record Management
Set sublist field values in SuiteScript 2.x for effective record management using standard and dynamic modes.
- Setting Field Values in SuiteScript for Effective Record
Learn to set field values in SuiteScript effectively, troubleshooting common errors and understanding data types.
- SuiteScript 2.1 Enhancements and API Updates in NetSuite
SuiteScript 2.1 enables execution of 2.0 scripts and supports PATCH method for enhanced API capabilities.
Advertising
Reach SuiteScript Professionals
Put your product in front of NetSuite experts who work with SuiteScript every day.
Sponsor This Category