PDFGenerationAPI - Scoped, Global
-
- UpdatedJan 30, 2025
- 32 minutes to read
- Yokohama
- API reference
The PDFGenerationAPI provides support for PDF conversion and handling PDF fields.
This API is part of the ServiceNow PDF
Generation Utilities plugin (com.snc.apppdfgenerator) and is provided within the
sn_pdfgeneratorutils
namespace. The plugin is activated by default.
Use the glide.pdf.url.whitelist property to add an extra layer of validation to ensure whether any external URL introduced should be included in the generated PDF. If the system property glide.pdf.url.whitelisting.enabled is set to true, the PDF does not process URL content unless it is listed in the Value field of the com.snc.pdf.whitelisted_urls system property. These properties are listed in the System Properties [sys_properties] table. For more information, see Available system properties.
- Dynamically generate a PDF from an HTML string and attach it to a record
- A4 size without headers or footers – PDFGenerationAPI – convertToPDF(String html, String targetTable, String targetTableSysId, String pdfName, String fontFamilySysId, Object documentConfiguration)
- Customizable page size with options for header and footer – PDFGenerationAPI – convertToPDFWithHeaderFooter(String html, String targetTable, String targetTableSysId, String pdfName, Object headerFooterInfo, String fontFamilySysId, Object documentConfiguration)
- Queue a PDF to be generated from an HTML string and attached to a record
- A4 size without headers or footers – PDFGenerationAPI – convertToPDFAsync(String html, String targetTable, String targetTableSysId, String pdfName, String fontFamilySysId, Object documentConfiguration)
- Customizable page size with options for header and footer – PDFGenerationAPI – convertToPDFWithHeaderFooterAsync(String html, String targetTable, String targetTableSysId, String pdfName, Object headerFooterInfo, String fontFamilySysId, Object documentConfiguration)
- Fill fields in a PDF
- PDFGenerationAPI – fillDocumentFieldsAndFlatten(Object fieldsMap, String sysId, String tableName, String tableSysId, String pdfName, Object flatten)
- PDFGenerationAPI – fillDocumentFields(Object fieldsMap, String sysId, String tableName, String tableSysId, String pdfName)
- PDFGenerationAPI – isDocumentFillable(String sysId)
- Sign a PDF
- PDFGenerationAPI – fillFieldsAndMergeSignature(Object fieldsMap, String sysId, String tableName, String tableSysId, String pdfName, PdfMergeSignRequestor requestor, Object flatten)
- PDFGenerationAPI – getFilledDocumentWithSignatureAsBase64(Object fieldsMap, String sysId, PdfMergeSignRequestor requestor, Object flatten)
- Restrict editing filled fields as flattened or partially flattened – PDFGenerationAPI – fillDocumentFieldsAndFlatten(Object fieldsMap, String sysId, String tableName, String tableSysId, String pdfName, Object flatten)
- Retrieve PDF page size and field data
- Redact information in a PDF – PDFGenerationAPI – redact(Object inputJson)
PDFGenerationAPI – PDFGenerationAPI()
Instantiates a new PDFGenerationAPI object.
Name | Type | Description |
---|---|---|
None |
Example
The following example shows how to create a PDFGenerationAPI object.
PDFGenerationAPI – convertToPDF(String html, String targetTable, String targetTableSysId, String pdfName, String fontFamilySysId, Object documentConfiguration)
Converts an HTML string to a PDF document.
This method creates a PDF using the page size A4 – 595 × 842 points. Content will be truncated if it exceeds this size.
To generate a PDF with additional settings, such as page size, orientation, and page numbers, use convertToPDFWithHeaderFooter().
Example
The following example shows how to convert HTML to a PDF and attach it to a record in the Incident [incident] table.
Output:
PDFGenerationAPI – convertToPDFAsync(String html, String targetTable, String targetTableSysId, String pdfName, String fontFamilySysId, Object documentConfiguration)
Stages a job that converts an HTML string to a PDF document asynchronously. Asynchronous processing enables you to work in the instance while the PDF conversion is in progress. This is especially helpful for larger PDF exports.
This API creates a PDF using the page size A4 – 595 × 842 points. Content will be truncated if it exceeds this size.
To generate a PDF with additional settings, such as page size, orientation, and page numbers, use convertToPDFWithHeaderFooterAsync().
Type | Description |
---|---|
Object | Object indicating whether the PDF conversion is in progress. You can review the conversion status in the PDF Generation Status [sys_pdf_generation_status] table. |
<Object>.message | Message confirming success or error.
Possible values:
Data type: String |
<Object>.request_id | Sys_id of the
change
producer request record. Data type: String |
Example
The following example shows how to queue a task that converts HTML to a PDF. When the conversion is complete, the PDF named "myPDF" is attached to the target record in the Incident [incident] table.
Output:
PDFGenerationAPI – convertToPDFWithHeaderFooter(String html, String targetTable, String targetTableSysId, String pdfName, Object headerFooterInfo, String fontFamilySysId, Object documentConfiguration)
Converts an HTML string into a PDF with header and footer content.
- Header and footer information
- Margin sizes
- Orientation
- Enumeration
- Page size
Example
The following example shows how to convert HTML to a PDF named "myPDF" and add the PDF as an attachment to a record in the Incident [incident] table. The PDF contains header and footer provided via attachment.
Output:
PDFGenerationAPI – convertToPDFWithHeaderFooterAsync(String html, String targetTable, String targetTableSysId, String pdfName, Object headerFooterInfo, String fontFamilySysId, Object documentConfiguration)
Stages a job that converts an HTML string into a PDF with header and footer content asynchronously. Asynchronous processing enables you to work in the instance while the PDF conversion is in progress. This is especially helpful for larger PDF exports.
- Header and footer information
- Margin sizes
- Orientation
- Enumeration
- Page size
Type | Description |
---|---|
Object | |
<Object>.message | Message confirming success or error.
Possible values:
Data type: String |
<Object>.request_id | Sys_id of the
change
producer request record. Data type: String |
Example
The following example shows how to queue a task that converts HTML to a PDF. The PDF contains header and footer provided via attachment. When the conversion is complete, the PDF named "myPDF" is attached to the target record in the Incident [incident] table.
Output:
PDFGenerationAPI – fillDocumentFields(Object fieldsMap, String sysId, String tableName, String tableSysId, String pdfName)
Fills fields in an editable PDF and attaches it to the provided record.
- fillDocumentFieldsAndFlatten() – Fills fields in an editable PDF, flattens the data fields, and attaches it to the provided record.
- fillFieldsAndMergeSignature() – Fills fields in an editable PDF, adds signature image, flattens the data fields, and attaches it to the provided record.
- getFilledDocumentWithSignatureAsBase64() – Fills fields in an editable PDF, creates an image, and converts it to a Base64-encoded PDF.
Example
The following example shows how to fill fields in an editable PDF.
Output:
PDFGenerationAPI – fillDocumentFieldsAndFlatten(Object fieldsMap, String sysId, String tableName, String tableSysId, String pdfName, Object flatten)
Fills fields in an editable PDF, flattens the data fields, and attaches it to the provided record.
- fillDocumentFields() – Fills fields in an editable PDF and attaches it to the provided record.
- fillFieldsAndMergeSignature() – Fills fields in an editable PDF, adds signature image, flattens the data fields, and attaches it to the provided record.
- getFilledDocumentWithSignatureAsBase64() – Fills fields in an editable PDF, creates an image, and converts it to a Base64-encoded PDF.
Example
The following example shows how to fill fields and flatten an editable PDF.
Output:
PDFGenerationAPI – fillFieldsAndMergeSignature(Object fieldsMap, String sysId, String tableName, String tableSysId, String pdfName, PdfMergeSignRequestor requestor, Object flatten)
Fills fields in an editable PDF, adds signature image, flattens the data fields, and attaches it to the provided record.
- fillDocumentFields() – Fills fields in an editable PDF and attaches it to the provided record.
- fillDocumentFieldsAndFlatten() – Fills fields in an editable PDF, flattens the data fields, and attaches it to the provided record.
- getFilledDocumentWithSignatureAsBase64() – Fills fields in an editable PDF, creates an image, and converts it to a Base64-encoded PDF.
Example
The following example shows how to fill fields with signature with default settings to completely flatten the fields.
PDFGenerationAPI – getDocumentFields(String sysId)
Gets a list of editable fields in a PDF document. Enables listing editable PDF fields without manually opening the file to check.
Name | Type | Description |
---|---|---|
sysId | String | Sys_id of a PDF in the Attachments [sys_attachment] table. |
Example
The following example shows how to retrieve fields in a PDF attachment.
Output:
PDFGenerationAPI – getDocumentFieldsType(String sysId)
Gets the field type of set of editable fields from a PDF document.
Name | Type | Description |
---|---|---|
sysId | String | Sys_id of a PDF in the Attachments [sys_attachment] table. |
Example
The following example shows how to retrieve field types in a PDF attachment. Results include manual returns for readability and are truncated for brevity.
Output:
PDFGenerationAPI – getFilledDocumentWithSignatureAsBase64(Object fieldsMap, String sysId, PdfMergeSignRequestor requestor, Object flatten)
Fills fields in an editable PDF, creates an image, and converts it to a Base64-encoded PDF.
Base64 encoding enables you to output a PDF as a string within a text document, such as HTML or JSON, without damaging the binary character syntax.
- fillDocumentFields() – Fills fields in an editable PDF and attaches it to the provided record.
- fillDocumentFieldsAndFlatten() – Fills fields in an editable PDF, flattens the data fields, and attaches it to the provided record.
- fillFieldsAndMergeSignature() – Fills fields in an editable PDF, adds signature image, flattens the data fields, and attaches it to the provided record.
Type | Description |
---|---|
String | If successful, PDF converted to Base64 format is added to the Attachments table [sys_attachment]. Contents reflect the PDF attachment provided with fields and signature filled. The fields are not editable unless an alternative flattening option was provided with the flatten parameter. |
<Object>.message | Message confirming success or error.
Valid values:
Data type: String |
<Object>.status | Status indicating whether the operation is successful. Possible values:
Data type: String |
Example
The following example shows how to load two fields in a PDF attachment, flatten the fields, and convert the PDF to Base64 format.
PDFGenerationAPI – getPdfPageSizes(String sysId)
Gets the page size of a PDF document.
Name | Type | Description |
---|---|---|
sysId | String | Sys_id of a PDF in the Attachments [sys_attachment] table. |
Example
The following example shows how to display the width and height of each page in a PDF attachment.
Output:
PDFGenerationAPI – isDocumentFillable(String sysId)
Checks if the PDF document contains editable fields.
Name | Type | Description |
---|---|---|
sysId | String | Sys_id of a PDF in the Attachments [sys_attachment] table. |
Example
The following example shows how to determine if PDF document fields are editable.
Output:
PDFGenerationAPI – redact(Object inputJson)
Applies redaction to a PDF document based on the given rectangle coordinates, search keywords, or both. A redacted copy of the original PDF is generated in the Attachments [sys_attachment] table.
- Redaction results might include an unexpected white redacted text block that overwrites text not intended to be redacted. If this event occurs, you can manually select the content for redaction using the highlightedSections property or the PDF Generation Utilities plugin. For more information, see Redact data from documents.
- This method doesn’t support redaction in PDFs containing JBIG2 images.
Example
The following example shows how to redact by rectangle and key word. On the redacted PDF, the areas selected on page 2 are blocked out. The string '23' is redacted on any page that it's found on.
Output:
On this page
- PDFGenerationAPI – PDFGenerationAPI()
- PDFGenerationAPI – convertToPDF(String html, String targetTable, String targetTableSysId,
String pdfName, String fontFamilySysId, Object documentConfiguration)
- PDFGenerationAPI – convertToPDFAsync(String html, String targetTable, String targetTableSysId, String pdfName, String fontFamilySysId, Object documentConfiguration)
- PDFGenerationAPI – convertToPDFWithHeaderFooter(String html, String targetTable, String
targetTableSysId, String pdfName, Object headerFooterInfo, String fontFamilySysId, Object
documentConfiguration)
- PDFGenerationAPI – convertToPDFWithHeaderFooterAsync(String html, String targetTable, String targetTableSysId, String pdfName, Object headerFooterInfo, String fontFamilySysId, Object documentConfiguration)
- PDFGenerationAPI – fillDocumentFields(Object fieldsMap, String sysId, String tableName,
String tableSysId, String pdfName)
- PDFGenerationAPI – fillDocumentFieldsAndFlatten(Object fieldsMap, String sysId, String
tableName, String tableSysId, String pdfName, Object flatten)
- PDFGenerationAPI – fillFieldsAndMergeSignature(Object fieldsMap, String sysId, String
tableName, String tableSysId, String pdfName, PdfMergeSignRequestor requestor, Object
flatten)
- PDFGenerationAPI – getDocumentFields(String sysId)
- PDFGenerationAPI – getDocumentFieldsType(String sysId)
- PDFGenerationAPI – getFilledDocumentWithSignatureAsBase64(Object fieldsMap, String sysId,
PdfMergeSignRequestor requestor, Object flatten)
- PDFGenerationAPI – getPdfPageSizes(String sysId)
- PDFGenerationAPI – isDocumentFillable(String sysId)
- PDFGenerationAPI – redact(Object inputJson)