マニュアル キャンセル

cfhtmltopdf

 

<cfhtmltopdf> は、PDF サービスマネージャーを使用して、CFML および HTML を含んだテキストブロックから高品質の PDF 出力を作成します。

<cfhtmltopdf> の WebKit 実装は PDFG(PDF Generator の略)と呼ばれます。PDFG は Jetty インストーラーに付属しています。Jetty サーバー内部で実行されるこのコンポーネントはサービスマネージャーと呼ばれ、1 つまたは複数の ColdFusion サーバーから PDF 変換リクエストを受け取ります。

<cfhtmltopdf> の WebKit 実装の役割は次のとおりです。

  • PDF 変換ライブラリをカプセル化します。
  • プロセス内で HTML から PDF への変換を実行します。

ColdFusion の機能強化された PDF エンジン(バージョン 2.0)は、HTML を規格に準拠した高品質な PDF に変換するための強力なツールです。HTML5、CSS3、JavaScript に対応しているので、開発者は複雑なレイアウトやデザインを簡単に作成できます。このエンジンは、標準的な HTML 使用の域を超えた追加のコーディングを必要とせずに、プロフェッショナルな外観の PDF ドキュメントを生成する場合に、特に役立ちます。

詳しくは、ColdFusion の機能強化された PDF 2.0 を参照してください。 

注意:

PDFg サービスの更新

適用対象:

  • ColdFusion(2025 リリース)
  • ColdFusion(2025 リリース)アップデート 1 以降
  • ColdFusion 2023 アップデート 13 以降
  • ColdFusion 2021 アップデート 19 以降

ColdFusion の 2025 リリースでは、Jetty 側での IP ベースのフィルタリングを導入しました。start.ini ファイルで ipaccess モジュールが有効になっています。これを実装するには、jetty-ipaccess.xml ファイルを Jetty サーバーの etc フォルダーに追加します。このファイルには、「white」と「black」の2つのセクションが含まれています。「white」セクションでは、アクセスが許可される IP アドレスを指定し、「black」セクションでは、ブロックされる IP アドレスをリストします。

既存のコードベースに IP フィルタリングを実装することが重要です。実装しない場合は、意図したとおりに機能しない可能性があります。

jetty-ipaccess.xml の例を次に示します。

<?xml version=&quot;1.0&quot;?>
<!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;http://www.eclipse.org/jetty/configure_9_3.dtd&quot;>
<!-- =============================================================== -->
<!-- The IP Access Handler -->
<!-- =============================================================== -->
<Configure id=&quot;Server&quot; class=&quot;org.eclipse.jetty.server.Server&quot;>
<Call name=&quot;insertHandler&quot;>
<Arg>
<New id=&quot;IPAccessHandler&quot; class=&quot;org.eclipse.jetty.server.handler.IPAccessHandler&quot;>
<Set name=&quot;white&quot;>
<Array type=&quot;String&quot;>
<Item>70.120.50.81</Item>
<Item>70.120.50.82</Item>
<Item>70.120.50.83</Item>
</Array>
</Set>
<Set name=&quot;black&quot;>
<Array type=&quot;String&quot;>
<Item>70.120.50.12</Item>
<Item>70.120.50.13</Item>
<Item>70.120.50.14</Item>
</Array>
</Set>
<Set name=&quot;whiteListByPath&quot;>false</Set>
</New>
</Arg>
</Call>
</Configure>
<?xml version=&quot;1.0&quot;?> <!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;http://www.eclipse.org/jetty/configure_9_3.dtd&quot;> <!-- =============================================================== --> <!-- The IP Access Handler --> <!-- =============================================================== --> <Configure id=&quot;Server&quot; class=&quot;org.eclipse.jetty.server.Server&quot;> <Call name=&quot;insertHandler&quot;> <Arg> <New id=&quot;IPAccessHandler&quot; class=&quot;org.eclipse.jetty.server.handler.IPAccessHandler&quot;> <Set name=&quot;white&quot;> <Array type=&quot;String&quot;> <Item>70.120.50.81</Item> <Item>70.120.50.82</Item> <Item>70.120.50.83</Item> </Array> </Set> <Set name=&quot;black&quot;> <Array type=&quot;String&quot;> <Item>70.120.50.12</Item> <Item>70.120.50.13</Item> <Item>70.120.50.14</Item> </Array> </Set> <Set name=&quot;whiteListByPath&quot;>false</Set> </New> </Arg> </Call> </Configure>
<?xml version=&quot;1.0&quot;?>
<!DOCTYPE Configure PUBLIC &quot;-//Jetty//Configure//EN&quot; &quot;http://www.eclipse.org/jetty/configure_9_3.dtd&quot;>
<!-- =============================================================== -->
<!-- The IP Access Handler                                           -->
<!-- =============================================================== -->
<Configure id=&quot;Server&quot; class=&quot;org.eclipse.jetty.server.Server&quot;>
   <Call name=&quot;insertHandler&quot;>
       <Arg>
           <New id=&quot;IPAccessHandler&quot; class=&quot;org.eclipse.jetty.server.handler.IPAccessHandler&quot;>
               <Set name=&quot;white&quot;>
                   <Array type=&quot;String&quot;>
                       <Item>70.120.50.81</Item>
                       <Item>70.120.50.82</Item>
                       <Item>70.120.50.83</Item>
                   </Array>
               </Set>
               <Set name=&quot;black&quot;>
                   <Array type=&quot;String&quot;>
                       <Item>70.120.50.12</Item>
                       <Item>70.120.50.13</Item>
                       <Item>70.120.50.14</Item>
                   </Array>
               </Set>
               <Set name=&quot;whiteListByPath&quot;>false</Set>
           </New>
       </Arg>
   </Call>
</Configure>

各 <Item> は ColdFusion サーバーの IP アドレスを表します。


HTML または CFML を使用して PDF を生成するときは、XSS の脆弱性が悪用されることのないようにする必要があります。このため、この脆弱性からシステムを保護するための対策は必須です。また、ColdFusion には XSS からの保護を実現するエンコーディング関数が用意されています。以下の関数のページを参照してください。

カテゴリ

データ出力タグ

履歴

  • ColdFusion(2025 リリース):cfhtmltopdf タグは PDF フォームの事前入力をサポートしていますが、プレビューエクスペリエンスはブラウザーによって異なる可能性があります。Adobe Acrobat と Firefox の組み合わせでは、事前入力されたフォームが想定どおりに処理されますが、Google Chrome や Microsoft Edge では違いが見られる場合があります。このような食い違いが発生するのは、Chrome や Edge で使用されているカスタム PDF ビューアーが、PDF フォーム内の特定の動的機能や JavaScript のやり取りを完全にはサポートしていない可能性があるからです。
  • ColdFusion(2016 リリース)アップデート 3:language 属性が追加されました。

関連項目

cfhtmltopdfitemcfdocumentcfdocumentitem

シンタックス

<cfhtmltopdf>

encryption = "AES_128|RC4_40|RC4_128|RC4_128M|None"
source = "URL|web ルートに対する絶対パス名または相対パス名"
destination = "ファイル名"

conformance="PDF 2.0 では、PDF/A-1a または PDF/A-3a 準拠のファイルおよびその他の PDF/A サブ形式のファイルの作成をサポートしています。"
language="言語名"
marginBottom = "数値"
marginLeft = "数値"
marginRight = "数値"
marginTop = "数値"
name = "出力変数名""
orientation = "portrait|landscape"
overwrite = "yes|no"
ownerPassword = "パスワード"
pageHeight = "ページの高さ(デフォルトはインチ単位)"
pageType = "ページの種類"
pageWidth = "ページの幅(デフォルトはインチ単位)"
permissions = "権限リスト"
saveAsName = "PDF ファイル名"
unit = "in|cm"
userPassword = "パスワード"

HTML および CFML コード

</cfhtmltopdf>

属性

属性

必須/オプション

デフォルト

説明

encryption

オプション

none

AES_128

RC4_40

RC4_128

RC4_128M

None

source

必須

 

ソース HTML ドキュメントの URLColdFusion 11 では、HTTP URL は、HTTPS URL に自動的にリダイレクトされます。ColdFusion 2016 では、HTTP から HTTPS への自動リダイレクトは行われないので、手動で HTTPS URL を入力します。

conformance オプション   サポートされている PDF/A 準拠レベルは、PDF/A-1a、PDF/A-1b、PDF/A-2a、PDF/A-2b、PDF/A-2u、PDF/A-3a、PDF/A-3b および PDF/A-3u です。詳しくは、ColdFusion の機能強化された PDF 2.0 を参照してください。

destination

オプション

 

PDF 形式の出力を保存するファイルのパス名です。destination 属性を省略すると、出力はブラウザーに表示されます。

language

オプション

英語

ドキュメントの言語。

marginBottom

オプション

 

ページの下マージンをインチ(デフォルト)またはセンチメートル単位で指定します。下マージンをセンチメートル単位で指定するには、unit=cm 属性を使用します。

marginLeft

オプション

 

ページの左マージンをインチ(デフォルト)またはセンチメートル単位で指定します。左マージンをセンチメートル単位で指定するには、unit=cm 属性を使用します。

marginRight

オプション

 

ページの右マージンをインチ(デフォルト)またはセンチメートル単位で指定します。右マージンをセンチメートル単位で指定するには、unit=cm 属性を使用します。

marginTop

オプション

 

ページの上マージンをインチ(デフォルト)またはセンチメートル単位で指定します。上マージンをセンチメートル単位で指定するには、unit=cm 属性を使用します。

name

オプション

 

PDF を格納する既存の変数の名前です。

orientation

オプション

portrait

ページの向き:

portrait

landscape

overwrite

オプション

no

既存のファイルを上書きするかどうかを指定します。destination 属性とともに使用します。

ownerPassword

オプション

 

オーナーパスワードを指定します。userPassword と同じものにはできません。

pageHeight

オプション

 

ページの高さをインチ(デフォルト)またはセンチメートル単位で指定します。この属性は、pagetype=custom の場合にのみ有効です。ページの高さをセンチメートル単位で指定するには、unit=cm 属性を使用します。

pageType

オプション

letter

ColdFusion で生成するレポートのページタイプです。

 

legal:8.5 インチ × 14 インチ

letter:8.5 インチ × 11 インチ

A4:8.27 インチ × 11.69 インチ

A5:5.81 インチ × 8.25 インチ

B4:9.88 インチ × 13.88 インチ

B5:7 インチ × 9.88 インチ

B4-JIS:10.13 インチ × 14.31 インチ

B5-JIS:7.19 インチ × 10.13 インチ

custom:カスタムの高さと幅

custom を指定する場合は、pageHeight 属性と pageWidth 属性も指定します。必要に応じて、margin に関する属性の指定や、単位をインチまたはセンチメートルのいずれにするかの指定もできます。

pageWidth

オプション

 

ページの幅をインチ(デフォルト)またはセンチメートル単位で指定します。この属性は、pageType=custom の場合にのみ有効です。ページの幅をセンチメートル単位で指定するには、unit=cm 属性を使用します。

permissions

オプション

 

(format="PDF" の場合のみ)次のいずれかの権限を設定します。

AllowPrinting

AllowModifyContents

AllowCopy

AllowModifyAnnotations

AllowFillIn

AllowScreenReaders

AllowAssembly

AllowDegradedPrinting

   AllowSecure

   All

   None

複数の権限を指定する場合は、コンマで区切ります。

saveAsName

オプション

 

ブラウザーに出力された PDF ファイルをユーザーが保存するときに名前を付けて保存ダイアログボックスに表示されるファイル名です。

unit

オプション

in

pageHeight、pageWidth、margin の各属性で使用するデフォルトの単位です。

in:インチ

cm:センチメートル

userPassword

オプション

 

ユーザーパスワードを指定します。ownerPassword と同じものにはできません。

注意:生成された PDF にヘッダー、フッターまたは改ページを挿入するための <cfhtmltopdfItem> が追加されています。  新しい <cfhtmltopdfitem> タグの説明を参照してください。

詳しくは、KB ドキュメント cfdocument と cfhtmltopdf の違いを参照してください。

制限事項:cfhtmltopdf を使用して、フォームを含んだ HTML ページを PDF に変換した場合、変換結果の PDF にはフォームフィールドが含まれていません。PDFg がサービスとして動作するように設定されている場合、これは PDFg サービスの制限事項です。コマンドラインから PDFg を実行すると、フォームフィールドは想定どおりに機能します。


次の例では、CFML コードから PDF を作成して表示用の PDF を返す場合の、<cfhtmltopdf> の最も基本的な使用法を示しています。

<cfhtmltopdf>
This is a test <cfoutput>#now()#</cfoutput>
</cfhtmltopdf>
<cfhtmltopdf> This is a test <cfoutput>#now()#</cfoutput> </cfhtmltopdf>
<cfhtmltopdf>
This is a test <cfoutput>#now()#</cfoutput>
</cfhtmltopdf>

次の例では、URL から返されたコンテンツを基に PDF を作成して表示用の PDF を返す場合の、<cfhtmltopdf> の最も基本的な使用法を示しています。

<cfhtmltopdf source=&quot;http://www.google.com/&quot; />
<cfhtmltopdf source=&quot;http://www.google.com/&quot; />
<cfhtmltopdf source=&quot;http://www.google.com/&quot; />

次の例では、オプションを使用して高さと幅を制御し、コンテンツを表示するのではなくファイルに保存する方法を示しています。ファイルはデフォルトで、コードが含まれているテンプレートと同じディレクトリに保存されます。

<cfhtmltopdf
destination=&quot;usage_example.pdf&quot; overwrite=&quot;yes&quot;
source=&quot;http://www.google.com/&quot;
unit=&quot;in&quot; pageheight=&quot;8&quot; pagewidth=&quot;4&quot;
pagetype=&quot;custom&quot; />
<cfhtmltopdf destination=&quot;usage_example.pdf&quot; overwrite=&quot;yes&quot; source=&quot;http://www.google.com/&quot; unit=&quot;in&quot; pageheight=&quot;8&quot; pagewidth=&quot;4&quot; pagetype=&quot;custom&quot; />
<cfhtmltopdf
  destination=&quot;usage_example.pdf&quot; overwrite=&quot;yes&quot;
  source=&quot;http://www.google.com/&quot;
  unit=&quot;in&quot; pageheight=&quot;8&quot; pagewidth=&quot;4&quot;
  pagetype=&quot;custom&quot; />

次の例では、マージン URL を設定する方法を示し、さらに、結果として生成されるファイルを <cfcontent> を使用してユーザーに表示するコードを追加しています。

<cfhtmltopdf destination=&quot;usage_example2.pdf&quot;
source=&quot;http://www.google.com&quot; overwrite=&quot;true&quot;
orientation=&quot;portrait&quot; pagetype=&quot;A4&quot; margintop=&quot;1&quot; marginbottom=&quot;1&quot;
marginleft=&quot;1&quot; marginright=&quot;1&quot; />
<cfcontent file=&quot;#getdirectoryfrompath(getbasetemplatepath())#usage_example2.pdf&quot; type=&quot;application/pdf&quot; >
<cfhtmltopdf destination=&quot;usage_example2.pdf&quot; source=&quot;http://www.google.com&quot; overwrite=&quot;true&quot; orientation=&quot;portrait&quot; pagetype=&quot;A4&quot; margintop=&quot;1&quot; marginbottom=&quot;1&quot; marginleft=&quot;1&quot; marginright=&quot;1&quot; /> <cfcontent file=&quot;#getdirectoryfrompath(getbasetemplatepath())#usage_example2.pdf&quot; type=&quot;application/pdf&quot; >
<cfhtmltopdf destination=&quot;usage_example2.pdf&quot;
  source=&quot;http://www.google.com&quot; overwrite=&quot;true&quot;  
  orientation=&quot;portrait&quot;  pagetype=&quot;A4&quot; margintop=&quot;1&quot; marginbottom=&quot;1&quot; 
  marginleft=&quot;1&quot; marginright=&quot;1&quot; />
 
<cfcontent file=&quot;#getdirectoryfrompath(getbasetemplatepath())#usage_example2.pdf&quot; type=&quot;application/pdf&quot; >

次の例では、ファイルを開くときにパスワードの入力をユーザーに求めることで PDF を保護する方法を示しています。

<cfhtmltopdf destination=&quot;usage_example3.pdf &quot;
source=&quot;http://www.google.com&quot; overwrite=&quot;true&quot;
orientation=&quot;portrait&quot; pagetype=&quot;A4&quot; margintop=&quot;1&quot; marginbottom=&quot;1&quot;
marginleft=&quot;1&quot; marginright=&quot;1&quot; ownerpassword=&quot;owner&quot; userpassword=&quot;user&quot;
encryption=&quot;RC4_128&quot; permissions=&quot;AllowPrinting,AllowCopy&quot; />
<cfhtmltopdf destination=&quot;usage_example3.pdf &quot; source=&quot;http://www.google.com&quot; overwrite=&quot;true&quot; orientation=&quot;portrait&quot; pagetype=&quot;A4&quot; margintop=&quot;1&quot; marginbottom=&quot;1&quot; marginleft=&quot;1&quot; marginright=&quot;1&quot; ownerpassword=&quot;owner&quot; userpassword=&quot;user&quot; encryption=&quot;RC4_128&quot; permissions=&quot;AllowPrinting,AllowCopy&quot; />
<cfhtmltopdf destination=&quot;usage_example3.pdf &quot; 
  source=&quot;http://www.google.com&quot; overwrite=&quot;true&quot;
  orientation=&quot;portrait&quot;  pagetype=&quot;A4&quot; margintop=&quot;1&quot; marginbottom=&quot;1&quot;
  marginleft=&quot;1&quot; marginright=&quot;1&quot; ownerpassword=&quot;owner&quot; userpassword=&quot;user&quot;
  encryption=&quot;RC4_128&quot; permissions=&quot;AllowPrinting,AllowCopy&quot; />

その他の関連ヘルプ

ヘルプをすばやく簡単に入手

新規ユーザーの場合