HTMLファイルをPDFに

Convert an entire HTML file into a pixel-perfect PDF with IronPDF for Python’s RenderHtmlFileAsPdf method.

開始方法

To convert an HTML file to PDF, you can use the RenderHtmlFileAsPdf method. This method requires only the path to the local HTML file and returns a PdfDocument object. このオブジェクトには、Webブラウザで表示されるようにレンダリングされたHTMLファイルの内容が含まれています。 レンダリングの問題を避けるためには、有効なマークアップを含めることを確認してください。

以下に、このメソッドの簡単な使用例を示します:

コードの理解

  • ChromePdfRenderer: このオブジェクトはレンダリングプロセスとのインタラクションのポイントとして機能します。 ヘッダー、フッターなどのプロパティを設定してPDF出力を調整できます。

  • ChromePdfRenderer: This method takes a path to an HTML file and converts it into a PdfDocument. 生成されたPDFは、Webブラウザで表示されるHTMLファイルに非常に近くなります。

  • save_as: This method saves the newly created PDF document to the specified path on your file system.

PDF出力のカスタマイズ

ChromePdfRenderer comes with various options for customization, including setting headers, footers, margins, backgrounds, page numbers, etc. For more advanced features and customization, see this code example and learn how to customize PDF output.

このチュートリアルでHTMLをPDFに変換する方法を学んでください!

準備はできましたか?
Version: 2025.9 リリース