<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>
// Import statement for IronPDF Javaimport com.ironsoftware.ironpdf.*;// Apply your license keyLicense.setLicenseKey("YOUR-LICENSE-KEY");// Set a log pathSettings.setLogPath(Paths.get("C:/tmp/IronPdfEngine.log"));// Render the HTML as a PDF. Stored in myPdf as type PdfDocumentPdfDocument myPdf = PdfDocument.renderHtmlAsPdf("<h1> ~Hello World~ </h1> Made with IronPDF!");// Save the PdfDocument to a filemyPdf.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 Javaimport com.ironsoftware.ironpdf.*;// Apply your license keyLicense.setLicenseKey("YOUR-LICENSE-KEY");// Set a log pathSettings.setLogPath(Paths.get("C:/tmp/IronPdfEngine.log"));// Render the URL as a PDF. Stored in myPdf as type PdfDocumentPdfDocument myPdf = PdfDocument.renderUrlAsPdf("https://ironpdf.com/java");// Save the PdfDocument to a filemyPdf.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 Javaimport 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 keyLicense.setLicenseKey("YOUR-LICENSE-KEY"); // Set a log pathSettings.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"));
}
}