---
sourceDocument: Xanadu API リファレンス
sourceDocumentLink: https://www.servicenow.com/docs/r/ja-JP/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - ja-JP

ft:publication_title :

    - Xanadu API リファレンス

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# Image - スコープ指定、グローバル

# Image - スコープ指定、グローバル {#ariaid-title1}

* リリースバージョン: Xanadu
* 
* 更新日 2024年08月01日
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 所要時間：9分

画像と PDF に挿入するそのレイアウトを表す Image オブジェクトを作成します。スケール、配置、境界色などの属性を定義できます。

この API は、 ServiceNow PDF Generation Utilities プラグイン (com.snc.apppdfgenerator) の一部であり、 `sn_pdfgeneratorutils` 名前空間内で提供されます。このプラグインはデフォルトでは有効になっています。

この API は、PDF を生成するために[ドキュメント API](https://www.servicenow.com/docs/PkT2cVgUF6xDOPZvUnjHtw#DocumentBothAPI "Document API には、PDF の初期化、コンテンツの追加、PDF のクローズを行うメソッドが用意されています。コンテンツを追加した後、ドキュメントをターゲットレコードに添付できます。") とともに使用されるコンポーネントです。  
次のいずれかの方法を使用して、PDF に画像を追加できます。

* [Cell -- addImage(画像 image)](https://www.servicenow.com/docs/WSUFZ9uZam0WKcEP7nd_Cw#Cell-addImage_O "テーブルセルに画像を追加します。") -- テーブルセルに画像を追加する
* [Table -- addImageCell(画像 image)](https://www.servicenow.com/docs/Tq1VCId8LFSSL8ibkjrd~A#Table-addImageCell_O "画像を含むセルをテーブルに追加します。") -- 画像を含むセルをテーブルに追加する
* [Document -- addImage(画像 image)](https://www.servicenow.com/docs/PkT2cVgUF6xDOPZvUnjHtw#Document-addImage_O "ドキュメントに画像を追加します。") - ページに画像を追加する
{#ImageBothAPI__ul_jkh_55q_s4b}

## Image - Image(文字列 attachmentSysId) {#ariaid-title2}

新しい Image オブジェクトをインスタンス化します。画像添付ファイルが存在し、変更できるかどうかを確認するために使用されます。
{#Image-Image_S__table_twm_hjk_34b__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| attachmentSysId | 文字列 | 添付ファイル \[sys_attachment\] テーブル内の画像の sys_id。 |
[表 : 1. パラメーター]

{#Image-Image_S__table_twm_hjk_34b}  
次の例は、Image オブジェクトを作成する方法を示しています。

    var image = new sn_pdfgeneratorutils.Image("<sys_id>");

## Image -- scaleAbsolute(数字 width, 数字 height) {#ariaid-title3}

画像を幅と高さのサイズ (絶対値) に拡大縮小します。この設定では画像の幅と高さの比率が保持されないため、設定が正確でないと望ましくないサイズに拡大される可能性があります。
画像の幅と高さの比率を保持した絶対値のサイズに拡大縮小するには、[scaleToFit()](https://www.servicenow.com/docs/Etr_NEw08i33zJAv3zMy0g#Image-scaleToFit_N_N "幅と高さの比率を維持して画像を絶対値のサイズに拡大縮小します。") メソッドを使用します。
{#Image-scaleAbsolute_N_N__table_vv5_52h_44b__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| width | 番号 | 画像の幅 (単位：ポイント)。 |
| height | 番号 | 画像の高さ (単位：ポイント)。 |
[表 : 2. パラメーター]

{#Image-scaleAbsolute_N_N__table_vv5_52h_44b} {#Image-scaleAbsolute_N_N__table_wv5_52h_44b__entry__2}

| タイプ | 説明 |
|-|-|
| なし |   |
[表 : 3. 返される内容]

{#Image-scaleAbsolute_N_N__table_wv5_52h_44b}  
次の例は、絶対値の幅と高さを設定して PDF に画像を追加する方法を示しています。

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

    var scaleAbsPic = new sn_pdfgeneratorutils.Image("<img_sys_id>");
    scaleAbsPic.scaleAbsolute(25,50);

    document.addImage(scaleAbsPic);

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

## Image -- scaleToFit(数字 width, 数字 height) {#ariaid-title4}

幅と高さの比率を維持して画像を絶対値のサイズに拡大縮小します。
結果の出力は画像のアスペクト比によって異なります。幅と高さのパラメーター値が画像のアスペクト比と一致しない場合、一方の値が指定された値よりも小さく出力に表示されます。
{#Image-scaleToFit_N_N__table_vv5_52h_44b__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| width | 数字 | 画像の最大幅 (単位：ポイント)。 |
| height | 数字 | 画像の最大の高さ (単位：ポイント)。 |
[表 : 4. パラメーター]

{#Image-scaleToFit_N_N__table_vv5_52h_44b} {#Image-scaleToFit_N_N__table_wv5_52h_44b__entry__2}

| タイプ | 説明 |
|-|-|
| なし |   |
[表 : 5. 返される内容]

{#Image-scaleToFit_N_N__table_wv5_52h_44b}  
次の例は、[Cell -- addImage()](https://www.servicenow.com/docs/WSUFZ9uZam0WKcEP7nd_Cw#Cell-addImage_O "テーブルセルに画像を追加します。") メソッドを使用して拡大縮小された画像を挿入する方法を示しています。

    var pageSize = new sn_pdfgeneratorutils.PdfPage("LETTER");
    var document = new sn_pdfgeneratorutils.Document.createDocument(pageSize);
     
    // add a table
    var table = new sn_pdfgeneratorutils.Table([1,3],false);

    // text for the left column
    var text = "sample image";

    // add a table cell for the image in the right column
    var imgCell = new sn_pdfgeneratorutils.Cell(1, 1);

    // add an image and set it scale-to-fit
    var scaleToFitPic = new sn_pdfgeneratorutils.Image("<img_sys_id>");
    scaleToFitPic.scaleToFit(90,175);

    // add the image to the cell
    imgCell.addImage(scaleToFitPic);
     
    table.addTextCell(text);
    table.addCell(imgCell);

    // Here's a paragraph
    var para = new sn_pdfgeneratorutils.Paragraph("The following table image uses scale to fit.");

    document.addParagraph(para);
    document.addTable(table);

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

## Image -- setAutoScale(ブーリアン value) {#ariaid-title5}

サイズを保持して、ページまたはセルの幅と高さを拡大縮小できます。
{#Image-setAutoScale_B__table_vv5_52h_44b__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| value | ブーリアン | 画像を自動的に拡大/縮小するかどうかを示すフラグ。 有効な値： * true：画像を自動的に拡大縮小する * false：画像は拡大縮小されない {#Image-setAutoScale_B__ul_drr_bbr_s4b} デフォルト値：false |
[表 : 6. パラメーター]

{#Image-setAutoScale_B__table_vv5_52h_44b} {#Image-setAutoScale_B__table_wv5_52h_44b__entry__2}

| タイプ | 説明 |
|-|-|
| なし |   |
[表 : 7. 返される内容]

{#Image-setAutoScale_B__table_wv5_52h_44b}  
次の例は、自動的に拡大縮小して PDF に画像を追加する方法を示しています。画像を追加する際は [Table -- addImageCell()](https://www.servicenow.com/docs/Tq1VCId8LFSSL8ibkjrd~A#Table-addImageCell_O "画像を含むセルをテーブルに追加します。") メソッドを使用します。

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

    // Add a table
    var table = new sn_pdfgeneratorutils.Table([1,2],false);

    // Text in left column
    var text = "sample image";

    // Image in right column
    var autoScaledPic = new sn_pdfgeneratorutils.Image("<image_sys_id>");
    autoScaledPic.setAutoScale(true);

    table.addTextCell(text);
    table.addImageCell(autoScaledPic);

    document.addTable(table);
    document.saveAsAttachment("incident", "<record_sys_id>", "imgAutoScale.pdf");

## Image -- setColoredBorder(色 color, 数字 width) {#ariaid-title6}

指定された色で PDF に境界線を設定します。
{#Image-setColoredBorder_O_N__table_vv5_52h_44b__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| color | [色](https://www.servicenow.com/docs/5ziHyJThRZ~YBMye1Ixwpw#ColorBothAPI "PDF の要素に適用できるセル、テーブル、行などの色属性を定義するために使用する Color オブジェクトを作成します。") | 画像の境界線の色。 |
| width | 数字 | 境界線の幅 (単位：ポイント)。 |
[表 : 8. パラメーター]

{#Image-setColoredBorder_O_N__table_vv5_52h_44b} {#Image-setColoredBorder_O_N__table_wv5_52h_44b__entry__2}

| タイプ | 説明 |
|-|-|
| なし |   |
[表 : 9. 返される内容]

{#Image-setColoredBorder_O_N__table_wv5_52h_44b}  
次の例は、画像に赤色の境界線を 5 ポイントの幅で設定する方法を示しています。

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

    var borderColor = new sn_pdfgeneratorutils.Color([1.0,0.0,0.0]);
     
    // declare image using sys attachment
    var image = new sn_pdfgeneratorutils.Image("<imgAttachment_sys_id>");

    image.setColoredBorder(borderColor, 5);

    document.addImage(image);
    document.saveAsAttachment("incident", "<record_sys_id>", "docWithBorderedImage.pdf");

## Image -- setHorizontalAlignment(文字列 alignment) {#ariaid-title7}

画像の水平配置を設定します。
{#Image-setHorizontalAlignment_S__table_vv5_52h_44b__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| alignment | 文字列 | ページまたはブロック要素に画像の位置調整を配置します。 有効な値： * 中心 * 左 * 右 {#Image-setHorizontalAlignment_S__ul_rn3_wvq_s4b} デフォルト：左 |
[表 : 10. パラメーター]

{#Image-setHorizontalAlignment_S__table_vv5_52h_44b} {#Image-setHorizontalAlignment_S__table_wv5_52h_44b__entry__2}

| タイプ | 説明 |
|-|-|
| なし |   |
[表 : 11. 返される内容]

{#Image-setHorizontalAlignment_S__table_wv5_52h_44b}  
次の例は、PDF ページに中央揃えの画像を追加する方法を示しています。

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

    String alignment = "Center";
    image.setHorizontalAlignment(alignment);

    document.addImage(image);
    // save pdf as attachment to target record in the Incident table
    document.saveAsAttachment("incident", "<sys_id>", "docWithImageCentered.pdf");

## Image -- setNoBorder() {#ariaid-title8}

境界線なしで画像を設定します。
{#Image-setNoBorder__table_vv5_52h_44b__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| なし |   |   |
[表 : 12. パラメーター]

{#Image-setNoBorder__table_vv5_52h_44b} {#Image-setNoBorder__table_wv5_52h_44b__entry__2}

| タイプ | 説明 |
|-|-|
| なし |   |
[表 : 13. 返される内容]

{#Image-setNoBorder__table_wv5_52h_44b}  
次の例は、ドキュメントに境界線なしの画像を追加する方法を示しています。

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

    image.setNoBorder();

    document.addImage(image);
    document.saveAsAttachment("incident", "<sys_id>", "docWithImgNoBorder.pdf");


