パラグラフ:スコープ対象、グローバル

  • リリースバージョン: Australia
  • 更新日 2026年03月12日
  • 所要時間:15分
  • PDF 内のテキストブロックを表す段落オブジェクトを作成します。

    この API は ServiceNow PDF 生成ユーティリティプラグイン (com.snc.apppdfgenerator) の一部であり、 sn_pdfgeneratorutils 名前空間内で提供されます。このプラグインはデフォルトでアクティブ化されています。

    この API は、PDF を生成するために ドキュメント API で使用されるコンポーネントです。

    パラグラフ:パラグラフ (文字列テキスト)

    文字列を含む新しい Paragraph オブジェクトをインスタンス化します。

    表 : 1. パラメーター
    名前 タイプ 説明
    テキスト 文字列 テキストの段落ブロック。

    次の例は、 Paragraph オブジェクトの作成方法を示しています。 ドキュメントの使用例については、「 ドキュメント API」 を参照してください。

    var para = new Paragraph("hello");

    パラグラフ – addNewLine()

    ドキュメント内の段落の後に空白行を追加します。

    表 : 2. パラメーター
    名前 タイプ 説明
    なし
    表 : 3. 返される内容
    タイプ 説明
    なし

    次の例は、ドキュメント内の段落の後に改行を追加する方法を示しています。 ドキュメントの使用例については、「 ドキュメント 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");

    パラグラフ – addParagraph(パラグラフパラグラフ)

    段落を追加します。この方法を使用して、自動改行を使用して段落のブロックを作成できます。

    表 : 4. パラメーター
    名前 タイプ 説明
    paragraph パラグラフ Paragraph オブジェクト。
    表 : 5. 返される内容
    タイプ 説明
    なし

    次の例は、ドキュメントに段落のセクションを追加する方法を示しています。 ドキュメントの使用例については、「 ドキュメント 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");

    パラグラフ:addString(文字列コンテンツ)

    段落にテキストの文字列を追加します。このメソッドでは、コンテンツの前にスペースが自動的に挿入されることはありません。

    表 : 6. パラメーター
    名前 タイプ 説明
    コンテンツ 文字列 段落に含める情報。
    表 : 7. 返される内容
    タイプ 説明
    なし

    次の例は、段落に新しい文を追加する方法を示しています。 ドキュメントの使用例については、「 ドキュメント 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");

    パラグラフ – addStyle(スタイルスタイル)

    段落テキストに事前定義されたスタイルを適用します。

    表 : 8. パラメーター
    名前 タイプ 説明
    style スタイル この要素に適用するスタイル。
    表 : 9. 返される内容
    タイプ 説明
    なし

    次の例は、段落にスタイルを適用する方法を示しています。 ドキュメントの使用例については、「 ドキュメント 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");

    パラグラフ:setFixedPosition(番号左、番号下、番号幅)

    段落要素をページ上の固定位置に設定します。

    表 : 10. パラメーター
    名前 タイプ 説明
    番号 PDF ページの左側からのインデント (ポイント単位)。
    番号 PDF ページの下からの位置 (ポイント単位)。
    番号 段落要素の幅 (ポイント単位)。この値は、改行の長さを決定します。
    表 : 11. 返される内容
    タイプ 説明
    なし

    次の例は、ページ上の固定位置を設定する方法を示しています。 ドキュメントの使用例については、「 ドキュメント 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");

    パラグラフ – setMargin(数値マージン)

    各段落の余白を設定します。

    4 つのマージンすべてを 1 つ以上の一意の値で設定するには、 setMargins() を使用します。

    表 : 12. パラメーター
    名前 タイプ 説明
    余白 番号 上、右、下、および左マージンの値 (ポイント単位)。
    表 : 13. 返される内容
    タイプ 説明
    なし

    次の例は、段落のすべての余白を 48 ポイントに設定する方法を示しています。

    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");

    パラグラフ – setMarginBottom(数値マージン)

    段落の下マージンを設定します。

    表 : 14. パラメーター
    名前 タイプ 説明
    余白 番号 下マージンの高さ (ポイント単位)。
    表 : 15. 返される内容
    タイプ 説明
    なし

    次の例は、段落の下マージンを 1 ポイントに設定する方法を示しています。

    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");

    パラグラフ – setMarginLeft(数値マージン)

    段落の左マージンを設定します。

    表 : 16. パラメーター
    名前 タイプ 説明
    左マージン 番号 左マージンの幅 (ポイント単位)。
    表 : 17. 返される内容
    タイプ 説明
    なし

    次の例は、段落の左マージンを 1 ポイントに設定する方法を示しています。

    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");

    パラグラフ – setMarginRight(数値マージン)

    段落の右マージンを設定します。

    表 : 18. パラメーター
    名前 タイプ 説明
    余白 番号 右マージンの幅 (ポイント単位)。
    表 : 19. 返される内容
    タイプ 説明
    なし

    次の例は、段落の右マージンを 1 ポイントに設定する方法を示しています。

    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");

    パラグラフ – setMargins(Number marginTop, Number marginRight, Number marginBottom, Number marginLeft)

    各段落の余白のサイズを設定します。

    各マージンを同じ値に設定するには、 setMargin() を使用します。

    表 : 20. パラメーター
    名前 タイプ 説明
    topMargin 番号 上マージンの高さ (ポイント単位)。
    右マージン 番号 右マージンの幅 (ポイント単位)。
    下マージン 番号 下マージンの高さ (ポイント単位)。
    左マージン 番号 左マージンの幅 (ポイント単位)。
    表 : 21. 返される内容
    タイプ 説明
    なし

    次の例は、段落の余白を設定する方法を示しています。ドキュメントの使用例については、「 ドキュメント 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);

    パラグラフ – setMarginTop(数値マージン)

    段落の上マージンを設定します。

    表 : 22. パラメーター
    名前 タイプ 説明
    余白 番号 上マージンの高さ (ポイント単位)。
    表 : 23. 返される内容
    タイプ 説明
    なし

    次の例は、段落の上マージンを 1 ポイントに設定する方法を示しています。

    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");

    パラグラフ:setTextAlignment(文字列配置)

    この段落のテキスト配置を設定します。

    表 : 24. パラメーター
    名前 タイプ 説明
    位置調整 文字列 テキストの配置位置。
    有効な値:
    • text-center:テキストを中央に揃えます。
    • text-justified:文字間のスペースを変更して、左右の間のテキストを完全に埋めます。最後の行は左揃えです。
    • text-justified-all:最後の行を含めてテキストの配置を両端揃えします。
    • text-left:テキストを左揃えにします。
    • text-right:テキストを右揃えにします。
    表 : 25. 返される内容
    タイプ 説明
    なし

    次の例は、段落のテキストを左揃えに設定する方法を示しています。

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