---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# Document - Scoped, Global

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

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 9 minutes to read

The Document API provides methods to initialize a PDF, add content,
and close the PDF. After adding content, the document can be attached to a target
record.

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.  
This API depends on the a suite of classes to build various elements comprising a PDF.

* [Cell](https://servicenow-prod.fluidtopics.net/uii5Qv66Cr~ri3bGB3uEvw#CellBothAPI "Creates a Cell object as a cell in a table. You can use this API to format the cell and include additional blocks, such as paragraphs and images.") -- Creates a Cell object as a cell in a table. You can use this API to format the cell and include additional blocks, such as paragraphs and images.
* [Color](https://servicenow-prod.fluidtopics.net/0EiXfws~5CY1d9dHdAL1UQ#ColorBothAPI "Creates a Color object used to define color attributes that you can apply to elements in a PDF; such as cells, tables, and lines.") -- Creates a Color object used to define color attributes that you can apply to elements in a PDF; such as cells, tables, and lines.
* [Image](https://servicenow-prod.fluidtopics.net/ulntT09aQ0TR~gRUuuS2Eg#ImageBothAPI "Creates an Image object representing an image and its layout insert in a PDF. Enables defining attributes such as scale, alignment, and border color.") -- Creates an Image object representing an image and its layout insert in a PDF. Enables defining attributes such as scale, alignment, and border color.
* [Line](https://servicenow-prod.fluidtopics.net/2vtFA~iaGjpKb8_ySGPr1w#LineBothAPI "Creates a Line object using methods to draw a line in a PDF.") -- Creates a Line object using methods to draw a line in a PDF.
* [Paragraph](https://servicenow-prod.fluidtopics.net/F66I_9eaQar0UBmo_g7irw#ParagraphBothAPI "Creates a Paragraph object representing a block of text in a PDF.") -- Creates a Paragraph object representing a block of text in a PDF.
* [PdfPage](https://servicenow-prod.fluidtopics.net/NvW_dlzXFzTihPWSTLMsWA#PdfPageBothAPI "Creates a PdfPage object representing a PDF page and its attributes; such as size, width, and color.") -- Creates a PdfPage object representing a PDF page and its attributes; such as size, width, and color.
* [Style](https://servicenow-prod.fluidtopics.net/EJ1CwYDsf~Ytpinx1B9fbg#StyleBothAPI "Creates a style for defining properties such font size, border, and alignment. You can apply the same style to multiple objects simultaneously.") -- Creates a style for defining properties such font size, border, and alignment. You can apply the same style to multiple objects simultaneously.
* [Table](https://servicenow-prod.fluidtopics.net/IaWzvxiBPOHtuTwBsfUUOg#TableBothAPI "Creates a Table object to add to a PDF document. Defines the data to use in each cell and sets styles, margins, and alignment.") -- Creates a Table object to add to a PDF document. Defines the data to use in each cell and sets styles, margins, and alignment.
{#DocumentBothAPI__ul_cc4_bt1_t4b}  
The following example shows how to create a basic PDF using the Document
API and several components, such as a table, cell, and paragraph. The result is a list of
Incidents from the Incident \[incident\] table listed in a PDF. You can test this example in
your instance if you replace `<sys_id>` with the sys_id of an incident
record.

    var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");
    var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);
     
    var whiteColor =  sn_pdfgeneratorutils.Color([1,1,1]);
    var greyColor =  sn_pdfgeneratorutils.Color([0.8,0.8,0.8]);
    var headerBgColor = new sn_pdfgeneratorutils.Color([0.4,0.6,0.8]);
     
    // Query the Incident table
    var gr = new GlideRecord("incident");
    gr.query();
     
    // declare table by providing width array and Boolean for large table
    var table = new sn_pdfgeneratorutils.Table(true, [70,200], false);
     
    var headerStyle = new sn_pdfgeneratorutils.Style;
    headerStyle.setBackgroundColor(headerBgColor);
    headerStyle.setTextAlignment("text-center");
    headerStyle.setBold();
    headerStyle.setFontColor(whiteColor);
     
    table.setHeaderStyle(headerStyle);
     
    var nParagraph = new sn_pdfgeneratorutils.Paragraph("Number");
    var sParagraph = new sn_pdfgeneratorutils.Paragraph("Short Description");
     
    var hdrCell1 = new sn_pdfgeneratorutils.Cell;
    var hdrCell2 = new sn_pdfgeneratorutils.Cell;
     
    hdrCell1.addParagraph(nParagraph);
    hdrCell2.addParagraph(sParagraph);
     
    table.addHeaderCell(hdrCell1);
    table.addHeaderCell(hdrCell2);
     
    var row = 0;
     
    while(gr.next()) {
    var numCell = new sn_pdfgeneratorutils.Cell;
    var sdCell = new sn_pdfgeneratorutils.Cell;
     
    var numberParagraph = new sn_pdfgeneratorutils.Paragraph(gr.number);
    var sdParagraph = new sn_pdfgeneratorutils.Paragraph(gr.short_description);
     
    numCell.addParagraph(numberParagraph);
    sdCell.addParagraph(sdParagraph);
     
    if (row % 2 == 1) {
         table.setDefaultbackGroundColor(greyColor);
    } else {
         table.setDefaultbackGroundColor(whiteColor);
    }
     
    table.addCell(numCell);
    table.addCell(sdCell);
     
    row = row + 1;
    }
     
    document.addTable(table);
    document.saveAsAttachment("incident", "<sys_id>", "SampleGenerationTest.pdf");

The PDF attachment is listed in the Attachments \[sys_attachment\] table.

## Document - Document(PdfPage pageSize) {#ariaid-title2}

Instantiates a Document object and generates a PDF
document.
{#Document-Document_O__table_twm_hjk_34b__entry__3}

| Name | Type | Description |
|-|-|-|
| pageSize | [PdfPage](https://servicenow-prod.fluidtopics.net/NvW_dlzXFzTihPWSTLMsWA#PdfPageBothAPI "Creates a PdfPage object representing a PDF page and its attributes; such as size, width, and color.") | PDF page size. |
[Table 1. Parameters]

{#Document-Document_O__table_twm_hjk_34b} {#Document-Document_O__table_wv5_52h_44b__entry__2}

| Type | Description |
|-|-|
| Object | PDF document. |
[Table 2. Returns]

{#Document-Document_O__table_wv5_52h_44b}  
The following example shows how to create a Document object and return a
PDF.

    var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");
    var document = new sn_pdfgeneratorutils.Document(pageSize);

## Document -- addAndStartNewPage() {#ariaid-title3}

Adds a page to the document by terminating the current page and creating a new one.
Additional methods for adding a new page in a document:

* [addNewPage()](https://servicenow-prod.fluidtopics.net/oJ48cUW_0DIZl2sK2PI~9A#Document-addNewPage "Adds a new blank page to the document. Use to force a page break to start a new chapter or section in your document.") -- Adds a new blank page to the document. Use to force a page break to start a new chapter or section in your document.{#Document-addAndStartNewPage__document-addNewPage-sdesc}
* [addNewPageAtIndex()](https://servicenow-prod.fluidtopics.net/oJ48cUW_0DIZl2sK2PI~9A#Document-addNewPageAtIndex_N "Adds a new page at the specified index of the document. For example, setting the index to 6 inserts a page six or inserts the page at the position of the existing page six in a document. The original page six becomes page seven.") -- Adds a new page at the specified index of the document. For example, setting the index to 6 inserts a page six or inserts the page at the position of the existing page six in a document. The original page six becomes page seven.{#Document-addAndStartNewPage__document-addNewPageAtIndex-sdesc}
{#Document-addAndStartNewPage__ul_bxw_z4f_t4b}
{#Document-addAndStartNewPage__table_vv5_52h_44b__entry__3}

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

{#Document-addAndStartNewPage__table_vv5_52h_44b} {#Document-addAndStartNewPage__table_wv5_52h_44b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 4. Returns]

{#Document-addAndStartNewPage__table_wv5_52h_44b}  
The following example shows how to add a new page to a document. For a document usage example, see [Document](https://servicenow-prod.fluidtopics.net/oJ48cUW_0DIZl2sK2PI~9A#DocumentBothAPI "The Document API provides methods to initialize a PDF, add content, and close the PDF. After adding content, the document can be attached to a target record.") API.

    var pageSize = new sn_pdfgeneratorutils.PdfPage("LETTER");
    var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);

    var para1 = new sn_pdfgeneratorutils.Paragraph("This text lands on the first page.");
    var para2 = new sn_pdfgeneratorutils.Paragraph("This text lands on the new page.");

    document.addParagraph(para1);

    document.addAndStartNewPage();

    document.addParagraph(para2);

    // save pdf as attachment to target record in the Incident table
    document.saveAsAttachment("incident", "<record_sys_id>", "newPage.pdf");

## Document -- addAuthor(String author) {#ariaid-title4}

Adds a name to the author field in PDF document properties.
{#Document-addAuthor_S__table_vv5_52h_44b__entry__3}

| Name | Type | Description |
|-|-|-|
| author | String | Name of the document's author. |
[Table 5. Parameters]

{#Document-addAuthor_S__table_vv5_52h_44b} {#Document-addAuthor_S__table_wv5_52h_44b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 6. Returns]

{#Document-addAuthor_S__table_wv5_52h_44b}  
The following example shows how to add a name to the author field in PDF document
properties. For a document usage example, see [Document](https://servicenow-prod.fluidtopics.net/oJ48cUW_0DIZl2sK2PI~9A#DocumentBothAPI "The Document API provides methods to initialize a PDF, add content, and close the PDF. After adding content, the document can be attached to a target record.") API.

    var author = "John Do";

    document.addAuthor(author);

## Document -- addImage(Image image) {#ariaid-title5}

Adds an image to a document.
{#Document-addImage_O__table_vv5_52h_44b__entry__3}

| Name | Type | Description |
|-|-|-|
| image | [Image](https://servicenow-prod.fluidtopics.net/ulntT09aQ0TR~gRUuuS2Eg#ImageBothAPI "Creates an Image object representing an image and its layout insert in a PDF. Enables defining attributes such as scale, alignment, and border color.") | Image to add to a document. |
[Table 7. Parameters]

{#Document-addImage_O__table_vv5_52h_44b} {#Document-addImage_O__table_wv5_52h_44b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 8. Returns]

{#Document-addImage_O__table_wv5_52h_44b}  
The following example shows how to add an image to a document. For a document usage example, see [Document](https://servicenow-prod.fluidtopics.net/oJ48cUW_0DIZl2sK2PI~9A#DocumentBothAPI "The Document API provides methods to initialize a PDF, add content, and close the PDF. After adding content, the document can be attached to a target record.") API.

    var pageSize = new sn_pdfgeneratorutils.PdfPage("LETTER");
    var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);
     
    // declare image using sys attachment
    var image = new sn_pdfgeneratorutils.Image("<imgAttachment_sys_id>");

    // add the image to the doc
    document.addImage(image);

    document.saveAsAttachment("incident", "<record_sys_id>", "docWithImage.pdf");

## Document -- addNewLine() {#ariaid-title6}

Adds a new empty line to the document.
{#Document-addNewLine__table_vv5_52h_44b__entry__3}

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

{#Document-addNewLine__table_vv5_52h_44b} {#Document-addNewLine__table_wv5_52h_44b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 10. Returns]

{#Document-addNewLine__table_wv5_52h_44b}  
The following example shows how to add a new line to a document. For a document usage example, see [Document](https://servicenow-prod.fluidtopics.net/oJ48cUW_0DIZl2sK2PI~9A#DocumentBothAPI "The Document API provides methods to initialize a PDF, add content, and close the PDF. After adding content, the document can be attached to a target record.") API.

    var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");

    var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);

    document.addNewLine();

## Document -- addNewPage() {#ariaid-title7}

Adds a new blank page to the document. Use to force a page break to start a new chapter or section in your document.
Additional methods for adding a new page in a document:

* [addAndStartNewPage()](https://servicenow-prod.fluidtopics.net/oJ48cUW_0DIZl2sK2PI~9A#Document-addAndStartNewPage "Adds a page to the document by terminating the current page and creating a new one.")-- Adds a page to the document by terminating the current page and creating a new one.{#Document-addNewPage__document-addAndStartNewPage-sdesc}
* [addNewPageAtIndex()](https://servicenow-prod.fluidtopics.net/oJ48cUW_0DIZl2sK2PI~9A#Document-addNewPageAtIndex_N "Adds a new page at the specified index of the document. For example, setting the index to 6 inserts a page six or inserts the page at the position of the existing page six in a document. The original page six becomes page seven.") -- Adds a new page at the specified index of the document. For example, setting the index to 6 inserts a page six or inserts the page at the position of the existing page six in a document. The original page six becomes page seven.{#Document-addNewPage__document-addNewPageAtIndex-sdesc}
{#Document-addNewPage__ul_bxw_z4f_t4b}
{#Document-addNewPage__table_vv5_52h_44b__entry__3}

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

{#Document-addNewPage__table_vv5_52h_44b} {#Document-addNewPage__table_wv5_52h_44b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 12. Returns]

{#Document-addNewPage__table_wv5_52h_44b}  
The following example shows how to add a new blank page to a document. For a document usage example, see [Document](https://servicenow-prod.fluidtopics.net/oJ48cUW_0DIZl2sK2PI~9A#DocumentBothAPI "The Document API provides methods to initialize a PDF, add content, and close the PDF. After adding content, the document can be attached to a target record.") API.

    Usage:
    var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");
    var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);

    document.addNewPage();

## Document -- addNewPageAtIndex(Number index) {#ariaid-title8}

Adds a new page at the specified index of the document. For example, setting the index to 6 inserts a page six or inserts the page at the position of the existing page six in a document. The original page six becomes page seven.
Additional methods for adding a new page in a document:

* [addAndStartNewPage()](https://servicenow-prod.fluidtopics.net/oJ48cUW_0DIZl2sK2PI~9A#Document-addAndStartNewPage "Adds a page to the document by terminating the current page and creating a new one.")-- Adds a page to the document by terminating the current page and creating a new one.{#Document-addNewPageAtIndex_N__document-addAndStartNewPage-sdesc}
* [addNewPage()](https://servicenow-prod.fluidtopics.net/oJ48cUW_0DIZl2sK2PI~9A#Document-addNewPage "Adds a new blank page to the document. Use to force a page break to start a new chapter or section in your document.") -- Adds a new blank page to the document. Use to force a page break to start a new chapter or section in your document.{#Document-addNewPageAtIndex_N__document-addNewPage-sdesc}
{#Document-addNewPageAtIndex_N__ul_bxw_z4f_t4b}
{#Document-addNewPageAtIndex_N__table_vv5_52h_44b__entry__3}

| Name | Type | Description |
|-|-|-|
| index | Number | Position at which to insert a new page. |
[Table 13. Parameters]

{#Document-addNewPageAtIndex_N__table_vv5_52h_44b} {#Document-addNewPageAtIndex_N__table_wv5_52h_44b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 14. Returns]

{#Document-addNewPageAtIndex_N__table_wv5_52h_44b}  
The following example shows how to add a new PDF page to position 6 of a document. For a document usage example, see [Document](https://servicenow-prod.fluidtopics.net/oJ48cUW_0DIZl2sK2PI~9A#DocumentBothAPI "The Document API provides methods to initialize a PDF, add content, and close the PDF. After adding content, the document can be attached to a target record.") API.

    var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");

    var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);

    var index = 6;

    document.addNewPageAtIndex(index);

## Document -- addParagraph(Paragraph paragraph) {#ariaid-title9}

Adds a paragraph to a document.
{#Document-addParagraph_O__table_vv5_52h_44b__entry__3}

| Name | Type | Description |
|-|-|-|
| paragraph | [Paragraph](https://servicenow-prod.fluidtopics.net/F66I_9eaQar0UBmo_g7irw#ParagraphBothAPI "Creates a Paragraph object representing a block of text in a PDF.") | Block of text provided as a paragraph object. |
[Table 15. Parameters]

{#Document-addParagraph_O__table_vv5_52h_44b} {#Document-addParagraph_O__table_wv5_52h_44b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 16. Returns]

{#Document-addParagraph_O__table_wv5_52h_44b}  
The following example shows how to add a paragraph to a document. For a document usage example, see [Document](https://servicenow-prod.fluidtopics.net/oJ48cUW_0DIZl2sK2PI~9A#DocumentBothAPI "The Document API provides methods to initialize a PDF, add content, and close the PDF. After adding content, the document can be attached to a target record.") API.

    var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");
    var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);

    var para = "Lorem ipsum dolor sit amet.";

    document.addParagraph(para);

## Document -- addTable(Table table) {#ariaid-title10}

Adds a table to a document.
{#Document-addTable_O__table_vv5_52h_44b__entry__3}

| Name | Type | Description |
|-|-|-|
| table | [Table](https://servicenow-prod.fluidtopics.net/IaWzvxiBPOHtuTwBsfUUOg#TableBothAPI "Creates a Table object to add to a PDF document. Defines the data to use in each cell and sets styles, margins, and alignment.") | Table to be inserted into the document. |
[Table 17. Parameters]

{#Document-addTable_O__table_vv5_52h_44b} {#Document-addTable_O__table_wv5_52h_44b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 18. Returns]

{#Document-addTable_O__table_wv5_52h_44b}  
The following example shows how to add a table to a document. See the [Table API](https://servicenow-prod.fluidtopics.net/IaWzvxiBPOHtuTwBsfUUOg#TableBothAPI "Creates a Table object to add to a PDF document. Defines the data to use in each cell and sets styles, margins, and alignment.") for more details on how
to define a table. For a document usage example, see [Document](https://servicenow-prod.fluidtopics.net/oJ48cUW_0DIZl2sK2PI~9A#DocumentBothAPI "The Document API provides methods to initialize a PDF, add content, and close the PDF. After adding content, the document can be attached to a target record.") API.

    var table = new sn_pdfgeneratorutils.Table([70,200], false);

    document.addTable(table);

## Document -- close() {#ariaid-title11}

Closes a document.
{#Document-close__table_vv5_52h_44b__entry__3}

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

{#Document-close__table_vv5_52h_44b} {#Document-close__table_wv5_52h_44b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 20. Returns]

{#Document-close__table_wv5_52h_44b}  
The following example shows how to close a document. For a document usage example, see [Document](https://servicenow-prod.fluidtopics.net/oJ48cUW_0DIZl2sK2PI~9A#DocumentBothAPI "The Document API provides methods to initialize a PDF, add content, and close the PDF. After adding content, the document can be attached to a target record.") API.

    var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");
    var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);

    document.close();

## Document -- createDocument(PdfPage pageSize) {#ariaid-title12}

Creates a document with the specified page size.
{#Document-createDocument_O__table_vv5_52h_44b__entry__3}

| Name | Type | Description |
|-|-|-|
| pageSize | [PdfPage](https://servicenow-prod.fluidtopics.net/NvW_dlzXFzTihPWSTLMsWA#PdfPageBothAPI "Creates a PdfPage object representing a PDF page and its attributes; such as size, width, and color.") | Document page size. |
[Table 21. Parameters]

{#Document-createDocument_O__table_vv5_52h_44b} {#Document-createDocument_O__table_wv5_52h_44b__entry__2}

| Type | Description |
|-|-|
| Object | PDF document. |
[Table 22. Returns]

{#Document-createDocument_O__table_wv5_52h_44b}  
The following example shows how to create a document. For a document usage example, see [Document](https://servicenow-prod.fluidtopics.net/oJ48cUW_0DIZl2sK2PI~9A#DocumentBothAPI "The Document API provides methods to initialize a PDF, add content, and close the PDF. After adding content, the document can be attached to a target record.") API.

    var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");

    var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);

## Document -- getPageCount() {#ariaid-title13}

Gets the number of pages in the document.
{#Document-getPageCount__table_vv5_52h_44b__entry__3}

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

{#Document-getPageCount__table_vv5_52h_44b} {#Document-getPageCount__table_wv5_52h_44b__entry__2}

| Type | Description |
|-|-|
| Number | Number of pages in the document. |
[Table 24. Returns]

{#Document-getPageCount__table_wv5_52h_44b}  
The following example shows how to get the page count of a nine-page document. For a document usage example, see [Document](https://servicenow-prod.fluidtopics.net/oJ48cUW_0DIZl2sK2PI~9A#DocumentBothAPI "The Document API provides methods to initialize a PDF, add content, and close the PDF. After adding content, the document can be attached to a target record.") API.

    var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");
    var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);

    var count = document.getPageCount();

    gs.info("The number of pages is " + count);

Output:

    The number of pages is 9

## Document -- getPageSize() {#ariaid-title14}

Gets the default page size of the document.
{#Document-getPageSize__table_vv5_52h_44b__entry__3}

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

{#Document-getPageSize__table_vv5_52h_44b} {#Document-getPageSize__table_wv5_52h_44b__entry__2}

| Type | Description |
|-|-|
| String | Value of the default page size set using the [PdfPage](https://servicenow-prod.fluidtopics.net/NvW_dlzXFzTihPWSTLMsWA#PdfPageBothAPI "Creates a PdfPage object representing a PDF page and its attributes; such as size, width, and color.") API. Possible values: * A4 -- 595 x 842 points * EXECUTIVE -- 522 x 756 points * LETTER -- 612 x 792 points * LEDGER -- 792 x 1224 points {#Document-getPageSize__ul_dml_q2p_k4b} |
[Table 26. Returns]

{#Document-getPageSize__table_wv5_52h_44b}  
The following example shows how to get the page size of a document. For a document usage example, see [Document](https://servicenow-prod.fluidtopics.net/oJ48cUW_0DIZl2sK2PI~9A#DocumentBothAPI "The Document API provides methods to initialize a PDF, add content, and close the PDF. After adding content, the document can be attached to a target record.") API.

    var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");

    var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);
     
    var pagesize = document.getPageSize();

## Document -- isClosed() {#ariaid-title15}

Indicates whether a document is closed or open.
{#Document-isClosed__table_vv5_52h_44b__entry__3}

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

{#Document-isClosed__table_vv5_52h_44b} {#Document-isClosed__table_wv5_52h_44b__entry__2}

| Type | Description |
|-|-|
| None | Flag that indicates whether a document is open or closed. Valid values: * true: Document is closed. * false: Document is open. {#Document-isClosed__ul_bqw_444_r4b} Default: true |
[Table 28. Returns]

{#Document-isClosed__table_wv5_52h_44b}  
The following example shows how to get the page size of a document. For a document usage example, see [Document](https://servicenow-prod.fluidtopics.net/oJ48cUW_0DIZl2sK2PI~9A#DocumentBothAPI "The Document API provides methods to initialize a PDF, add content, and close the PDF. After adding content, the document can be attached to a target record.") API.

    var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");

    var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);

    var closed = document.isClosed();

## Document -- saveAsAttachment(String tableName, String tableSysId, String fileName) {#ariaid-title16}

Attaches the document file to the specified target table.
{#Document-saveAsAttachment_S_S_S__table_vv5_52h_44b__entry__3}

| Name | Type | Description |
|-|-|-|
| tableName | String | Name of the table on which to attach the document. |
| tableSysId | String | Sys_id of the record on which to attach the document. |
| fileName | String | Name of the document to attach. |
[Table 29. Parameters]

{#Document-saveAsAttachment_S_S_S__table_vv5_52h_44b} {#Document-saveAsAttachment_S_S_S__table_wv5_52h_44b__entry__2}

| Type | Description |
|-|-|
| String | Sys_id of the attached document in the Attachments \[sys_attachment\] table. |
[Table 30. Returns]

{#Document-saveAsAttachment_S_S_S__table_wv5_52h_44b}  
The following example shows how to attach a document to an incident record. For a document usage example, see [Document](https://servicenow-prod.fluidtopics.net/oJ48cUW_0DIZl2sK2PI~9A#DocumentBothAPI "The Document API provides methods to initialize a PDF, add content, and close the PDF. After adding content, the document can be attached to a target record.") API.

    var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);

    // Additional document properties

    document.saveAsAttachment("incident", "<record_sys_id>", "SampleDocGeneration.pdf");

## Document -- setBaseDirection(String direction) {#ariaid-title17}

Sets the base text flow direction to reorder from based on character
recognition
{#Document-setBaseDirection_S__table_vv5_52h_44b__entry__3}

| Name | Type | Description |
|-|-|-|
| direction | String | Text flow direction. Valid values: * LEFT_TO_RIGHT: Order text flow left to right. The text direction is only reordered if left-to-right language characters are detected. * RIGHT_TO_LEFT: Order text flow right to left. The text direction is only reordered if right-to-left language characters are detected. {#Document-setBaseDirection_S__ul_ifh_p5q_p4b} Default: LEFT_TO_RIGHT |
[Table 31. Parameters]

{#Document-setBaseDirection_S__table_vv5_52h_44b} {#Document-setBaseDirection_S__table_wv5_52h_44b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 32. Returns]

{#Document-setBaseDirection_S__table_wv5_52h_44b}  
The following example shows how to set text flow left to right. For a document usage example, see [Document](https://servicenow-prod.fluidtopics.net/oJ48cUW_0DIZl2sK2PI~9A#DocumentBothAPI "The Document API provides methods to initialize a PDF, add content, and close the PDF. After adding content, the document can be attached to a target record.") API.

    var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");

    var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);

    document.setBaseDirection("RIGHT_TO_LEFT");

## Document -- setMargins(Number topMargin, Number rightMargin, Number bottomMargin, Number
leftMargin) {#ariaid-title18}

Sets the page margin sizes in the document.
{#Document-setMargins_N_N_N_N__table_vv5_52h_44b__entry__3}{#Document-setMargins_N_N_N_N__docviewer-api-parm-topM-des}{#Document-setMargins_N_N_N_N__docviewer-api-parm-rightM-des}{#Document-setMargins_N_N_N_N__docviewer-api-parm-bottomM-des}{#Document-setMargins_N_N_N_N__docviewer-api-parm-leftM-des}

| Name | Type | Description |
|-|-|-|
| topMargin | Number | Height of the top margin in points. |
| rightMargin | Number | Width of the right margin in points. |
| bottomMargin | Number | Height of the bottom margin in points. |
| leftMargin | Number | Width of the left margin in points. |
[Table 33. Parameters]

{#Document-setMargins_N_N_N_N__table_vv5_52h_44b} {#Document-setMargins_N_N_N_N__table_wv5_52h_44b__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 34. Returns]

{#Document-setMargins_N_N_N_N__table_wv5_52h_44b}  
The following example shows how to set page margins in a document. For a document usage example, see [Document](https://servicenow-prod.fluidtopics.net/oJ48cUW_0DIZl2sK2PI~9A#DocumentBothAPI "The Document API provides methods to initialize a PDF, add content, and close the PDF. After adding content, the document can be attached to a target record.") API.

    var pageSize = new sn_pdfgeneratorutils.PdfPage("A4");
    var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);

    document.setMargins(72,36,36,36);


