---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://www.servicenow.com/docs/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# PDFGenerationAPI - Scoped, Global

# PDFGenerationAPI - Scoped, Global {#ariaid-title1}

* Release version: Xanadu
* 
* Updated January 15, 2026
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 30 minutes to read

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.  
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
  * -- [PDFGenerationAPI -- convertToPDF(String html, String targetTable, String targetTableSysId, String pdfName, String fontFamilySysId, Object documentConfiguration)](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-convertToPDF_S_S_S_S "Converts an HTML string to a PDF document.")
  * -- [PDFGenerationAPI -- convertToPDFWithHeaderFooter(String html, String targetTable, String targetTableSysId, String pdfName, Object headerFooterInfo, String fontFamilySysId, Object documentConfiguration)](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-convertToPDFWithHdrFtr_S_S_S_S_O "Converts an HTML string into a PDF with header and footer content.")
  {#PDFGenerationAPIBothAPI__ul_ocm_vpr_tbc}
* Queue a PDF to be generated from an HTML string and attached to a record
  * --
  * --
  {#PDFGenerationAPIBothAPI__ul_mld_5nl_ydc}
* Fill fields in a PDF
  * [PDFGenerationAPI -- fillDocumentFieldsAndFlatten(Object fieldsMap, String sysId, String tableName, String tableSysId, String pdfName, Object flatten)](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-fillDocFieldsFlatten_O_S_S_S_S_O "Fills fields in an editable PDF, flattens the data fields, and attaches it to the provided record.")
  * [PDFGenerationAPI -- fillDocumentFields(Object fieldsMap, String sysId, String tableName, String tableSysId, String pdfName)](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-fillDocumentFields_O_S_S_S_S "Fills fields in an editable PDF and attaches it to the provided record.")
  * [PDFGenerationAPI -- isDocumentFillable(String sysId)](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-isDocumentFillable_S "Checks if the PDF document contains editable fields.")
  {#PDFGenerationAPIBothAPI__ul_kvf_spr_tbc}
* Sign a PDF
  * [PDFGenerationAPI -- fillFieldsAndMergeSignature(Object fieldsMap, String sysId, String tableName, String tableSysId, String pdfName, PdfMergeSignRequestor requestor, Object flatten)](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-fillFieldsMergeSig_O_S_S_S_S_O_O "Fills fields in an editable PDF, adds signature image, flattens the data fields, and attaches it to the provided record.")
  * [PDFGenerationAPI -- getFilledDocumentWithSignatureAsBase64(Object fieldsMap, String sysId, PdfMergeSignRequestor requestor, Object flatten)](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-getFilDocWithSigAsBase64_O_S_O_O "Fills fields in an editable PDF, creates an image, and converts it to a Base64-encoded PDF.")
  {#PDFGenerationAPIBothAPI__ul_xzr_frr_tbc}
* Restrict editing filled fields as flattened or partially flattened -- [PDFGenerationAPI -- fillDocumentFieldsAndFlatten(Object fieldsMap, String sysId, String tableName, String tableSysId, String pdfName, Object flatten)](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-fillDocFieldsFlatten_O_S_S_S_S_O "Fills fields in an editable PDF, flattens the data fields, and attaches it to the provided record.")
* Retrieve PDF page size and field data
  * [PDFGenerationAPI -- getPdfPageSizes(String sysId)](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-getPdfPageSizes_S "Gets the page size of a PDF document.")
  * [PDFGenerationAPI -- getDocumentFieldsType(String sysId)](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-getDocumentFieldsType_S "Gets the field type of set of editable fields from a PDF document.")
  * [PDFGenerationAPI -- getDocumentFields(String sysId)](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-getDocumentFields_S "Gets a list of editable fields in a PDF document. Enables listing editable PDF fields without manually opening the file to check.")
  {#PDFGenerationAPIBothAPI__ul_e2p_ypr_tbc}
* Redact information in a PDF -- [PDFGenerationAPI -- redact(Object inputJson)](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-redact_O "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.")

{#PDFGenerationAPIBothAPI__ul_csg_2vl_l4b}  
Note:  
These methods can also be used for documents created by non-catalog items.  
Related APIs:

* [PdfMergeSignRequestor](https://www.servicenow.com/docs/65LbP2HCAV_XhDJ4TlzvhQ#PdfMergeSignRequestorBothAPI "The PdfMergeSignRequestor API provides methods to add an image representing a signature to a PDF document.")
* [SVGToPDFConversionAPI](https://www.servicenow.com/docs/UdcW8uQ~j7TisabB0Z4RYQ#SVGToPDFConversionAPBothAPI "The SVGToPDFConversionAPI provides methods that enable the adding of an SVG to a PDF and converting an SVG to PDF.")

## PDFGenerationAPI -- PDFGenerationAPI() {#ariaid-title2}

Instantiates a new PDFGenerationAPI object.
{#P-PDFGenerationAPI__table_twm_hjk_34b__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 1. Parameters]

{#P-PDFGenerationAPI__table_twm_hjk_34b}  
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) {#ariaid-title3}

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()](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-convertToPDFWithHdrFtr_S_S_S_S_O "Converts an HTML string into a PDF with header and footer content.").
{#P-convertToPDF_S_S_S_S__table_sj4_p5j_34b__entry__3}{#P-convertToPDF_S_S_S_S__api_pdfgen_parm_fill_tableN_desc}

| 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. {​ "toc_config" : "String",​ "page_number_config": "String"​ }​ |
| 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 |
[Table 2. Parameters]

{#P-convertToPDF_S_S_S_S__table_sj4_p5j_34b} {#P-convertToPDF_S_S_S_S__table_tj4_p5j_34b__entry__2}{#P-convertToPDF_S_S_S_S__row_pdfgen_ret_msgCnv}

| Type | Description |
|-|-|
| Object | Object containing sys_id of the PDF attachment if conversion is successful, error message otherwise. { "attachment_id": "String", "message": "String", "request_id": "String", "status": "String" } |
| \<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. {#P-convertToPDF_S_S_S_S__ul_zv2_wq3_k4b} 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: * success - Operation was successful. * failure -- Operation was not successful. The message provides details. {#P-convertToPDF_S_S_S_S__ul_rlv_5cv_j4b} Data type: String |
[Table 3. Returns]

{#P-convertToPDF_S_S_S_S__table_tj4_p5j_34b}  
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 -- convertToPDFWithHeaderFooter(String html, String targetTable, String
targetTableSysId, String pdfName, Object headerFooterInfo, String fontFamilySysId, Object
documentConfiguration) {#ariaid-title4}

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
{#P-convertToPDFWithHdrFtr_S_S_S_S_O__ul_iqx_3xc_l4b}
{#P-convertToPDFWithHdrFtr_S_S_S_S_O__table_hmj_q5j_34b__entry__3}{#P-convertToPDFWithHdrFtr_S_S_S_S_O__api_pdfgen_parm_fill_tableN_desc}

| 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. { "FooterImageAlignment": "String", "FooterImageAttachmentId": "String", "FooterImageHeight": "String", "FooterText": "String", "FooterTextAlignment": "String", "GeneratePageNumber": "String", "HeaderImageAlignment": "String", "HeaderImageAttachmentId": "String", "HeaderImageHeight": "String", "LeftOrRightMargin": "String", "PageOrientation": "String", "PageSize": "String", "TopOrBottomMargin": "String" } |
| 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. {#P-convertToPDFWithHdrFtr_S_S_S_S_O__ul_ezt_f4c_l4b} |
| 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: * BOTTOM_CENTER: Position the text in the bottom center of the footer. * BOTTOM_LEFT: Position the text in the bottom left area of the footer. * BOTTOM_RIGHT: Position the text in the bottom right area of the footer. * TOP_CENTER: Position the text in the top center of the footer. * TOP_LEFT: Position the text in the top left area of the footer. * TOP_RIGHT: Position the text in the top right area of the footer. {#P-convertToPDFWithHdrFtr_S_S_S_S_O__ul_lfd_mdd_l4b} |
| 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. {#P-convertToPDFWithHdrFtr_S_S_S_S_O__ul_zlg_4cp_k4b} 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. {#P-convertToPDFWithHdrFtr_S_S_S_S_O__ul_qjq_npc_l4b} |
| 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 {#P-convertToPDFWithHdrFtr_S_S_S_S_O__ul_lyr_qyc_l4b} Default: Portrait |
| headerFooterInfo.​PageSize | String | Document page size. Valid values: * A4 -- 595 × 842 points * LETTER -- 612 × 792 points * LEDGER -- 792 x 1224 points {#P-convertToPDFWithHdrFtr_S_S_S_S_O__ul_dml_q2p_k4b} 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. {​ "toc_config" : "String",​ "page_number_config": "String"​ }​ |
| 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 |
[Table 4. Parameters]

{#P-convertToPDFWithHdrFtr_S_S_S_S_O__table_hmj_q5j_34b} {#P-convertToPDFWithHdrFtr_S_S_S_S_O__table_tj4_p5j_34b__entry__2}{#P-convertToPDFWithHdrFtr_S_S_S_S_O__row_pdfgen_ret_msgCnv}

| Type | Description |
|-|-|
| Object | Object containing sys_id of the PDF attachment if conversion is successful, error message otherwise. { "attachment_id": "String", "message": "String", "request_id": "String", "status": "String" } |
| \<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. * Footer Image alignment and text alignment cannot be in the same region with same alignment: \<footerImageAlignment value\> -- Make sure that headerFooterInfo.FooterImageAlignment and headerFooterInfo.FooterTextAlignment values are not in the same area. * 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. * Invalid footer image alignment: \<invalid_option\> is provided. -- Provide a valid option in the headerFooterInfo.FooterImageAlignment property. * Invalid footer text alignment: " + \<invalid_option\> + " is provided. -- Provide a valid option in the headerFooterInfo.footerTextAlignment property. * 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. * Unable to get the footer image. sysId: + \<value provided\> -- Make sure the sys_id provided for headerFooterInfo.footerImageId is accurate. * Unable to get the header image. sysId: + \<value provided\> -- Make sure the sys_id provided for headerFooterInfo.headerImageId is accurate. * Undefined -- Sys_id provided does not exist or is not a PDF attachment. {#P-convertToPDFWithHdrFtr_S_S_S_S_O__ul_zv2_wq3_k4b} 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: * success - Operation was successful. * failure -- Operation was not successful. The message provides details. {#P-convertToPDFWithHdrFtr_S_S_S_S_O__ul_rlv_5cv_j4b} Data type: String |
[Table 5. Returns]

{#P-convertToPDFWithHdrFtr_S_S_S_S_O__table_tj4_p5j_34b}  
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 -- fillDocumentFields(Object fieldsMap, String sysId, String tableName,
String tableSysId, String pdfName) {#ariaid-title5}

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:

* [isDocumentFillable()](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-isDocumentFillable_S "Checks if the PDF document contains editable fields.")
* [getDocumentFields()](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-getDocumentFields_S "Gets a list of editable fields in a PDF document. Enables listing editable PDF fields without manually opening the file to check.")
* [getDocumentFieldsType()](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-getDocumentFieldsType_S "Gets the field type of set of editable fields from a PDF document.")
{#P-fillDocumentFields_O_S_S_S_S__ul_e1m_kpj_l4b}  
PDFGenerationAPI provides additional fill methods with different options:

* [fillDocumentFieldsAndFlatten()](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-fillDocFieldsFlatten_O_S_S_S_S_O "Fills fields in an editable PDF, flattens the data fields, and attaches it to the provided record.") -- Fills fields in an editable PDF, flattens the data fields, and attaches it to the provided record.
* [fillFieldsAndMergeSignature()](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-fillFieldsMergeSig_O_S_S_S_S_O_O "Fills fields in an editable PDF, adds signature image, flattens the data fields, and attaches it to the provided record.") -- Fills fields in an editable PDF, adds signature image, flattens the data fields, and attaches it to the provided record.
* [getFilledDocumentWithSignatureAsBase64()](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-getFilDocWithSigAsBase64_O_S_O_O "Fills fields in an editable PDF, creates an image, and converts it to a Base64-encoded PDF.") -- Fills fields in an editable PDF, creates an image, and converts it to a Base64-encoded PDF.
{#P-fillDocumentFields_O_S_S_S_S__ul_lyz_lft_l4b}
{#P-fillDocumentFields_O_S_S_S_S__table_ohl_lzj_34b__entry__3}{#P-fillDocumentFields_O_S_S_S_S__ph_api_pdfgen_parm_attIDesc}{#P-fillDocumentFields_O_S_S_S_S__entry-api-pdfgen-tblName}{#P-fillDocumentFields_O_S_S_S_S__entry-api-pdfgen-tblID}

| 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. |
[Table 6. Parameters]

{#P-fillDocumentFields_O_S_S_S_S__table_ohl_lzj_34b} {#P-fillDocumentFields_O_S_S_S_S__table_phl_lzj_34b__entry__2}{#P-fillDocumentFields_O_S_S_S_S__desc-fill-only}{#P-fillDocumentFields_O_S_S_S_S__desc_pdfgen_ret_attID_Fill}

| Type | Description |
|-|-|
| Object | Object containing sys_id of the updated PDF attachment if successful, error message otherwise. { "attachment_id": "String", "message": "String", "status": "String" } |
| \<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. {#P-fillDocumentFields_O_S_S_S_S__ul_eln_fwk_l4b} Data type: String |
| \<Object\>.status | Status indicating whether the operation is successful. Possible values: * success - Operation was successful. * failure -- Operation was not successful. The message provides details. {#P-fillDocumentFields_O_S_S_S_S__ul_rlv_5cv_j4b} Data type: String |
[Table 7. Returns]

{#P-fillDocumentFields_O_S_S_S_S__table_phl_lzj_34b}  
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) {#ariaid-title6}

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:

* [isDocumentFillable()](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-isDocumentFillable_S "Checks if the PDF document contains editable fields.")
* [getDocumentFields()](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-getDocumentFields_S "Gets a list of editable fields in a PDF document. Enables listing editable PDF fields without manually opening the file to check.")
* [getDocumentFieldsType()](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-getDocumentFieldsType_S "Gets the field type of set of editable fields from a PDF document.")
{#P-fillDocFieldsFlatten_O_S_S_S_S_O__ul_e1m_kpj_l4b}  
PDFGenerationAPI provides additional fill methods with different options:

* [fillDocumentFields()](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-fillDocumentFields_O_S_S_S_S "Fills fields in an editable PDF and attaches it to the provided record.") -- Fills fields in an editable PDF and attaches it to the provided record.
* [fillFieldsAndMergeSignature()](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-fillFieldsMergeSig_O_S_S_S_S_O_O "Fills fields in an editable PDF, adds signature image, flattens the data fields, and attaches it to the provided record.") -- Fills fields in an editable PDF, adds signature image, flattens the data fields, and attaches it to the provided record.
* [getFilledDocumentWithSignatureAsBase64()](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-getFilDocWithSigAsBase64_O_S_O_O "Fills fields in an editable PDF, creates an image, and converts it to a Base64-encoded PDF.") -- Fills fields in an editable PDF, creates an image, and converts it to a Base64-encoded PDF.
{#P-fillDocFieldsFlatten_O_S_S_S_S_O__ul_lyz_lft_l4b}
{#P-fillDocFieldsFlatten_O_S_S_S_S_O__table_xp4_thk_34b__entry__3}{#P-fillDocFieldsFlatten_O_S_S_S_S_O__ph_api_pdfgen_parm_attIDesc}{#P-fillDocFieldsFlatten_O_S_S_S_S_O__entry-api-pdfgen-tblName}{#P-fillDocFieldsFlatten_O_S_S_S_S_O__entry-api-pdfgen-tblID}

| 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. {#P-fillDocFieldsFlatten_O_S_S_S_S_O__ul_mwn_5wc_k4b} Default: fully_flatten { "FlattenType": "String" } |
[Table 8. Parameters]

{#P-fillDocFieldsFlatten_O_S_S_S_S_O__table_xp4_thk_34b} {#P-fillDocFieldsFlatten_O_S_S_S_S_O__table_phl_lzj_34b__entry__2}{#P-fillDocFieldsFlatten_O_S_S_S_S_O__desc-fill-only}{#P-fillDocFieldsFlatten_O_S_S_S_S_O__desc_pdfgen_ret_attID_Fill}

| Type | Description |
|-|-|
| Object | Object containing sys_id of the updated PDF attachment if successful, error message otherwise. { "attachment_id": "String", "message": "String", "status": "String" } |
| \<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. {#P-fillDocFieldsFlatten_O_S_S_S_S_O__ul_eln_fwk_l4b} Data type: String |
| \<Object\>.status | Status indicating whether the operation is successful. Possible values: * success - Operation was successful. * failure -- Operation was not successful. The message provides details. {#P-fillDocFieldsFlatten_O_S_S_S_S_O__ul_rlv_5cv_j4b} Data type: String |
[Table 9. Returns]

{#P-fillDocFieldsFlatten_O_S_S_S_S_O__table_phl_lzj_34b}  
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) {#ariaid-title7}

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:

* [isDocumentFillable()](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-isDocumentFillable_S "Checks if the PDF document contains editable fields.")
* [getDocumentFields()](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-getDocumentFields_S "Gets a list of editable fields in a PDF document. Enables listing editable PDF fields without manually opening the file to check.")
* [getDocumentFieldsType()](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-getDocumentFieldsType_S "Gets the field type of set of editable fields from a PDF document.")
{#P-fillFieldsMergeSig_O_S_S_S_S_O_O__ul_e1m_kpj_l4b}  
PDFGenerationAPI provides additional fill methods with different options:

* [fillDocumentFields()](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-fillDocumentFields_O_S_S_S_S "Fills fields in an editable PDF and attaches it to the provided record.") -- Fills fields in an editable PDF and attaches it to the provided record.
* [fillDocumentFieldsAndFlatten()](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-fillDocFieldsFlatten_O_S_S_S_S_O "Fills fields in an editable PDF, flattens the data fields, and attaches it to the provided record.") -- Fills fields in an editable PDF, flattens the data fields, and attaches it to the provided record.
* [getFilledDocumentWithSignatureAsBase64()](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-getFilDocWithSigAsBase64_O_S_O_O "Fills fields in an editable PDF, creates an image, and converts it to a Base64-encoded PDF.") -- Fills fields in an editable PDF, creates an image, and converts it to a Base64-encoded PDF.
{#P-fillFieldsMergeSig_O_S_S_S_S_O_O__ul_lyz_lft_l4b}
{#P-fillFieldsMergeSig_O_S_S_S_S_O_O__table_xp4_thk_34b__entry__3}{#P-fillFieldsMergeSig_O_S_S_S_S_O_O__ph_api_pdfgen_parm_attIDesc}{#P-fillFieldsMergeSig_O_S_S_S_S_O_O__entry-api-pdfgen-tblName}{#P-fillFieldsMergeSig_O_S_S_S_S_O_O__entry-api-pdfgen-tblID}

| 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 | [PdfMergeSign​Requestor](https://www.servicenow.com/docs/65LbP2HCAV_XhDJ4TlzvhQ#PdfMergeSignRequestorBothAPI "The PdfMergeSignRequestor API provides methods to add an image representing a signature to a PDF document.") | 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. {#P-fillFieldsMergeSig_O_S_S_S_S_O_O__ul_mwn_5wc_k4b} Default: fully_flatten { "FlattenType": "String" } |
[Table 10. Parameters]

{#P-fillFieldsMergeSig_O_S_S_S_S_O_O__table_xp4_thk_34b} {#P-fillFieldsMergeSig_O_S_S_S_S_O_O__table_anm_5hk_34b__entry__2}{#P-fillFieldsMergeSig_O_S_S_S_S_O_O__desc-fill-only}{#P-fillFieldsMergeSig_O_S_S_S_S_O_O__desc_pdfgen_ret_attID_Fill}

| Type | Description |
|-|-|
| Object | Object containing sys_id of the updated PDF attachment if successful, error message otherwise. { "attachment_id": "String", "message": "String", "status": "String" } |
| \<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. {#P-fillFieldsMergeSig_O_S_S_S_S_O_O__ul_eln_fwk_l4b} Data type: String |
| \<Object\>.status | Status indicating whether the operation is successful. Possible values: * success - Operation was successful. * failure -- Operation was not successful. The message provides details. {#P-fillFieldsMergeSig_O_S_S_S_S_O_O__ul_rlv_5cv_j4b} Data type: String |
[Table 11. Returns]

{#P-fillFieldsMergeSig_O_S_S_S_S_O_O__table_anm_5hk_34b}  
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) {#ariaid-title8}

Gets a list of editable fields in a PDF document. Enables listing editable PDF fields
without manually opening the file to check.
{#P-getDocumentFields_S__table_hmj_q5j_34b__entry__3}{#P-getDocumentFields_S__ph_api_pdfgen_parm_attIDesc}

| Name | Type | Description |
|-|-|-|
| sysId | String | Sys_id of a PDF in the Attachments \[sys_attachment\] table. |
[Table 12. Parameters]

{#P-getDocumentFields_S__table_hmj_q5j_34b} {#P-getDocumentFields_S__table_v1y_g3k_34b__entry__2}

| Type | Description |
|-|-|
| Object | Object containing ID of the signed PDF, error message otherwise. { "attachment_id": "String", "message": "String", "status": "String" } |
| \<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\>.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. {#P-getDocumentFields_S__ul_qlv_5cv_j4b} Data type: String |
| \<Object\>.status | Status indicating whether the operation is successful. Possible values: * success - Operation was successful. * failure -- Operation was not successful. The message provides details. {#P-getDocumentFields_S__ul_rlv_5cv_j4b} Data type: String |
[Table 13. Returns]

{#P-getDocumentFields_S__table_v1y_g3k_34b}  
The following example shows how to retrieve fields in a PDF attachment.

    var v = new sn_pdfgeneratorutils.PDFGenerationAPI;
    var result = v.getDocumentFields("attachmentSysId");
    gs.info(JSON.stringify(result));

Output:

    {"message":"Request completed successfully.","fields":["NP_formFillable","reset","print","1SSN","Signature.1","5sigDate","Check Box21"],"status":"success"}

## PDFGenerationAPI -- getDocumentFieldsType(String sysId) {#ariaid-title9}

Gets the field type of set of editable fields from a PDF document.
{#P-getDocumentFieldsType_S__table_hmj_q5j_34b__entry__3}{#P-getDocumentFieldsType_S__ph_api_pdfgen_parm_attIDesc}

| Name | Type | Description |
|-|-|-|
| sysId | String | Sys_id of a PDF in the Attachments \[sys_attachment\] table. |
[Table 14. Parameters]

{#P-getDocumentFieldsType_S__table_hmj_q5j_34b} {#P-getDocumentFieldsType_S__table_jxx_whk_34b__entry__2}{#P-getDocumentFieldsType_S__api_pdfgen_ret_msg}

| Type | Description |
|-|-|
| Object | Object containing each PDF field type if successful, error message otherwise. { "fields_type": {Object}, "message": "String", "status": "String" } |
| \<Object\>.fields_type | Object listing each field in the specified PDF if successful, error message otherwise. Data type: Object "fields_type": { "<field type>": {Object}, } |
| \<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 "<field>": { "fieldsDetails": [Array], // Check boxes, radio buttons, choice boxes only "pageNumber": "String", "type": "String" } |
| \<Object\>.fields_type.​\<field\>.fieldsDetails | List of objects containing field name and corresponding value of each option for choice field types. Applicable types: * Check box * Choice box * Combo box * Multi select choice box Data type: Array "fieldsDetails": [ "fieldName": "String", "value": "String" ] |
| \<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.{#P-getDocumentFieldsType_S__api_pdfgen_reg_msg_hdrNF} {#P-getDocumentFieldsType_S__api_pdfgen_reg_msg_hdrNF} * Request cannot proceed as the attachment with sys_id \[{0}\] did not pass security scan -- The PDF did not pass the antivirus scan.{#P-getDocumentFieldsType_S__api_pdfgen_reg_msg_failScan} {#P-getDocumentFieldsType_S__api_pdfgen_reg_msg_failScan} * Request cannot proceed as the attachment with sys_id \[{0}\] is pending security scan -- The PDF requires an antivirus scan.{#P-getDocumentFieldsType_S__api_pdfgen_reg_msg_pendScan} {#P-getDocumentFieldsType_S__api_pdfgen_reg_msg_pendScan} * Request completed successfully -- Operation is successful.{#P-getDocumentFieldsType_S__api_pdfgen_reg_msg_succ} {#P-getDocumentFieldsType_S__api_pdfgen_reg_msg_succ} * Undefined -- Sys_id provided does not exist or is not a PDF attachment.{#P-getDocumentFieldsType_S__api_pdfgen_reg_msg_und} {#P-getDocumentFieldsType_S__api_pdfgen_reg_msg_und} {#P-getDocumentFieldsType_S__ul_qlv_5cv_j4b} Data type: String |
| \<Object\>.status | Status indicating whether the operation is successful. Possible values: * success - Operation was successful. * failure -- Operation was not successful. The message provides details. {#P-getDocumentFieldsType_S__ul_rlv_5cv_j4b} Data type: String |
[Table 15. Returns]

{#P-getDocumentFieldsType_S__table_jxx_whk_34b}  
The following example shows how to retrieve field types in a PDF attachment. Results
include manual returns for readability and are truncated for brevity.

    var v = new sn_pdfgeneratorutils.PDFGenerationAPI;
    var result = v.getDocumentFieldsType("<attachmentSysId>");
    gs.info(JSON.stringify(result));

Output:

    {"fields_type":{"1ADDLINE2.25":{"pageNumber":2,"type":"text"},"1ADDLINE2.24":{"pageNumber":2,"type":"text"},
    "1ADDLINE2.23":{"pageNumber":2,"type":"text"},"1ADDLINE2.22":{"pageNumber":2,"type":"text"},
    "1ADDLINE2.11":{"pageNumber":2,"type":"text"},
    "Check Box1":{"fieldsDetails":[{"fieldName":"Yes"}],"pageNumber":2,"type":"check_box"},
    "4consentDate.6":{"pageNumber":4,"type":"text"},"4consentDate.7":{"pageNumber":4,"type":"text"},
    "3SSN.9":{"pageNumber":3,"type":"text"},"3SSN.8":{"pageNumber":3,"type":"text"},"3SSN.7":{"pageNumber":3,"type":"text"},
    "pageNumber":2,"type":"check_box"},"Check Box8":{"fieldsDetails":[{"fieldName":"Off"},{"fieldName":"yes"}],
    "4planAdminDate.8":{"pageNumber":4,"type":"text"},"4planAdminDate.7":{"pageNumber":4,"type":"text"},
    "1FirstName_ID.7":{"pageNumber":2,"type":"text"},
    "Check Box9":{"fieldsDetails":[{"fieldName":"Yes"}],"pageNumber":3,"type":"check_box"},
    "1LN.1":{"pageNumber":2,"type":"text"},"1LN.2":{"pageNumber":2,"type":"text"},
    "Check Box11":{"fieldsDetails":[{"fieldName":"Yes"}],"pageNumber":3,"type":"check_box"},
    "1LN.9":{"pageNumber":2,"type":"text"},
    "Check Box17":{"fieldsDetails":[{"fieldName":"Yes"}],"pageNumber":3,"type":"check_box"},
    "Check Box16":{"fieldsDetails":[{"fieldName":"Yes"}],"pageNumber":3,"type":"check_box"},
    "1LN.7":{"pageNumber":2,"type":"text"},"Check Box19":{"fieldsDetails":[{"fieldName":"Yes"}],
    "1LN.8":{"pageNumber":2,"type":"text"},"Check Box18":{"fieldsDetails":[{"fieldName":"Yes"}],
    "print":{"pageNumber":2,"type":"push_button"},"4planAdministrator.1":{"pageNumber":4,"type":"text"},
    "1TaxID.9":{"pageNumber":2,"type":"text"},"4SSN.1":{"pageNumber":3,"type":"text"},"4SSN.2":{"pageNumber":3,"type":"text"},
    "Signature.1":{"pageNumber":4,"type":"text"},"1ZIP.2":{"pageNumber":2,"type":"text"},"1ZIP.3":{"pageNumber":2,"type":"text"},
    "message":"Request completed successfully.","status":"success"}

## PDFGenerationAPI -- getFilledDocumentWithSignatureAsBase64(Object fieldsMap, String sysId,
PdfMergeSignRequestor requestor, Object flatten) {#ariaid-title10}

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:

* [isDocumentFillable()](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-isDocumentFillable_S "Checks if the PDF document contains editable fields.")
* [getDocumentFields()](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-getDocumentFields_S "Gets a list of editable fields in a PDF document. Enables listing editable PDF fields without manually opening the file to check.")
* [getDocumentFieldsType()](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-getDocumentFieldsType_S "Gets the field type of set of editable fields from a PDF document.")
{#P-getFilDocWithSigAsBase64_O_S_O_O__ul_e1m_kpj_l4b}  
PDFGenerationAPI provides additional fill methods with different options:

* [fillDocumentFields()](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-fillDocumentFields_O_S_S_S_S "Fills fields in an editable PDF and attaches it to the provided record.") -- Fills fields in an editable PDF and attaches it to the provided record.
* [fillDocumentFieldsAndFlatten()](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-fillDocFieldsFlatten_O_S_S_S_S_O "Fills fields in an editable PDF, flattens the data fields, and attaches it to the provided record.") -- Fills fields in an editable PDF, flattens the data fields, and attaches it to the provided record.
* [fillFieldsAndMergeSignature()](https://www.servicenow.com/docs/r6ifZ3JkiLd_1W_LcORhLw#P-fillFieldsMergeSig_O_S_S_S_S_O_O "Fills fields in an editable PDF, adds signature image, flattens the data fields, and attaches it to the provided record.") -- Fills fields in an editable PDF, adds signature image, flattens the data fields, and attaches it to the provided record.
{#P-getFilDocWithSigAsBase64_O_S_O_O__ul_lyz_lft_l4b}
{#P-getFilDocWithSigAsBase64_O_S_O_O__table_w4w_xhk_34b__entry__3}{#P-getFilDocWithSigAsBase64_O_S_O_O__ph_api_pdfgen_parm_attIDesc}

| 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. |
| requestor | [PdfMergeSign​Requestor](https://www.servicenow.com/docs/65LbP2HCAV_XhDJ4TlzvhQ#PdfMergeSignRequestorBothAPI "The PdfMergeSignRequestor API provides methods to add an image representing a signature to a PDF document.") | 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. {#P-getFilDocWithSigAsBase64_O_S_O_O__ul_mwn_5wc_k4b} Default: fully_flatten { "FlattenType": "String" } |
[Table 16. Parameters]

{#P-getFilDocWithSigAsBase64_O_S_O_O__table_w4w_xhk_34b} {#P-getFilDocWithSigAsBase64_O_S_O_O__table_x4w_xhk_34b__entry__2}

| 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: * 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. {#P-getFilDocWithSigAsBase64_O_S_O_O__ul_eln_fwk_l4b} Data type: String |
| \<Object\>.status | Status indicating whether the operation is successful. Possible values: * success - Operation was successful. * failure -- Operation was not successful. The message provides details. {#P-getFilDocWithSigAsBase64_O_S_O_O__ul_rlv_5cv_j4b} Data type: String |
[Table 17. Returns]

{#P-getFilDocWithSigAsBase64_O_S_O_O__table_x4w_xhk_34b}  
The following example shows how to load two fields in a PDF attachment, flatten the fields,
and convert the PDF to Base64 format.

    var mymap = new Object();
    mymap["City"] = "City value here";
    mymap["State"] = "XX";

    // create a requestor
    var requestor = new sn_pdfgeneratorutils.PdfMergeSignRequestor;
    requestor.createRequest("<sys_id>", "tableName", "<tableSysId>", "pdfName");
    requestor.addSignatureMapping(6, 40, 50, 188, 44, "<signImgSysId>");
    var processedRequestObj = requestor.processRequest();

    var v = new sn_pdfgeneratorutils.PDFGenerationAPI;

    var result = v.getFilledDocumentWithSignatureAsBase64(mymap, "<attachmentSysId>", processedRequestObj);
    gs.info (JSON.stringify(result));

## PDFGenerationAPI -- getPdfPageSizes(String sysId) {#ariaid-title11}

Gets the page size of a PDF document.
{#P-getPdfPageSizes_S__table_hmj_q5j_34b__entry__3}{#P-getPdfPageSizes_S__ph_api_pdfgen_parm_attIDesc}

| Name | Type | Description |
|-|-|-|
| sysId | String | Sys_id of a PDF in the Attachments \[sys_attachment\] table. |
[Table 18. Parameters]

{#P-getPdfPageSizes_S__table_hmj_q5j_34b} {#P-getPdfPageSizes_S__table_v1y_g3k_34b__entry__2}{#P-getPdfPageSizes_S__api_pdfgen_ret_msg}

| Type | Description |
|-|-|
| Object | Object containing the size of each page if successful, error message otherwise. { "pages_size": {Object}, "message": "String", "status": "String" } |
| \<Object\>.pages_size | If the operation is successful, width and height of each PDF page in points. The page number is returned as a string and the measurement values are returned as number data types. Data type: Object "pages_size": {"<page number>":[<width>,<height>]} |
| \<Object\>.message | Message confirming success or error. Possible values: * 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. {#P-getPdfPageSizes_S__ul_qlv_5cv_j4b} Data type: String |
| \<Object\>.status | Status indicating whether the operation is successful. Possible values: * success - Operation was successful. * failure -- Operation was not successful. The message provides details. {#P-getPdfPageSizes_S__ul_rlv_5cv_j4b} Data type: String |
[Table 19. Returns]

{#P-getPdfPageSizes_S__table_v1y_g3k_34b}  
The following example shows how to display the width and height of each page in a PDF
attachment.

    var v = new sn_pdfgeneratorutils.PDFGenerationAPI;
    var result = v.getPdfPageSizes ("<attachmentSysId>");
    gs.info(JSON.stringify(result));

Output:

    {"pages_size":{"1":[612,792],"2":[612,792],"3":[612,792],"4":[612,792],"5":[612,792]},"message":"Request completed successfully.","status":"success"}

## PDFGenerationAPI -- isDocumentFillable(String sysId) {#ariaid-title12}

Checks if the PDF document contains editable fields.
{#P-isDocumentFillable_S__table_drx_h3k_34b__entry__3}{#P-isDocumentFillable_S__ph_api_pdfgen_parm_attIDesc}

| Name | Type | Description |
|-|-|-|
| sysId | String | Sys_id of a PDF in the Attachments \[sys_attachment\] table. |
[Table 20. Parameters]

{#P-isDocumentFillable_S__table_drx_h3k_34b} {#P-isDocumentFillable_S__table_erx_h3k_34b__entry__2}{#P-isDocumentFillable_S__api_pdfgen_ret_msg}

| Type | Description |
|-|-|
| Object | Object containing the size of each page if successful, error message otherwise. { "document_editable": "String", "message": "String", "status": "String" } |
| \<Object\>.​document_editable | If the operation is successful, flag indicating whether the document is editable. Valid values: * true: PDF document has editable fields. * false: PDF document does not have editable fields. {#P-isDocumentFillable_S__ul_h4w_sbd_k4b} Data type: Boolean value provided as a 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.{#P-isDocumentFillable_S__api_pdfgen_reg_msg_hdrNF} {#P-isDocumentFillable_S__api_pdfgen_reg_msg_hdrNF} * Request cannot proceed as the attachment with sys_id \[{0}\] did not pass security scan -- The PDF did not pass the antivirus scan.{#P-isDocumentFillable_S__api_pdfgen_reg_msg_failScan} {#P-isDocumentFillable_S__api_pdfgen_reg_msg_failScan} * Request cannot proceed as the attachment with sys_id \[{0}\] is pending security scan -- The PDF requires an antivirus scan.{#P-isDocumentFillable_S__api_pdfgen_reg_msg_pendScan} {#P-isDocumentFillable_S__api_pdfgen_reg_msg_pendScan} * Request completed successfully -- Operation is successful.{#P-isDocumentFillable_S__api_pdfgen_reg_msg_succ} {#P-isDocumentFillable_S__api_pdfgen_reg_msg_succ} * Undefined -- Sys_id provided does not exist or is not a PDF attachment.{#P-isDocumentFillable_S__api_pdfgen_reg_msg_und} {#P-isDocumentFillable_S__api_pdfgen_reg_msg_und} {#P-isDocumentFillable_S__ul_qlv_5cv_j4b} Data type: String |
| \<Object\>.status | Status indicating whether the operation is successful. Possible values: * success - Operation was successful. * failure -- Operation was not successful. The message provides details. {#P-isDocumentFillable_S__ul_rlv_5cv_j4b} Data type: String |
[Table 21. Returns]

{#P-isDocumentFillable_S__table_erx_h3k_34b}  
The following example shows how to determine if PDF document fields are editable.

    var v = new sn_pdfgeneratorutils.PDFGenerationAPI;
    var result = v.isDocumentFillable("<attachmentSysId>");
    gs.info(JSON.stringify(result));

Output:

    {"message":"Request completed successfully.","document_editable":"true","status":"success"}

## PDFGenerationAPI -- redact(Object inputJson) {#ariaid-title13}

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.
Note:  
* 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](https://www.servicenow.com/docs/access?context=redact-sensitive-data&version=xanadu&pubname=xanadu-servicenow-platform&ft:locale=en-US).
* This method doesn't support redaction in PDFs containing JBIG2 images.
{#P-redact_O__ul_ulb_2dx_qbc}
{#P-redact_O__table_drx_h3k_34b__entry__3}{#P-redact_O__ph_api_pdfgen_parm_attIDesc}

| Name | Type | Description |
|-|-|-|
| inputJson | Object | Identifies the PDF and its content to be redacted. { "sysId": "String", "highlightedSections": [Array], "searchedKeywords": [Array] } |
| inputJson.sysId | String | Sys_id of a PDF in the Attachments \[sys_attachment\] table. |
| inputJson. highlightedSections | Array of Objects | List of rectangles coordinates provided as an object. Each coordinate represents the location of the content to be redacted on each page. Optional if including the searchedKeywords property. [ { "pageNumber": Number, "x": Number, "y": Number, "width": Number, "height": Number } ] |
| inputJson. highlightedSections. pageNumber | Number | PDF page number containing the content to select for redaction. |
| inputJson. highlightedSections. x | Number | The X-axis (horizontal position) of the redaction rectangle on the PDF in points. The value at the bottom-left corner of the PDF page is 0. For example, a value of <kbd class="ph userinput">306</kbd> places the rectangle approximately in the horizontal center of a letter-size PDF page. |
| inputJson. highlightedSections. y | Number | The Y-axis (vertical position) of the redaction rectangle on the PDF in points. The value at the bottom-left corner of the PDF page is 0. For example, a value of <kbd class="ph userinput">396</kbd> places the rectangle approximately in the vertical center of a letter-size PDF page. |
| inputJson. highlightedSections. width | Number | Width of the redaction rectangle is in points. This value increases the size of the rectangle horizontally from the lower left point at which the x an y axes intersect. |
| inputJson. highlightedSections. height | Number | Height of the redaction rectangle in points. This value increases the size of the rectangle vertically from the lower left point at which the x an y axes intersect. |
| inputJson. searchedKeywords | Array | List of one or more strings used to find text for redaction. The redaction rectangle size matches the height and width of the text that is blocked out as a result. Optional if including the highlightedSections property. Note: In some cases, text strings containing special characters or punctuation such as `"items:"` and `"PDF."` aren't redacted. You can alternatively remove the character from the string or highlight the area to remove the text. |
[Table 22. Parameters]

{#P-redact_O__table_drx_h3k_34b} {#P-redact_O__table_phl_lzj_34b__entry__2}{#P-redact_O__desc-fill-only}{#P-redact_O__desc_pdfgen_ret_attID_Fill}

| Type | Description |
|-|-|
| Object | Object containing sys_id of the updated PDF attachment if successful, error message otherwise. { "attachment_id": "String", "message": "String", "status": "String" } |
| \<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. Possible values: * Can't parse this format -- Unable to process an image embedded in the PDF. The PDF contains one or more images in an unsupported format, such as a JBIG2 image. * 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. {#P-redact_O__ul_eln_fwk_l4b} Data type: String |
| \<Object\>.status | Status indicating whether the operation is successful. Possible values: * success - Operation was successful. * failure -- Operation was not successful. The message provides details. {#P-redact_O__ul_rlv_5cv_j4b} Data type: String |
[Table 23. Returns]

{#P-redact_O__table_phl_lzj_34b}  
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.

    var pdfRequest = {
      sysId: 'e4b3ae35fc128210f877789781ea59f3',
      highlightedSections: [
        {
          "pageNumber": 2,
          "x": 261.75,
          "y": 480,
          "width": 21,
          "height": 14.25
        },
        {
          "pageNumber": 2,
          "x": 249,
          "y": 390.75,
          "width": 63.75,
          "height": 15.75
        }
        // Add more coordinates as needed
      ],
      searchedKeywords: ['23']
    };

    // Convert the JSON object to a string
    var jsonRequest = JSON.stringify(pdfRequest);
    gs.info('JSON Request: ' + jsonRequest + '\n');

    var PDFRedaction = new sn_pdfgeneratorutils.PDFGenerationAPI;
    var result = PDFRedaction.redact(jsonRequest);
    gs.info(JSON.stringify(result));

Output:

    JSON Request: {"sysId":"e4b3ae35fc128210f877789781ea59f3","highlightedSections":[{"pageNumber":2,"x":261.75,"y":480,"width":21,"height":14.25},{"pageNumber":2,"x":249,"y":390.75,"width":63.75,"height":15.75}],"searchedKeywords":[23]}

    {"attachment_id":"1744ae35fc128210f877789781ea59fc","message":"Request completed successfully.","status":"success"}


