PDFGenerationAPI - Scoped, Global
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.
Note: The maximum PDF size is 50 MB.
The methods in this class enable the following tasks:
- 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)
Note: These methods can also be used for documents created by non-catalog items.
Related APIs:
Parent Topic:Server API reference
PDFGenerationAPI – PDFGenerationAPI()
Instantiates a new PDFGenerationAPI object.
| Name | Type | Description |
|---|---|---|
| None |
The following example shows how to create a PDFGenerationAPI object.
var v = new sn_pdfgeneratorutils.PDFGenerationAPI;
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().
| Name | Type | Description |
|---|---|---|
| html | String | HTML to convert to a PDF document. |
| targetTable | String | Name of the table on which to attach the converted PDF. |
| targetTableSysId | String | Sys\_id of the record on which to attach the converted PDF. |
| pdfName | String | Name to give the PDF.Default: Sys\_id of the PDF in the Attachments \[sys\_attachment\] table. |
| fontFamilySysId | String | Optional. Sys\_id of the font family to use for the PDF. This sys\_id is from the PDF Generation Font Family \[sys\_pdf\_generation\_font\_family\] table.Default: none |
| documentConfiguration | Object | Optional. Object containing a table of contents configuration and a page number configuration. |
| documentConfiguration.accessibilityEnabled | Boolean | Optional. Flag that indicates whether to format the generated PDF to support accessibility. When this feature is enabled, accessibility tags will be available in the PDF tag tree to help users who rely on screen readers to navigate, understand, and interact with the generated PDF documents.Valid values: - true: The generated PDF is formatted for accessibility. - false: The generated PDF is not formatted for accessibility. Default: False |
| documentConfiguration.toc\_config | String | Optional. Sys\_id of the table of contents configuration to use for the PDF. This sys\_id is from the Table of Contents Configuration \[doc\_toc\_config\] table.Default: none |
| documentConfiguration.page\_number\_config | String | Optional. Sys\_id of the page number configuration to use for the PDF. This sys\_id is from the Page Number Configuration \[doc\_page\_number\_config\] table.Default: none |
| Type | Description |
|---|---|
| Object | Object containing sys\_id of the PDF attachment if conversion is successful, error message otherwise. |
| <Object>.attachment\_id | If HTML conversion is successful, sys\_id of the converted and attached PDF. The file is listed in the Attachments \[sys\_attachment\] table.Data type: String |
| <Object>.message | Message confirming success or error. Possible values: - Conversion failed. – No PDF created. Make sure the values provided are accurate. - Conversion is successful. – The HTML successfully converted to PDF. - Exception while reading Source document contents. PDF header not found. – Input attachment provided is not a valid PDF. Provide the correct attachment sys\_id. - Given target record \[<tableName> - <targetTableSysId>\] does not exist. – Target table sys\_id is not in the table provided. Make sure you include the correct table name for the record. - No Form associated with pdf to fill. attachmentSysId: <sys\_id> - No editable fields exist with specified names. Please check and try again. field names: <field names> - Request cannot proceed as the attachment with sys\_id \[\{0\}\] did not pass security scan – The PDF did not pass the antivirus scan. - Request cannot proceed as the attachment with sys\_id \[\{0\}\] is pending security scan – The PDF requires an antivirus scan. - Request completed successfully – Operation is successful. - Undefined – Sys\_id provided does not exist or is not a PDF attachment. - <URL> is not listed in whitelisted URL, please check URL whitelisting property : "glide.pdf.url.whitelisting.enabled" and "com.snc.pdf.whitelisted\_urls" – 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. Data type: String |
| <Object>.request\_id | Sys\_id of the change producer request record.Data type: String |
| <Object>.status | Status indicating whether the operation is successful.Possible values:
Data type: String |
The following example shows how to convert HTML to a PDF and attach it to a record in the Incident [incident] table.
var v = new sn_pdfgeneratorutils.PDFGenerationAPI;
// (Option) get HTML from the description field of an incident record
var gr = new GlideRecord("incident");
var html;
if (gr.get("<tableSysId>")) {
html = gr.description.toString();
}
var result = v.convertToPDF(html, "incident", "<target_sys_id>", "myPDF");
gs.info(JSON.stringify(result));
Output:
{"attachment_id":"<sys_id>","message":"Conversion is successful.","request_id":"<change_sys_id>","status":"success"}
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().
| Name | Type | Description |
|---|---|---|
| html | String | HTML to convert to a PDF document. |
| targetTable | String | Name of the table on which to attach the converted PDF. |
| targetTableSysId | String | Sys\_id of the record on which to attach the converted PDF. |
| pdfName | String | Name to give the PDF.Default: Sys\_id of the PDF in the Attachments \[sys\_attachment\] table. |
| fontFamilySysId | String | Optional. Sys\_id of the font family to use for the PDF. This sys\_id is from the PDF Generation Font Family \[sys\_pdf\_generation\_font\_family\] table.Default: none |
| documentConfiguration | Object | Optional. Object containing a table of contents configuration and a page number configuration. |
| documentConfiguration.accessibilityEnabled | Boolean | Optional. Flag that indicates whether to format the generated PDF to support accessibility. When this feature is enabled, accessibility tags will be available in the PDF tag tree to help users who rely on screen readers to navigate, understand, and interact with the generated PDF documents.Valid values: - true: The generated PDF is formatted for accessibility. - false: The generated PDF is not formatted for accessibility. Default: False |
| documentConfiguration.toc\_config | String | Optional. Sys\_id of the table of contents configuration to use for the PDF. This sys\_id is from the Table of Contents Configuration \[doc\_toc\_config\] table.Default: none |
| documentConfiguration.page\_number\_config | String | Optional. Sys\_id of the page number configuration to use for the PDF. This sys\_id is from the Page Number Configuration \[doc\_page\_number\_config\] table.Default: none |
| 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: - HTML to PDF Conversion is in progress. – Request to convert HTML to a PDF document is successful. - Exception while reading Source document contents. PDF header not found. – Input attachment provided is not a valid PDF. Provide the correct attachment sys\_id. - Given target record \[<tableName> - <targetTableSysId>\] does not exist. – Target table sys\_id is not in the table provided. Make sure you include the correct table name for the record. - No Form associated with pdf to fill. attachmentSysId: <sys\_id> - No editable fields exist with specified names. Please check and try again. field names: <field names> - Request cannot proceed as the attachment with sys\_id \[\{0\}\] did not pass security scan – The PDF did not pass the antivirus scan. - Request cannot proceed as the attachment with sys\_id \[\{0\}\] is pending security scan – The PDF requires an antivirus scan. - Undefined – Sys\_id provided does not exist or is not a PDF attachment. - <URL> is not listed in whitelisted URL, please check URL whitelisting property : "glide.pdf.url.whitelisting.enabled" and "com.snc.pdf.whitelisted\_urls" – 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. Data type: String |
| <Object>.request\_id | Sys\_id of the change producer request record.Data type: String |
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.
var v = new sn_pdfgeneratorutils.PDFGenerationAPI;
// (Option) get HTML from the description field of an incident record
var gr = new GlideRecord("incident");
var html;
if (gr.get("<tableSysId>")) {
html = gr.description.toString();
}
var result = v.convertToPDFAsync(html, "incident", "<target_sys_id>", "myPDF");
gs.info(JSON.stringify(result));
Output:
{"message":"HTML to PDF Conversion is in progress.","request_id":"<sys_id>"}
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.
Use this method to generate PDFs with page settings:
- Header and footer information
- Margin sizes
- Orientation
- Enumeration
- Page size
| Name | Type | Description |
|---|---|---|
| html | String | HTML to convert to a PDF document. |
| targetTable | String | Name of the table on which to attach the converted PDF. |
| targetTableSysId | String | Sys\_id of the record on which to attach the converted PDF. |
| pdfName | String | Name to give the PDF.Default: Sys\_id of the PDF in the Attachments \[sys\_attachment\] table. |
| headerFooterInfo | Object | Defines PDF header and footer details. |
| headerFooterInfo.FooterImageAlignment | String | Sets the image position in the footer.Valid values: - BOTTOM\_CENTER: Position the image in the bottom center of the footer. - BOTTOM\_LEFT: Position the image in the bottom left area of the footer. - BOTTOM\_RIGHT: Position the image in the bottom right area of the footer. - TOP\_CENTER: Position the image in the top center of the footer. - TOP\_LEFT: Position the image in the top left area of the footer. - TOP\_RIGHT: Position the image in the top right area of the footer. |
| headerFooterInfo.FooterImageAttachmentId | String | Sys_id of the footer image in the Attachments [sys_attachment] table.To determine if the file type is supported in your instance, Navigate to System Properties, Security, and check if it's listed in List of file extensions (comma-separated) that can be attached field. |
| headerFooterInfo.FooterImageHeight | String | Height of footer image.Default: 50 points |
| headerFooterInfo.FooterText | String | Footer text to place at the bottom of each PDF page. |
| headerFooterInfo.FooterTextAlignment | String | Sets the text position in the footer. Make sure this value does not match or conflict with the area provided in headerFooterInfo.FooterImageAlignment.Valid values:
|
| headerFooterInfo.GeneratePageNumber | String | Flag that indicates whether to generate a PDF page number.Valid values: - true: Generate page numbers. - false: Do not generate page numbers. Default: true |
| headerFooterInfo.HeaderImageAlignment | String | Sets the image position in the header.Valid values: - center: Position the image in the center of the header. - left: Position the image on the left side of the header. - right: Position the image on the right side of the header. |
| headerFooterInfo.HeaderImageAttachmentId | String | Sys_id of the header image in the Attachments [sys_attachment] table.To determine if the file type is supported in your instance, Navigate to System Properties, Security, and check if it's listed in List of file extensions (comma-separated) that can be attached field. |
| headerFooterInfo.HeaderImageHeight | String | Height of the header image. Default: 50 points |
| headerFooterInfo.LeftOrRightMargin | String | Size of the left and right margins. If positioned in the left or right side of the page, header/footer details are placed within in this area.Default: 36 points |
| headerFooterInfo.PageOrientation | String | Page orientation.Valid values: - PORTRAIT - LANDSCAPE Default: Portrait |
| headerFooterInfo.PageSize | String | Document page size.Valid values: - A4 – 595 × 842 points - LETTER – 612 × 792 points - LEDGER – 792 x 1224 points Content will be truncated if it exceeds the page size. |
| headerFooterInfo.TopOrBottomMargin | String | Size of the top and bottom margins. Header and footer details are placed within in this area.Default: 72 points |
| fontFamilySysId | String | Optional. Sys\_id of the font family to use for the PDF. This sys\_id is from the PDF Generation Font Family \[sys\_pdf\_generation\_font\_family\] table.Default: none |
| documentConfiguration | Object | Optional. Object containing a table of contents configuration and a page number configuration. |
| documentConfiguration.accessibilityEnabled | Boolean | Optional. Flag that indicates whether to format the generated PDF to support accessibility. When this feature is enabled, accessibility tags will be available in the PDF tag tree to help users who rely on screen readers to navigate, understand, and interact with the generated PDF documents.Valid values: - true: The generated PDF is formatted for accessibility. - false: The generated PDF is not formatted for accessibility. Default: False |
| documentConfiguration.toc\_config | String | Optional. Sys\_id of the table of contents configuration to use for the PDF. This sys\_id is from the Table of Contents Configuration \[doc\_toc\_config\] table.Default: none |
| documentConfiguration.page\_number\_config | String | Optional. Sys\_id of the page number configuration to use for the PDF. This sys\_id is from the Page Number Configuration \[doc\_page\_number\_config\] table.Default: none |
| Type | Description |
|---|---|
| Object | Object containing sys\_id of the PDF attachment if conversion is successful, error message otherwise. |
| <Object>.attachment\_id | If HTML conversion is successful, sys\_id of the converted and attached PDF. The file is listed in the Attachments \[sys\_attachment\] table.Data type: String |
| <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 |
| <Object>.status | Status indicating whether the operation is successful.Possible values:
Data type: String |
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.
var v = new sn_pdfgeneratorutils.PDFGenerationAPI;
// (Option) get HTML from the description field of an incident record
var gr = new GlideRecord("incident");
var html;
if (gr.get("<tableSysId>")) {
html = gr.description.toString();
}
var hfInfo = new Object();
hfInfo["HeaderImageAttachmentId"] = "<hdrImgAttSysId>";
hfInfo["HeaderImageAlignment"] = "left";
hfInfo["FooterImageAttachmentId"] = "<ftrImgAttSysId>";
hfInfo["FooterImageAlignment"] = "TOP_CENTER";
hfInfo["FooterText"] = "Sample Footer Message";
hfInfo["PageSize"] = "A4";
hfInfo["GeneratePageNumber"] = "false";
hfInfo["TopOrBottomMargin"] = "36";
hfInfo["LeftOrRightMargin"] = "24";
var result = v.convertToPDFWithHeaderFooter(html, "incident", "<targetTbl_sys_id>", "myPDF", hfInfo);
gs.info(JSON.stringify(result));
Output:
{"attachment_id":"<sys_id>","message":"Conversion is successful.","request_id":"<change_sys_id>","status":"success"}
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.
Use this method to generate PDFs with page settings:
- Header and footer information
- Margin sizes
- Orientation
- Enumeration
- Page size
| Name | Type | Description |
|---|---|---|
| html | String | HTML to convert to a PDF document. |
| targetTable | String | Name of the table on which to attach the converted PDF. |
| targetTableSysId | String | Sys\_id of the record on which to attach the converted PDF. |
| pdfName | String | Name to give the PDF.Default: Sys\_id of the PDF in the Attachments \[sys\_attachment\] table. |
| headerFooterInfo | Object | Defines PDF header and footer details. |
| headerFooterInfo.FooterImageAlignment | String | Sets the image position in the footer.Valid values: - BOTTOM\_CENTER: Position the image in the bottom center of the footer. - BOTTOM\_LEFT: Position the image in the bottom left area of the footer. - BOTTOM\_RIGHT: Position the image in the bottom right area of the footer. - TOP\_CENTER: Position the image in the top center of the footer. - TOP\_LEFT: Position the image in the top left area of the footer. - TOP\_RIGHT: Position the image in the top right area of the footer. |
| headerFooterInfo.FooterImageAttachmentId | String | Sys_id of the footer image in the Attachments [sys_attachment] table.To determine if the file type is supported in your instance, Navigate to System Properties, Security, and check if it's listed in List of file extensions (comma-separated) that can be attached field. |
| headerFooterInfo.FooterImageHeight | String | Height of footer image.Default: 50 points |
| headerFooterInfo.FooterText | String | Footer text to place at the bottom of each PDF page. |
| headerFooterInfo.FooterTextAlignment | String | Sets the text position in the footer. Make sure this value does not match or conflict with the area provided in headerFooterInfo.FooterImageAlignment.Valid values:
|
| headerFooterInfo.GeneratePageNumber | String | Flag that indicates whether to generate a PDF page number.Valid values: - true: Generate page numbers. - false: Do not generate page numbers. Default: true |
| headerFooterInfo.HeaderImageAlignment | String | Sets the image position in the header.Valid values: - center: Position the image in the center of the header. - left: Position the image on the left side of the header. - right: Position the image on the right side of the header. |
| headerFooterInfo.HeaderImageAttachmentId | String | Sys_id of the header image in the Attachments [sys_attachment] table.To determine if the file type is supported in your instance, Navigate to System Properties, Security, and check if it's listed in List of file extensions (comma-separated) that can be attached field. |
| headerFooterInfo.HeaderImageHeight | String | Height of the header image. Default: 50 points |
| headerFooterInfo.LeftOrRightMargin | String | Size of the left and right margins. If positioned in the left or right side of the page, header/footer details are placed within in this area.Default: 36 points |
| headerFooterInfo.PageOrientation | String | Page orientation.Valid values: - PORTRAIT - LANDSCAPE Default: Portrait |
| headerFooterInfo.PageSize | String | Document page size.Valid values: - A4 – 595 × 842 points - LETTER – 612 × 792 points - LEDGER – 792 x 1224 points Content will be truncated if it exceeds the page size. |
| headerFooterInfo.TopOrBottomMargin | String | Size of the top and bottom margins. Header and footer details are placed within in this area.Default: 72 points |
| fontFamilySysId | String | Optional. Sys\_id of the font family to use for the PDF. This sys\_id is from the PDF Generation Font Family \[sys\_pdf\_generation\_font\_family\] table.Default: none |
| documentConfiguration | Object | Optional. Object containing a table of contents configuration and a page number configuration. |
| documentConfiguration.accessibilityEnabled | Boolean | Optional. Flag that indicates whether to format the generated PDF to support accessibility. When this feature is enabled, accessibility tags will be available in the PDF tag tree to help users who rely on screen readers to navigate, understand, and interact with the generated PDF documents.Valid values: - true: The generated PDF is formatted for accessibility. - false: The generated PDF is not formatted for accessibility. Default: False |
| documentConfiguration.toc\_config | String | Optional. Sys\_id of the table of contents configuration to use for the PDF. This sys\_id is from the Table of Contents Configuration \[doc\_toc\_config\] table.Default: none |
| documentConfiguration.page\_number\_config | String | Optional. Sys\_id of the page number configuration to use for the PDF. This sys\_id is from the Page Number Configuration \[doc\_page\_number\_config\] table.Default: none |
| 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 |
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.
var v = new sn_pdfgeneratorutils.PDFGenerationAPI;
// (Option) get HTML from the description field of an incident record
var gr = new GlideRecord("incident");
var html;
if (gr.get("<tableSysId>")) {
html = gr.description.toString();
}
var hfInfo = new Object();
hfInfo["HeaderImageAttachmentId"] = "<hdrImgAttSysId>";
hfInfo["HeaderImageAlignment"] = "left";
hfInfo["FooterImageAttachmentId"] = "<ftrImgAttSysId>";
hfInfo["FooterImageAlignment"] = "TOP_CENTER";
hfInfo["FooterText"] = "Sample Footer Message";
hfInfo["PageSize"] = "A4";
hfInfo["GeneratePageNumber"] = "false";
hfInfo["TopOrBottomMargin"] = "36";
hfInfo["LeftOrRightMargin"] = "24";
var result = v.convertToPDFWithHeaderFooterAsync(html, "incident", "<targetTbl_sys_id>", "myPDF", hfInfo);
gs.info(JSON.stringify(result));
Output:
{"message":"HTML to PDF Conversion is in progress.","request_id":"<sys_id>"}
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.
Use the following methods to determine if the PDF is fillable and get field information:
PDFGenerationAPI provides additional fill methods with different options:
- 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.
| Name | Type | Description |
|---|---|---|
| fieldsMap | Object | Optional. Key value map by PDF field name and value to fill. Use the getDocumentFields\(\) method to get the list of available fields. |
| sysId | String | Sys\_id of a PDF in the Attachments \[sys\_attachment\] table. |
| tableName | String | Name of the table containing the record to which the PDF is attached. You can find this value in the same row as the attachment listed in the Attachments \[sys\_attachment\] table. |
| tableSysId | String | Sys\_id of the record to which the PDF is attached. You can find this value in the same row as the attachment listed in the Attachments \[sys\_attachment\] table. |
| pdfName | String | Name to give the PDF.Default: Sys\_id of the PDF in the Attachments \[sys\_attachment\] table. |
| Type | Description |
|---|---|
| Object | Object containing sys\_id of the updated PDF attachment if successful, error message otherwise. |
| <Object>.attachment\_id | If the operation is successful, sys\_id of the filled PDF. The file is listed in the Attachments \[sys\_attachment\] table.Data type: String |
| <Object>.message | Message confirming success or error. Valid values: - Exception while reading Source document contents. PDF header not found. – Input attachment provided is not a valid PDF. Provide the correct attachment sys\_id. - Given target record \[<tableName> - <targetTableSysId>\] does not exist. – Target table sys\_id is not in the table provided. Make sure you include the correct table name for the record. - No Form associated with pdf to fill. attachmentSysId: <sys\_id> - No editable fields exist with specified names. Please check and try again. field names: <field names> - Request cannot proceed as the attachment with sys\_id \[\{0\}\] did not pass security scan – The PDF did not pass the antivirus scan. - Request cannot proceed as the attachment with sys\_id \[\{0\}\] is pending security scan – The PDF requires an antivirus scan. - Request completed successfully – Operation is successful. - Undefined – Sys\_id provided does not exist or is not a PDF attachment. Data type: String |
| <Object>.status | Status indicating whether the operation is successful.Possible values:
Data type: String |
The following example shows how to fill fields in an editable PDF.
var fieldMap = new Object();
fieldMap["Address"] = "Address value here";
fieldMap["State"] = "State value here";
var v = new sn_pdfgeneratorutils.PDFGenerationAPI;
var result = v.fillDocumentFields(fieldMap, "<attachmentSysId>", "<tableName>", "<tableSysId>", "pdfName");
gs.info(JSON.stringify(result));
Output:
{"attachment_id":"<sys_id>","message":"Request completed successfully.","status":"success"}
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.
Use the following methods to determine if the PDF is fillable and get field information:
PDFGenerationAPI provides additional fill methods with different options:
- 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.
| Name | Type | Description |
|---|---|---|
| fieldsMap | Object | Optional. Key value map by PDF field name and value to fill. Use the getDocumentFields\(\) method to get the list of available fields. |
| sysId | String | Sys\_id of a PDF in the Attachments \[sys\_attachment\] table. |
| tableName | String | Name of the table containing the record to which the PDF is attached. You can find this value in the same row as the attachment listed in the Attachments \[sys\_attachment\] table. |
| tableSysId | String | Sys\_id of the record to which the PDF is attached. You can find this value in the same row as the attachment listed in the Attachments \[sys\_attachment\] table. |
| pdfName | String | Name to give the PDF.Default: Sys\_id of the PDF in the Attachments \[sys\_attachment\] table. |
| flatten | Object | Optional. Flattening fields enable locking the fields so that other users cannot change the information. Specify the key as "FlattenType" and provide a flattening option as a string.Valid values: - donot\_flatten - Do not flatten any fields. - partially\_flatten - Flatten only the fields which are modified. - fully\_flatten - Flattens all the fields. Default: fully\_flatten |
| Type | Description |
|---|---|
| Object | Object containing sys\_id of the updated PDF attachment if successful, error message otherwise. |
| <Object>.attachment\_id | If the operation is successful, sys\_id of the filled PDF. The file is listed in the Attachments \[sys\_attachment\] table.Data type: String |
| <Object>.message | Message confirming success or error. Valid values: - Exception while reading Source document contents. PDF header not found. – Input attachment provided is not a valid PDF. Provide the correct attachment sys\_id. - Given target record \[<tableName> - <targetTableSysId>\] does not exist. – Target table sys\_id is not in the table provided. Make sure you include the correct table name for the record. - No Form associated with pdf to fill. attachmentSysId: <sys\_id> - No editable fields exist with specified names. Please check and try again. field names: <field names> - Request cannot proceed as the attachment with sys\_id \[\{0\}\] did not pass security scan – The PDF did not pass the antivirus scan. - Request cannot proceed as the attachment with sys\_id \[\{0\}\] is pending security scan – The PDF requires an antivirus scan. - Request completed successfully – Operation is successful. - Undefined – Sys\_id provided does not exist or is not a PDF attachment. Data type: String |
| <Object>.status | Status indicating whether the operation is successful.Possible values:
Data type: String |
The following example shows how to fill fields and flatten an editable PDF.
var fieldMap = new Object();
fieldMap["Last Name First Name Middle Initial"] = "Tuter Abel E.";
fieldMap["Date of Birth"] = "08101952";
fieldMap["US SSN"] = "111-22-9999";
fieldMap["Address"] = "PO Box 344";
fieldMap["City"] = "Jerome";
fieldMap["State"] = "AZ";
fieldMap["Zip"] = "86331";
var flatten = new Object();
flatten["FlattenType"] = "partially_flatten";
var v = new sn_pdfgeneratorutils.PDFGenerationAPI;
var result = v.fillDocumentFieldsAndFlatten(fieldMap, "<attachmentSysId>", "<tableName>", "<tableSysId>", "pdfName", flatten);
gs.info(JSON.stringify(result));
Output:
"attachment_id":"<sys_id>","message":"Request completed successfully.","status":"success"
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.
Use the following methods to determine if the PDF is fillable and get field information:
PDFGenerationAPI provides additional fill methods with different options:
- 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.
| Name | Type | Description |
|---|---|---|
| fieldsMap | Object | Optional. Key value map by PDF field name and value to fill. Use the getDocumentFields\(\) method to get the list of available fields. |
| sysId | String | Sys\_id of a PDF in the Attachments \[sys\_attachment\] table. |
| tableName | String | Name of the table containing the record to which the PDF is attached. You can find this value in the same row as the attachment listed in the Attachments \[sys\_attachment\] table. |
| tableSysId | String | Sys\_id of the record to which the PDF is attached. You can find this value in the same row as the attachment listed in the Attachments \[sys\_attachment\] table. |
| pdfName | String | Name to give the PDF.Default: Sys\_id of the PDF in the Attachments \[sys\_attachment\] table. |
| requestor | PdfMergeSignRequestor | Signature input returned from pdfMergeSignRequestor. |
| flatten | Object | Optional. Flattening fields enable locking the fields so that other users cannot change the information. Specify the key as "FlattenType" and provide a flattening option as a string.Valid values: - donot\_flatten - Do not flatten any fields. - partially\_flatten - Flatten only the fields which are modified. - fully\_flatten - Flattens all the fields. Default: fully\_flatten |
| Type | Description |
|---|---|
| Object | Object containing sys\_id of the updated PDF attachment if successful, error message otherwise. |
| <Object>.attachment\_id | If the operation is successful, sys\_id of the filled PDF. The file is listed in the Attachments \[sys\_attachment\] table.Data type: String |
| <Object>.message | Message confirming success or error. Valid values: - Exception while reading Source document contents. PDF header not found. – Input attachment provided is not a valid PDF. Provide the correct attachment sys\_id. - Given target record \[<tableName> - <targetTableSysId>\] does not exist. – Target table sys\_id is not in the table provided. Make sure you include the correct table name for the record. - No Form associated with pdf to fill. attachmentSysId: <sys\_id> - No editable fields exist with specified names. Please check and try again. field names: <field names> - Request cannot proceed as the attachment with sys\_id \[\{0\}\] did not pass security scan – The PDF did not pass the antivirus scan. - Request cannot proceed as the attachment with sys\_id \[\{0\}\] is pending security scan – The PDF requires an antivirus scan. - Request completed successfully – Operation is successful. - Undefined – Sys\_id provided does not exist or is not a PDF attachment. Data type: String |
| <Object>.status | Status indicating whether the operation is successful.Possible values:
Data type: String |
The following example shows how to fill fields with signature with default settings to completely flatten the fields.
var fieldMap = new Object();
fieldMap["Address_Salutation"] = "Address value here";
var paramMap = new Object();
paramMap["FlattenType"] = "partially_flatten";
var requestor = new sn_pdfgeneratorutils.PdfMergeSignRequestor;
requestor.createRequest("<attachmentSysId>", "incident", "<tableSysId>", "filledPdf");
requestor.addSignatureMapping(6, 40, 50, 188, 44, "<signatureSysId>");
var v = new sn_pdfgeneratorutils.PDFGenerationAPI;
var result = v.fillFieldsAndMergeSignature(fieldMap, "<attachmentSysId>", "incident", "<tableSysId>", requestor, "filledPdf", paramMap);
gs.info(JSON.stringify(result));
Output:
{"attachment_id":"5440d993dbed3010d66be1191396194e","message":"Request completed successfully.","status":"success"}
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. |
| Type | Description | |||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Object | Object containing ID of the signed PDF, error message otherwise. | |||||||||||||||||||||||||||||||||||||||||||||||
| <Object>.fields | If the request is successful, list containing the name of each field in the PDF.Data type: Array of strings ``` "fields": ["field_name"] | |||||||||||||||||||||||||||||||||||||||||||||||
| <Object>.fields\_type.<field> | Object containing page number of each field. The <field> name represents the field label, for example, "SSN", or an automated label representing the type.Data type: Object ``` "<Object>.fields\_type.<field>.fieldsDetails.fieldName | Name of a choice field.Data type: String | <Object>.fields\_type.<field>.fieldsDetails.value | Value of a choice field.Data type: String | <Object>.fields\_type.<field>.pageNumber | PDF page number corresponding to this field.Data type: String | <Object>.fields\_type.<field>.type | PDF field type.Possible values: - check\_box - choice\_box - combo\_box - multi\_select\_choice\_box - push\_button - radio\_button - signature - text Data type: String | <Object>.message | Message confirming success or error. Possible values: - Exception while reading Source document contents. PDF header not found. – Input attachment provided is not a valid PDF. Provide the correct attachment sys\_id. - Request cannot proceed as the attachment with sys\_id \[\{0\}\] did not pass security scan – The PDF did not pass the antivirus scan. - Request cannot proceed as the attachment with sys\_id \[\{0\}\] is pending security scan – The PDF requires an antivirus scan. - Request completed successfully – Operation is successful. - Undefined – Sys\_id provided does not exist or is not a PDF attachment. Data type: String | <Object>.status | Status indicating whether the operation is successful.Possible values:
Data type: String 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. Use the following methods to determine if the PDF is fillable and get field information: PDFGenerationAPI provides additional fill methods with different options:
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.
|