IronPDF for Java - JavaアプリケーションでPDFを作成、編集、読み取り

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コンテンツを作成、編集、抽出するのに役立ちます。

Java 用 IronPDF は、.NET 用 IronPDF の成功と人気に基づいています。

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

IronPDF(IronPDF)は優れています

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

Java向けIronPDFの使用

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

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エンジンをインストールする

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

  • このアプローチにより、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 シリコン)

<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コードの記述を開始

依存関係が定義されたら、Javaコードの先頭にimport com.ironsoftware.ironpdf.*ステートメントを追加して開始できます。 以下に、簡単な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"));

PdfDocument pdfDocument = PdfDocument.renderUrlAsPdf("https://ironpdf.com/java");
// 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"));

PdfDocument pdfDocument = PdfDocument.renderUrlAsPdf("https://ironpdf.com/java");
JAVA

Full Main.java Example

完全な 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 loggerを使用します。 ロギングを有効にするには

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 resourcesをご覧ください。

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