IronPDF for Java - Create, Edit, and Read PDFs in Java Applications

This article was translated from English: Does it need improvement?
Translated
View the article in English

IronPDF for Javaについて

IronPDF for Javaは、Iron Softwareによって開発および維持されているライブラリで、ソフトウェアエンジニアがJava 8+、Kotlin、ScalaプロジェクトでPDFコンテンツを作成、編集、および抽出するのを助けます。

IronPDF for JavaIronPDF for .NETの成功と人気を基に構築されています。

IronPDF for JavaはIronPdfEngineと通信するためにgRPCを使用します。

IronPDFの得意分野

  • HTML、URL、JavaScript、CSS、および多くの画像フォーマットからPDFを生成
  • ヘッダー/フッター、署名、添付ファイル、パスワードおよびセキュリティの追加
  • パフォーマンス最適化: フルマルチスレッドおよび非同期サポート
  • その他多数! すべてのコード例と50以上の機能の完全なリストを表示するには、当社のウェブサイトをご覧ください。

IronPDF for Javaの使用

IronPDFをJavaの依存関係として定義

pom.xml 依存関係

IronPDFを依存関係として定義するには、以下をpom.xmlに追加してください:

<dependencies>

    <!-- Adds IronPDF Java. Use the latest version in the version tag. -->
    <dependency>
        <groupId>com.ironsoftware</groupId>
        <artifactId>ironpdf</artifactId>
        <version>20xx.xx.xxxx</version>
    </dependency>

    <!-- Adds the slf4j logger which IronPDF Java uses. -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>2.0.3</version>
    </dependency>

</dependencies>
<dependencies>

    <!-- Adds IronPDF Java. Use the latest version in the version tag. -->
    <dependency>
        <groupId>com.ironsoftware</groupId>
        <artifactId>ironpdf</artifactId>
        <version>20xx.xx.xxxx</version>
    </dependency>

    <!-- Adds the slf4j logger which IronPDF Java uses. -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>2.0.3</version>
    </dependency>

</dependencies>
XML

jarファイルのダウンロード

オプションでIronPDF JARファイルを手動でダウンロードしてスタンドアロンで使用することができます。

初回ビルドと実行

IronPdfEngineのバイナリは、プロジェクトの初回実行時に自動的にダウンロードされます。最初にIronPdf関数を呼び出すとIronPdfEngineプロセスが開始し、アプリケーションが終了するかアイドル状態に入ると停止します。

Maven依存関係としてIronPDFエンジンをインストール

IronPdfEngineをMaven依存関係として追加することで、依存関係の読み込み中にバイナリがダウンロードされます:

  • このアプローチにより、IronPdfEngineのバイナリがすでにダウンロードされているため、長いスタートアッププロセスを避けることができます。
  • さらに、外部ソースからのダウンロードを許可しないデプロイメント設定にも有益です。

マルチプラットフォームアプリで作業している場合は、単純に以下のいずれかまたは複数のコードスニペットをpom.xmlファイルに追加してください:

Windows x64用

<dependency>
    <groupId>com.ironsoftware</groupId>
    <artifactId>ironpdf-engine-windows-x64</artifactId>
    <version>20xx.xx.xxxx</version>
</dependency>
<dependency>
    <groupId>com.ironsoftware</groupId>
    <artifactId>ironpdf-engine-windows-x64</artifactId>
    <version>20xx.xx.xxxx</version>
</dependency>
XML

Windows x86用

<dependency>
    <groupId>com.ironsoftware</groupId>
    <artifactId>ironpdf-engine-windows-x86</artifactId>
    <version>20xx.xx.xxxx</version>
</dependency>
<dependency>
    <groupId>com.ironsoftware</groupId>
    <artifactId>ironpdf-engine-windows-x86</artifactId>
    <version>20xx.xx.xxxx</version>
</dependency>
XML

Linux x64用

<dependency>
    <groupId>com.ironsoftware</groupId>
    <artifactId>ironpdf-engine-linux-x64</artifactId>
    <version>20xx.xx.xxxx</version>
</dependency>
<dependency>
    <groupId>com.ironsoftware</groupId>
    <artifactId>ironpdf-engine-linux-x64</artifactId>
    <version>20xx.xx.xxxx</version>
</dependency>
XML

macOS x64 (Intel)用

<dependency>
    <groupId>com.ironsoftware</groupId>
    <artifactId>ironpdf-engine-macos-x64</artifactId>
    <version>20xx.xx.xxxx</version>
</dependency>
<dependency>
    <groupId>com.ironsoftware</groupId>
    <artifactId>ironpdf-engine-macos-x64</artifactId>
    <version>20xx.xx.xxxx</version>
</dependency>
XML

macOS Arm (Apple Silicon)用

<dependency>
    <groupId>com.ironsoftware</groupId>
    <artifactId>ironpdf-engine-macos-arm64</artifactId>
    <version>20xx.xx.xxxx</version>
</dependency>
<dependency>
    <groupId>com.ironsoftware</groupId>
    <artifactId>ironpdf-engine-macos-arm64</artifactId>
    <version>20xx.xx.xxxx</version>
</dependency>
XML

Javaコードの書き始め

依存関係が定義されると、import com.ironsoftware.ironpdf.*ステートメントをJavaコードの冒頭に追加することで始められます。 始めるための簡単なHTMLからPDFへのサンプルはこちらです:

// Import statement for IronPDF Java
import com.ironsoftware.ironpdf.*;

// Apply your license key
License.setLicenseKey("YOUR-LICENSE-KEY");

// Set a log path
Settings.setLogPath(Paths.get("C:/tmp/IronPdfEngine.log"));

// Render the HTML as a PDF. Stored in myPdf as type PdfDocument
PdfDocument myPdf = PdfDocument.renderHtmlAsPdf("<h1> ~Hello World~ </h1> Made with IronPDF!");

// Save the PdfDocument to a file
myPdf.saveAs(Paths.get("html_saved.pdf"));
// Import statement for IronPDF Java
import com.ironsoftware.ironpdf.*;

// Apply your license key
License.setLicenseKey("YOUR-LICENSE-KEY");

// Set a log path
Settings.setLogPath(Paths.get("C:/tmp/IronPdfEngine.log"));

// Render the HTML as a PDF. Stored in myPdf as type PdfDocument
PdfDocument myPdf = PdfDocument.renderHtmlAsPdf("<h1> ~Hello World~ </h1> Made with IronPDF!");

// Save the PdfDocument to a file
myPdf.saveAs(Paths.get("html_saved.pdf"));
JAVA

これは、URLからPDFへの別の簡単な例です:

// Import statement for IronPDF Java
import com.ironsoftware.ironpdf.*;

// Apply your license key
License.setLicenseKey("YOUR-LICENSE-KEY");

// Set a log path
Settings.setLogPath(Paths.get("C:/tmp/IronPdfEngine.log"));

// Render the URL as a PDF. Stored in myPdf as type PdfDocument
PdfDocument myPdf = PdfDocument.renderUrlAsPdf("https://ironpdf.com/java");

// Save the PdfDocument to a file
myPdf.saveAs(Paths.get("url_saved.pdf"));
// Import statement for IronPDF Java
import com.ironsoftware.ironpdf.*;

// Apply your license key
License.setLicenseKey("YOUR-LICENSE-KEY");

// Set a log path
Settings.setLogPath(Paths.get("C:/tmp/IronPdfEngine.log"));

// Render the URL as a PDF. Stored in myPdf as type PdfDocument
PdfDocument myPdf = PdfDocument.renderUrlAsPdf("https://ironpdf.com/java");

// Save the PdfDocument to a file
myPdf.saveAs(Paths.get("url_saved.pdf"));
JAVA

完全なMain.java例

package org.example;

// Import statement for IronPDF Java
import com.ironsoftware.ironpdf.*;
import java.io.IOException;
import java.nio.file.Paths;

public class Main {

    public static void main(String[] args) throws IOException {
        // Apply your license key
        License.setLicenseKey("YOUR-LICENSE-KEY");

        // Set a log path
        Settings.setLogPath(Paths.get("C:/tmp/IronPdfEngine.log"));

        // Render the HTML as a PDF. Stored in myPdf as type PdfDocument
        PdfDocument myPdf = PdfDocument.renderHtmlAsPdf("<h1> ~Hello World~ </h1> Made with IronPDF!");

        // Save the PdfDocument to a file
        myPdf.saveAs(Paths.get("html_saved.pdf"));

    }

}
package org.example;

// Import statement for IronPDF Java
import com.ironsoftware.ironpdf.*;
import java.io.IOException;
import java.nio.file.Paths;

public class Main {

    public static void main(String[] args) throws IOException {
        // Apply your license key
        License.setLicenseKey("YOUR-LICENSE-KEY");

        // Set a log path
        Settings.setLogPath(Paths.get("C:/tmp/IronPdfEngine.log"));

        // Render the HTML as a PDF. Stored in myPdf as type PdfDocument
        PdfDocument myPdf = PdfDocument.renderHtmlAsPdf("<h1> ~Hello World~ </h1> Made with IronPDF!");

        // Save the PdfDocument to a file
        myPdf.saveAs(Paths.get("html_saved.pdf"));

    }

}
JAVA

さらなる設定情報

注意:すべての設定、ログ、およびライセンス操作は、任意のIronPDFメソッドが呼び出される前に実行される必要があることに注意してください。

ライセンスキーの適用

ライセンスキーを適用するには、以下をメソッドの冒頭に追加してください。

com.ironsoftware.ironpdf.License.setLicenseKey("YOUR-LICENSE-KEY");
com.ironsoftware.ironpdf.License.setLicenseKey("YOUR-LICENSE-KEY");
JAVA

ロギング

IronPDF Javaは、ロギング目的でslf4jロガーを使用します。 ロギングを有効にするには、次を使用します:

com.ironsoftware.ironpdf.Settings.setDebug(true);
com.ironsoftware.ironpdf.Settings.setDebug(true);
JAVA

IronPdfEngineのログパスを指定するには、次を追加してください:

com.ironsoftware.ironpdf.Settings.setLogPath(Paths.get("C:/tmp/myIronPdfEngineLog.log"));
com.ironsoftware.ironpdf.Settings.setLogPath(Paths.get("C:/tmp/myIronPdfEngineLog.log"));
JAVA

ライセンスとサポートの提供

ライブプロジェクトで使用するためにIronPDFのライセンスを購入する。 30日間のトライアルライセンスもトライアルユーザー向けに利用可能です

完全なコード例、チュートリアル、ライセンス情報、ドキュメントについては、IronPDF for Javaリソースを訪問してください。

さらなるサポートとお問い合わせには、サポートチームに連絡してください

Darrius Serrant
フルスタックソフトウェアエンジニア(WebOps)

Darrius Serrantは、マイアミ大学でコンピュータサイエンスの学士号を取得し、Iron SoftwareでフルスタックWebOpsマーケティングエンジニアとして働いています。若い頃からコーディングに惹かれ、コンピューティングを神秘的かつアクセス可能なものとし、創造性と問題解決のための完璧な媒体と考えていました。

Iron Softwareでは、新しいものを創造することと、複雑なコンセプトをより理解しやすくすることを楽しんでいます。Resident Developerの一人として、次世代に専門知識を共有するために、学生を教えることにも志願しました。

Darriusにとって、その仕事は価値があり、実際の影響があるため、満足感があります。

準備はいいですか?
バージョン: 2025.11 ただ今リリースされました