ServerResponse PDF Rendering in NetSuite

Learn PDF rendering using the ServerResponse.renderPdf method in SuiteScript.

·2 min read·View Oracle Docs

The ServerResponse.renderPdf(options) method in SuiteScript allows developers to generate and send a PDF directly as a response within server scripts. This is crucial for creating dynamic documents on-the-fly in applications.

How Does the renderPdf Method Work?

The method uses a JavaScript object parameter, options, which must include an xmlString. This string is the content to be rendered into the PDF. Notably, the method does not return any value, operating in a 'void' context.

Key Parameters

  • options.xmlString: Type: string | Required: Yes | Description: The XML content of the PDF to be rendered.

Common Errors

Understanding potential errors is critical for efficient debugging:

  • Error Code: SSS_MISSING_REQD_ARGUMENT
    • Message: Missing a required argument: {param name}
    • Thrown If: The options.xmlString parameter is not specified.

Example Usage

Here's a basic example demonstrating how to use the renderPdf method:

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});

Who This Affects

  • Developers: Writing server-side scripts requiring PDF generation.
  • Administrators: Managing and deploying SuiteScripts.

Key Takeaways

  • The renderPdf method is vital for generating PDFs in server scripts.
  • The options.xmlString parameter is essential and required.
  • Ensure correct XML formatting to avoid errors during rendering.

Frequently Asked Questions (4)

What script types support PDF generation in SuiteScript?
PDF generation is supported in server-side contexts, particularly through Suitelet scripts.
What is the governance impact of rendering PDFs in SuiteScript?
Rendering PDFs in SuiteScript consumes 10 governance units per execution.
What required parameter must be provided to avoid errors when generating PDFs?
The required parameter is `options.xmlString`, which must contain the XML content for the PDF.
What does the error code SSS_MISSING_REQD_ARGUMENT indicate in PDF rendering?
The error code SSS_MISSING_REQD_ARGUMENT indicates that a required argument, such as `options.xmlString`, is missing.
Source: Errors 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 Platform

View all Platform articles →