JavaでPDFファイルを印刷する方法
JavaアプリケーションからプログラムによってPDFを印刷することにより、ドキュメントの処理を自動化し、印刷機能をシームレスに統合することができます。 IronPDF for Javaを使用すると、PDFを物理的なプリンターに直接送信でき、コピー数やページ範囲などの印刷設定を正確に制御できます。 このガイドでは、Javaアプリケーション内で印刷タスクを効率化するためにIronPDFの機能を使用する方法を説明します。
JavaでPDFファイルを印刷する方法
- PDFファイルを印刷するためのJavaライブラリをインストールする
- 既存のPDFを読み込むか、新しいPDFをレンダリングする
print
メソッドを使用してダイアログで印刷しますprintWithoutDialog
メソッドを使用して、ダイアログなしで印刷します。- 印刷されたPDFドキュメントを確認してください。
Print PDF
The first step is to load the PDF document you want to print. The print
method opens the standard print dialog, allowing you to select the printer, page range, and other options before printing. Here's an example:
javaimport com.ironsoftware.ironpdf.License;import com.ironsoftware.ironpdf.PdfDocument; License.setLicenseKey("IRONPDF-MYLICENSE-KEY-1EF01"); // Render HTML to PDFPdfDocument pdf = PdfDocument.renderHtmlAsPdf("<h1>テスト</h1>"); // Print with Dialogpdf.print();
You will be prompted with a print dialog to select the printer and options, as shown below.
Print PDF without the Print Dialog
The printWithoutDialog
method bypasses the print dialog and sends the document straight to the default printer. This is useful in automation scenarios where no user interaction is needed.
javaimport com.ironsoftware.ironpdf.License;import com.ironsoftware.ironpdf.PdfDocument; License.setLicenseKey("IRONPDF-MYLICENSE-KEY-1EF01"); // Render HTML to PDFPdfDocument pdf = PdfDocument.renderHtmlAsPdf("<h1>テスト</h1>"); // Print without Dialogpdf.printWithoutDialog();