Render PDF Documents with SuiteScript 2.x in NetSuite

Generate and render PDF documents using SuiteScript 2.x functionality within NetSuite.

·2 min read·View Oracle Docs

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:

ParameterTypeRequiredDescription
options.xmlStringstringRequiredThe 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 the options.xmlString parameter 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.

suitescript
1/**
2 * @NApiVersion 2.x
3 * @NScriptType Suitelet
4 */
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

Source: This article is based on Oracle's official NetSuite documentation.

Key Takeaways

  • Use renderPdf method from the N/http module for PDF generation.
  • Ensure the options.xmlString parameter 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?
No, the renderPdf method can only be utilized in server-side scripts, such as Suitelets.
What happens if I do not provide the options.xmlString parameter when calling the renderPdf method?
If you do not provide the options.xmlString parameter, you will encounter an SSS_MISSING_REQD_ARGUMENT error.
What governance cost is incurred when calling the renderPdf method in SuiteScript 2.x?
Each call to the renderPdf method incurs a cost of 10 governance units in NetSuite.
Is it necessary to use the define function for testing the renderPdf method in the SuiteScript Debugger?
No, for testing the renderPdf method in the SuiteScript Debugger, you should use the require function instead of the define function.
Source: Syntax Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in General

View all General articles →