// Add IronPDF dependency to your Maven pom.xml file// Import IronPDF classesimport com.ironsoftware.ironpdf.*;// Load PDF documentPdfDocument pdf = newPdfDocument(Paths.get("MyPdf.pdf"));// Print without dialogpdf.printWithoutDialog();// Or show print dialogpdf.print();
// Add IronPDF dependency to your Maven pom.xml file
// Import IronPDF classes
import com.ironsoftware.ironpdf.*;
// Load PDF document
PdfDocument pdf = new PdfDocument(Paths.get("MyPdf.pdf"));
// Print without dialog
pdf.printWithoutDialog();
// Or show print dialog
pdf.print();
IronPDF for Java提供了一個構造函式來將PDF內容載入到程式庫中。 有效的參數包括一個位元組陣列和一個文件路徑。 對於受密碼保護的文件,可以提供包含密碼的第三個參數。
下面的程式碼片段載入了文件系統上的PDF:
// Set the license key for IronPDF// Learn more about licensing at https://ironpdf.com/java/get-started/license-keys/License.setLicenseKey("Enter-Your-License"); // Load PDF from the filesystemPdfDocument pdf = newPdfDocument(Paths.get("MyPdf.pdf"));// Alternative: Load from byte array// byte[] pdfBytes = Files.readAllBytes(Paths.get("MyPdf.pdf"));// PdfDocument pdfFromBytes = new PdfDocument(pdfBytes);// For password-protected PDFs// PdfDocument protectedPdf = new PdfDocument(Paths.get("Protected.pdf"), "password123");
// Set the license key for IronPDF
// Learn more about licensing at https://ironpdf.com/java/get-started/license-keys/
License.setLicenseKey("Enter-Your-License");
// Load PDF from the filesystem
PdfDocument pdf = new PdfDocument(Paths.get("MyPdf.pdf"));
// Alternative: Load from byte array
// byte[] pdfBytes = Files.readAllBytes(Paths.get("MyPdf.pdf"));
// PdfDocument pdfFromBytes = new PdfDocument(pdfBytes);
// For password-protected PDFs
// PdfDocument protectedPdf = new PdfDocument(Paths.get("Protected.pdf"), "password123");
// Print PDF document using default printer settings without showing a print dialog// This will immediately send the document to the default system printerpdf.printWithoutDialog();// The method returns immediately after sending the print job to the spoolerSystem.out.println("PDF document sent to default printer");
// Print PDF document using default printer settings without showing a print dialog
// This will immediately send the document to the default system printer
pdf.printWithoutDialog();
// The method returns immediately after sending the print job to the spooler
System.out.println("PDF document sent to default printer");
// Display print dialog to let the user specify printing options// This will show the system print dialog with all available printerspdf.print();// The method will wait for user interaction before proceeding// User can select printer, paper size, orientation, number of copies, etc.
// Display print dialog to let the user specify printing options
// This will show the system print dialog with all available printers
pdf.print();
// The method will wait for user interaction before proceeding
// User can select printer, paper size, orientation, number of copies, etc.
package IronPDF.ironpdf_java;// Import statement for IronPDF Javaimport com.ironsoftware.ironpdf.*;import java.awt.print.PrinterException;import java.io.IOException;import java.nio.file.Paths;public class App { public static void main(String[] args) throws PrinterException, IOException { // Apply your license key // Get your license key from https://ironpdf.com/java/get-started/license-keys/License.setLicenseKey("Enter-Your-License"); // Load PDF document from the file system PdfDocument pdf = newPdfDocument(Paths.get("MyPdf.pdf")); // Option 1: Print the PDF document without displaying a print dialog // Uses default printer and settings pdf.printWithoutDialog(); // Option 2: Display the print dialog for the user to configure printing options // Allows selection of printer, copies, page range, etc. pdf.print(); // Don't forget to close the document when done pdf.close(); }}
package IronPDF.ironpdf_java;
// Import statement for IronPDF Java
import com.ironsoftware.ironpdf.*;
import java.awt.print.PrinterException;
import java.io.IOException;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) throws PrinterException, IOException {
// Apply your license key
// Get your license key from https://ironpdf.com/java/get-started/license-keys/
License.setLicenseKey("Enter-Your-License");
// Load PDF document from the file system
PdfDocument pdf = new PdfDocument(Paths.get("MyPdf.pdf"));
// Option 1: Print the PDF document without displaying a print dialog
// Uses default printer and settings
pdf.printWithoutDialog();
// Option 2: Display the print dialog for the user to configure printing options
// Allows selection of printer, copies, page range, etc.
pdf.print();
// Don't forget to close the document when done
pdf.close();
}
}
是的,IronPDF 允許您在列印 PDF 時配置列印機設置以自定義輸出。您可以指定各種列印參數和選項來控制 PDF 文件的列印方式,以確保滿足您的特定要求。
在伺服器端 Java 應用中列印 PDF 是否可行?
是的,IronPDF 支援在伺服器端 Java 應用中列印 PDF。這在批量處理系統和需要在無需使用者交互的情況下列印 PDF 的自動文件工作流程中很常見,使其非常適合生成發票、報告和其他文件的企業應用。
支持哪些型別的列印機列印 PDF?
IronPDF 支持列印到物理列印機和虛擬列印機。這種靈活性使您能夠將 PDF 文件發送到標準辦公列印機、網路列印機或用於進一步處理的虛擬 PDF 列印機,使其適合各種業務場景和文件管理工作流程。
How can I optimize performance during PDF printing in Java applications?
For optimal performance, consider compressing large PDFs to reduce memory usage and speed up printing processes, especially for large batch operations.
Can IronPDF be used on different operating systems?
Yes, IronPDF is compatible across various operating systems like Windows, Linux, and macOS; however, printer configurations and options may vary, so it's advisable to test on the target platform.
What is the licensing model for IronPDF?
IronPDF offers a free trial for production testing, with pricing available starting from the 'liteLicense' option. You can explore their pricing page for more details.
Does IronPDF support converting HTML to PDF?
Yes, IronPDF supports converting HTML, CSS, and JavaScript code directly into PDF documents, making it easy to create PDFs from web pages or HTML templates.