---
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


---

# Paragraph - Scoped, Global

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

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

Creates a Paragraph object representing a block of text in a PDF.

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 is a component used with the [Document API](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.") to generate a
PDF.

## Paragraph - Paragraph(String text) {#ariaid-title2}

Instantiates a new Paragraph object containing a string.
{#Paragraph-Paragraph_S__table_twm_hjk_34b__entry__3}

| Name | Type | Description |
|-|-|-|
| text | String | Paragraph block of text. |
[Table 1. Parameters]

{#Paragraph-Paragraph_S__table_twm_hjk_34b}  
The following example shows how to create a Paragraph object. 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 para = new Paragraph("hello");

## Paragraph -- addNewLine() {#ariaid-title3}

Adds an empty line after a paragraph in a document.
{#Paragraph-addNewLine__table_vv5_52h_44b__entry__3}

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

{#Paragraph-addNewLine__table_vv5_52h_44b} {#Paragraph-addNewLine__table_wv5_52h_44b__entry__2}

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

{#Paragraph-addNewLine__table_wv5_52h_44b}  
The following example shows how to add a new line after a paragraph 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);
            
    var myPara = new sn_pdfgeneratorutils.Paragraph("This is a paragraph.");
    myPara.addNewLine();

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

## Paragraph -- addParagraph(Paragraph paragraph) {#ariaid-title4}

Adds a paragraph. You can use this method to create a block of paragraphs with
automatic line breaks.
{#Paragraph-addParagraph_O__table_vv5_52h_44b__entry__3}

| Name | Type | Description |
|-|-|-|
| paragraph | [Paragraph](https://servicenow-prod.fluidtopics.net/F66I_9eaQar0UBmo_g7irw#Paragraph-Paragraph_S "Instantiates a new Paragraph object containing a string.") | Paragraph object. |
[Table 4. Parameters]

{#Paragraph-addParagraph_O__table_vv5_52h_44b} {#Paragraph-addParagraph_O__table_wv5_52h_44b__entry__2}

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

{#Paragraph-addParagraph_O__table_wv5_52h_44b}  
The following example shows how to add a section of paragraphs 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 sectionPara = new sn_pdfgeneratorutils.Paragraph("This is the first paragraph.");
    var subPara1 = new sn_pdfgeneratorutils.Paragraph("Pellentesque nec neque interdum turpis ultricies tristique at ut lacus. Nam eget sollicitudin.");
    var subPara2 = new sn_pdfgeneratorutils.Paragraph("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla vel ultrices erat.");
    var subPara3 = new sn_pdfgeneratorutils.Paragraph("Aenean fermentum lorem congue metus faucibus, vitae viverra quam eleifend. Donec sed risus quis eros suscipit efficitur.");

    sectionPara.addParagraph(subPara1);
    sectionPara.addParagraph(subPara2);
    sectionPara.addParagraph(subPara3);

    document.addParagraph(sectionPara);

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

## Paragraph -- addString(String content) {#ariaid-title5}

Adds a string of text to a paragraph. This method does not automatically insert a space
preceding the content.
{#Paragraph-addString_S__table_vv5_52h_44b__entry__3}

| Name | Type | Description |
|-|-|-|
| content | String | Information to include in a paragraph. |
[Table 6. Parameters]

{#Paragraph-addString_S__table_vv5_52h_44b} {#Paragraph-addString_S__table_wv5_52h_44b__entry__2}

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

{#Paragraph-addString_S__table_wv5_52h_44b}  
The following example shows how to add a new sentence to a paragraph. 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 myPara = new sn_pdfgeneratorutils.Paragraph("This is the first sentence.");

    myPara.addString(" This is the second sentence in the same paragraph. Spaces are not inserted automatically.")

    document.addParagraph(myPara);

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

## Paragraph -- addStyle(Style style) {#ariaid-title6}

Applies a predefined style to paragraph text.
{#Paragraph-addStyle_O__table_vv5_52h_44b__entry__3}

| Name | Type | Description |
|-|-|-|
| style | [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.") | Style to apply to this element. |
[Table 8. Parameters]

{#Paragraph-addStyle_O__table_vv5_52h_44b} {#Paragraph-addStyle_O__table_wv5_52h_44b__entry__2}

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

{#Paragraph-addStyle_O__table_wv5_52h_44b}  
The following example shows how to apply a style to a paragraph. 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);

    // Create a font color (result is purple)
    var fontColor = new sn_pdfgeneratorutils.Color([0.5,0.0,0.5]);

    // Create a style for your paragraph
    var paraStyle = new sn_pdfgeneratorutils.Style();
    paraStyle.setFontColor(fontColor);
    paraStyle.setFontSize(10);

    var myPara = new sn_pdfgeneratorutils.Paragraph("This paragraph has style.");

    myPara.addStyle(paraStyle);


    document.addParagraph(myPara);

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

## Paragraph -- setFixedPosition(Number left, Number bottom, Number width) {#ariaid-title7}

Sets a paragraph element to a fixed position on the page.
{#Paragraph-setFixedPosition_N_N_N__table_vv5_52h_44b__entry__3}

| Name | Type | Description |
|-|-|-|
| left | Number | Indentation from the left side of the PDF page in points. |
| bottom | Number | Position from the bottom of the PDF page in points. |
| width | Number | Width of the paragraph element in points. This value determines the length at which the line breaks. |
[Table 10. Parameters]

{#Paragraph-setFixedPosition_N_N_N__table_vv5_52h_44b} {#Paragraph-setFixedPosition_N_N_N__table_wv5_52h_44b__entry__2}

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

{#Paragraph-setFixedPosition_N_N_N__table_wv5_52h_44b}  
The following example shows how to set a fixed position on a page. 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);

    // Create a style
    var paraStyle = new sn_pdfgeneratorutils.Style();
    paraStyle.setFontSize(48);
    paraStyle.setBold();

    // my paragraph
    var para = new sn_pdfgeneratorutils.Paragraph("Document Title");

    para.setFixedPosition(204,400,240);

    para.setTextAlignment("text-center");
    para.addStyle(paraStyle);


    document.addParagraph(para);

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

## Paragraph -- setMargin(Number margin) {#ariaid-title8}

Sets each paragraph margin.
To set all four margins with one or more unique values, use [setMargins()](https://servicenow-prod.fluidtopics.net/F66I_9eaQar0UBmo_g7irw#Paragraph-setMargins_N_N_N_N "Sets a size for each paragraph margin.").
{#Paragraph-setMargin_N__table_vv5_52h_44b__entry__3}

| Name | Type | Description |
|-|-|-|
| margin | Number | Value of the top, right, bottom, and left margins in points. |
[Table 12. Parameters]

{#Paragraph-setMargin_N__table_vv5_52h_44b} {#Paragraph-setMargin_N__table_wv5_52h_44b__entry__2}

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

{#Paragraph-setMargin_N__table_wv5_52h_44b}  
The following example shows how to set the all margins of the paragraph to 48 points.

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

    var margins = 48.0;

    var myPara = new sn_pdfgeneratorutils.Paragraph("Paragraph text with all margins set to the same value.");
    myPara.setMargin(margins);

    document.addParagraph(myPara);

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

## Paragraph -- setMarginBottom(Number margin) {#ariaid-title9}

Sets the bottom margin of a paragraph.
{#Paragraph-setMarginBottom_N__table_vv5_52h_44b__entry__3}

| Name | Type | Description |
|-|-|-|
| margin | Number | Height of the bottom margin in points. |
[Table 14. Parameters]

{#Paragraph-setMarginBottom_N__table_vv5_52h_44b} {#Paragraph-setMarginBottom_N__table_wv5_52h_44b__entry__2}

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

{#Paragraph-setMarginBottom_N__table_wv5_52h_44b}  
The following example shows how to set the bottom margin of a paragraph to one point.

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

    var marginVal = 1.0;

    var paraMarginBottom = new sn_pdfgeneratorutils.Paragraph("Paragraph text with bottom margin set.");
    paraMarginBottom.setMarginBottom(marginVal);

    document.addParagraph(paraMarginBottom);

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

## Paragraph -- setMarginLeft(Number margin) {#ariaid-title10}

Sets the left margin of a paragraph.
{#Paragraph-setMarginLeft_N__table_vv5_52h_44b__entry__3}{#Paragraph-setMarginLeft_N__docviewer-api-parm-leftM-des}

| Name | Type | Description |
|-|-|-|
| leftMargin | Number | Width of the left margin in points. |
[Table 16. Parameters]

{#Paragraph-setMarginLeft_N__table_vv5_52h_44b} {#Paragraph-setMarginLeft_N__table_wv5_52h_44b__entry__2}

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

{#Paragraph-setMarginLeft_N__table_wv5_52h_44b}  
The following example shows how to set the left margin of a paragraph to one point.

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

    var marginVal = 1.0;

    var paraMarginLeft = new sn_pdfgeneratorutils.Paragraph("Paragraph text with left margin set.");
    paraMarginLeft.setMarginLeft(marginVal);

    document.addParagraph(paraMarginLeft);

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

## Paragraph -- setMarginRight(Number margin) {#ariaid-title11}

Sets the right margin of a paragraph.
{#Paragraph-setMarginRight_N__table_vv5_52h_44b__entry__3}

| Name | Type | Description |
|-|-|-|
| margin | Number | Width of the right margin in points. |
[Table 18. Parameters]

{#Paragraph-setMarginRight_N__table_vv5_52h_44b} {#Paragraph-setMarginRight_N__table_wv5_52h_44b__entry__2}

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

{#Paragraph-setMarginRight_N__table_wv5_52h_44b}  
The following example shows how to set the right margin of a paragraph to one point.

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

    var marginVal = 1.0;

    var paraMarginRight = new sn_pdfgeneratorutils.Paragraph("Paragraph text with right margin set.");
    paraMarginRight.setMarginRight(marginVal);

    document.addParagraph(paraMarginRight);

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

## Paragraph -- setMargins(Number marginTop, Number marginRight, Number marginBottom, Number
marginLeft) {#ariaid-title12}

Sets a size for each paragraph margin.
To set each margin to the same value, use [setMargin()](https://servicenow-prod.fluidtopics.net/F66I_9eaQar0UBmo_g7irw#Paragraph-setMargin_N "Sets each paragraph margin.").
{#Paragraph-setMargins_N_N_N_N__table_vv5_52h_44b__entry__3}{#Paragraph-setMargins_N_N_N_N__docviewer-api-parm-topM-des}{#Paragraph-setMargins_N_N_N_N__docviewer-api-parm-rightM-des}{#Paragraph-setMargins_N_N_N_N__docviewer-api-parm-bottomM-des}{#Paragraph-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 20. Parameters]

{#Paragraph-setMargins_N_N_N_N__table_vv5_52h_44b} {#Paragraph-setMargins_N_N_N_N__table_wv5_52h_44b__entry__2}

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

{#Paragraph-setMargins_N_N_N_N__table_wv5_52h_44b}  
The following example shows how to set paragraph margins.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 para = new sn_pdfgeneratorutils.Paragraph("Paragraph text.");

    var topMargin = 1.0;
    var rightMargin = 1.0;
    var bottomMargin = 1.0;
    var leftMargin = 1.5;

    para.setMargins(marginTop, marginRight, marginBottom, marginLeft);

## Paragraph -- setMarginTop(Number margin) {#ariaid-title13}

Sets the top margin of a paragraph.
{#Paragraph-setMarginTop_N__table_vv5_52h_44b__entry__3}

| Name | Type | Description |
|-|-|-|
| margin | Number | Height of the top margin in points. |
[Table 22. Parameters]

{#Paragraph-setMarginTop_N__table_vv5_52h_44b} {#Paragraph-setMarginTop_N__table_wv5_52h_44b__entry__2}

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

{#Paragraph-setMarginTop_N__table_wv5_52h_44b}  
The following example shows how to set the top margin of a paragraph to one point.

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

    var marginVal = 1.0;

    var paraMarginTop = new sn_pdfgeneratorutils.Paragraph("Paragraph text with top margin set.");
    paraMarginTop.setMarginTop(marginVal);

    document.addParagraph(paraMarginTop);

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

## Paragraph -- setTextAlignment(String alignment) {#ariaid-title14}

Sets the text alignment of this paragraph.
{#Paragraph-setTextAlignment_S__table_vv5_52h_44b__entry__3}

| Name | Type | Description |
|-|-|-|
| alignment | String | Text alignment position. Valid values: * text-center: Aligns text to the center. * text-justified: Modifies the space between characters to completely fill text between the left and right sides. The final line is left-aligned. * text-justified-all: Justifies text alignment including the final line. * text-left: Align text to the left. * text-right: Align text to the right. {#Paragraph-setTextAlignment_S__ul_sgj_44p_p4b} |
[Table 24. Parameters]

{#Paragraph-setTextAlignment_S__table_vv5_52h_44b} {#Paragraph-setTextAlignment_S__table_wv5_52h_44b__entry__2}

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

{#Paragraph-setTextAlignment_S__table_wv5_52h_44b}  
The following example shows how to set the paragraph text to left alignment.

    var paragraph = new sn_pdfgeneratorutils.Paragraph("This paragraph text is centered.");
            
    var alignment = "text-center";
           
    paragraph.setTextAlignment(alignment);


