IronPDF dla Java - Tworzenie, Edycja i Odczyt PDF w Aplikacjach Java
O IronPDF dla Java
IronPDF dla Java to biblioteka opracowana i utrzymywana przez Iron Software, która pomaga inżynierom oprogramowania tworzyć, edytować i wydobywać treść PDF w projektach Java 8+, Kotlin i Scala.
IronPDF for Java opiera się na sukcesie i popularności IronPDF for .NET.
IronPDF for Java wykorzystuje gRPC do komunikacji z IronPdfEngine.
IronPDF wyróżnia się w
- Generowaniu PDF z: HTML, URL, JavaScript, CSS i wielu formatów obrazów
- Dodawaniu nagłówków/stopek, podpisów, załączników, haseł i zabezpieczeń
- Optymalizacji wydajności: Pełne wsparcie dla Multithreading i Async
- Oraz wiele innych! Odwiedź naszą stronę internetową, aby zobaczyć wszystkie przykłady kodu i pełną listę naszych 50+ funkcji
Korzystanie z IronPDF dla Java
Zdefiniuj IronPDF jako zależność Java
Zależność pom.xml
Aby zdefiniować IronPDF jako zależność, dodaj następujący fragment do pliku pom.xml:
<dependencies>
<dependency>
<groupId>com.ironsoftware</groupId>
<artifactId>ironpdf</artifactId>
<version>20xx.xx.xxxx</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.3</version>
</dependency>
</dependencies>
<dependencies>
<dependency>
<groupId>com.ironsoftware</groupId>
<artifactId>ironpdf</artifactId>
<version>20xx.xx.xxxx</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.3</version>
</dependency>
</dependencies>
Pobierz plik jar
Opcjonalnie pobierz ręcznie plik JAR IronPDF do użytku samodzielnego.
Pierwsza kompilacja i uruchomienie
Pliki binarne IronPdfEngine zostaną automatycznie pobrane podczas pierwszego uruchomienia projektu. Proces IronPdfEngine rozpocznie się po pierwszym wywołaniu dowolnej funkcji IronPDF i zakończy się po zamknięciu aplikacji lub przejściu do stanu bezczynności.
Zainstaluj IronPDF Engine jako zależność Maven
Dodając IronPdfEngine jako zależność Maven, binaria zostaną pobrane podczas ładowania zależności:
- Podejście to uniknie długiego procesu startowego, ponieważ binaria IronPdfEngine będą już pobrane.
- Ponadto będzie to korzystne dla konfiguracji wdrożeń, które nie pozwalają na pobieranie z zewnętrznych źródeł.
Po prostu dodaj jeden lub kilka z poniższych fragmentów kodu do swojego pliku pom.xml, jeśli pracujesz nad aplikacją multiplatformową:
Dla 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>
Dla 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>
Dla 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>
Na 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>
Na 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>
Rozpocznij pisanie kodu Java
Po zdefiniowaniu zależności można rozpocząć pracę, dodając instrukcję import com.ironsoftware.ironpdf.* na początku kodu Java. Oto prosty przykład, jak rozpocząć pracę: HTML do 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"));
Oto kolejny prosty przykład, który pokazuje URL do 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"));
Pełen przykład 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"));
}
}
Dalsze informacje o ustawieniach
Uwaga: Pamiętaj, że wszystkie ustawienia, logowanie i operacje licencyjne muszą być wykonane przed wywołaniem jakiejkolwiek metody IronPDF.
Stosowanie klucza licencyjnego
Aby zastosować klucz licencyjny, dodaj poniższe na początku swojej metody:
com.ironsoftware.ironpdf.License.setLicenseKey("YOUR-LICENSE-KEY");
com.ironsoftware.ironpdf.License.setLicenseKey("YOUR-LICENSE-KEY");
Logowanie
IronPDF Java używa rejestratora slf4j do celu logowania. Aby włączyć logowanie, użyj:
com.ironsoftware.ironpdf.Settings.setDebug(true);
com.ironsoftware.ironpdf.Settings.setDebug(true);
Aby określić ścieżkę logu IronPdfEngine, dodaj:
com.ironsoftware.ironpdf.Settings.setLogPath(Paths.get("C:/tmp/myIronPdfEngineLog.log"));
com.ironsoftware.ironpdf.Settings.setLogPath(Paths.get("C:/tmp/myIronPdfEngineLog.log"));
Licencjonowanie i wsparcie dostępne
Kup licencję IronPDF, aby używać w żywych projektach. 30-dniowe licencje próbne są również dostępne dla użytkowników próbnych.
Aby uzyskać pełną listę przykładów kodu, samouczków, informacji o licencjach i dokumentacji, odwiedź: Zasoby IronPDF dla Java.
Aby uzyskać więcej wsparcia i zapytań, prosimy skontaktuj się z naszym zespołem wsparcia.


