자바로 PDF 파일을 만드는 방법
Java에서 PDF 파일을 생성하는 것은 비즈니스 응용 프로그램에서 일반적인 요구 사항입니다: 수요에 따라 송장 및 보고서 생성, 증명서, 영수증 및 감사 로그 생성. IronPDF for Java는 전체 Chromium 렌더링 엔진을 사용하여 HTML을 PDF로 변환하므로, HTML5, CSS3, JavaScript 콘텐츠가 형식 손실 없이 충실하게 렌더링됩니다.
이 가이드는 HTML 문자열부터, 로컬 HTML 파일에서, 그리고 라이브 URL에서 PDF를 생성하는 세 가지 방법을 설명합니다. 또한 페이지 포맷팅, 비밀번호 보호, Spring Boot 통합도 설명합니다.
빠른 시작: Java에서 HTML로 PDF 만들기
pom.xml에 IronPDF를 추가하세요:
//:path=/static-assets/pdf/content-code-examples/how-to/java-create-pdf-tutorial/maven-dependency.xml
<dependency>
<groupId>com.ironsoftware</groupId>
<artifactId>ironpdf</artifactId>
<version>2024.9.1</version>
</dependency>
//:path=/static-assets/pdf/content-code-examples/how-to/java-create-pdf-tutorial/maven-dependency.xml
<dependency>
<groupId>com.ironsoftware</groupId>
<artifactId>ironpdf</artifactId>
<version>2024.9.1</version>
</dependency>
- 라이브러리를 가져오고 PDF를 생성하세요:
//:path=/static-assets/pdf/content-code-examples/how-to/java-create-pdf-tutorial/quickstart.java
import com.ironsoftware.ironpdf.*;
import java.nio.file.Paths;
// Set your license key (remove watermarks in production)
License.setLicenseKey("Your-License-Key");
// Convert HTML string to PDF and save
PdfDocument pdf = PdfDocument.renderHtmlAsPdf("<h1>Hello, IronPDF!</h1>");
pdf.saveAs(Paths.get("output.pdf"));
//:path=/static-assets/pdf/content-code-examples/how-to/java-create-pdf-tutorial/quickstart.java
import com.ironsoftware.ironpdf.*;
import java.nio.file.Paths;
// Set your license key (remove watermarks in production)
License.setLicenseKey("Your-License-Key");
// Convert HTML string to PDF and save
PdfDocument pdf = PdfDocument.renderHtmlAsPdf("<h1>Hello, IronPDF!</h1>");
pdf.saveAs(Paths.get("output.pdf"));
Java에서 PDF 파일을 만드는 방법
- Maven 또는 Gradle을 통해 IronPDF Java 라이브러리 설치
- 라이브러리를 가져오고 라이센스 키를 설정하세요
com.ironsoftware.ironpdf.* - PDF를 메모리에서 생성하기 위해 HTML 문자열과 함께
PdfDocument.renderHtmlAsPdf()를 호출하세요 - 로컬 HTML 파일을 PDF로 변환하기 위해
PdfDocument.renderHtmlFileAsPdf()를 사용하세요 - 완성된 문서를 디스크에 저장하려면
pdf.saveAs()를 호출하세요
IronPDF for Java는 무엇이며 왜 사용해야 하나요?
IronPDF for Java는 Chromium 렌더링 엔진에 구축된 PDF 생성 및 조작 라이브러리입니다. Chrome과 정확히 동일하게 HTML을 렌더링하기 때문에 복잡한 레이아웃, 사용자 지정 글꼴, CSS 애니메이션, JavaScript 생성 콘텐츠, 포함된 이미지를 수동 레이아웃 코드 없이 처리합니다.
라이브러리는 단일 종속성으로 전체 PDF 수명을 다룹니다. 개발자는 처음부터 문서를 생성하고, 기존 HTML 콘텐츠를 변환하고, 파일을 병합 또는 분할하고, 워터마크를 추가하고, 비밀번호로 암호화하고, 텍스트와 이미지를 추출하고, 작성 가능한 양식을 생성할 수 있으며, 모든 것이 일관된 API를 통해 가능합니다. HTML 중심의 워크플로우의 경우, IronPDF는 Apache PDFBox와 같은 저수준 PDF 라이브러리에서 필요한 수동 페이지 레이아웃 계산을 피합니다.
대부분의 상업적 사용을 위해 AGPL 오픈소스 라이센스가 필요한 iText와 달리, IronPDF는 상업적으로 친숙한 라이센스를 제공하며 복잡한 라이센스 준수 검토가 필요 없습니다. IronPDF for Java는 Maven 아티팩트로 제공되며 Windows, Linux 및 macOS에서 작동합니다. Spring Boot, Jakarta EE 및 독립 실행형 Java 애플리케이션과 통합됩니다. 이 라이브러리는 AWS, Azure, Google Cloud에서 서버 배포를 지원합니다.
Java에서 IronPDF를 사용하기 위한 필수 구성 요소는 무엇인가요?
필요한 Java 버전 및 빌드 도구는 무엇인가요?
IronPDF for Java는 JDK 8 이상을 필요로 합니다. 프로덕션 사용을 위해 권장 최소 버전은 JDK 11 (LTS)입니다. Download the JDK from the Oracle download page or use an OpenJDK distribution such as Eclipse Temurin.
Maven (3.6+) 및 Gradle (7.0+) 모두 지원됩니다. 기업 Java 프로젝트에서는 Maven이 보다 일반적인 선택입니다.
Maven 프로젝트에 IronPDF를 어떻게 추가하나요?
프로젝트의 pom.xml 파일을 열고 <dependencies> 블록 내에 다음 종속성을 추가하십시오:
//:path=/static-assets/pdf/content-code-examples/how-to/java-create-pdf-tutorial/maven-full.xml
<dependency>
<groupId>com.ironsoftware</groupId>
<artifactId>ironpdf</artifactId>
<version>2024.9.1</version>
</dependency>
//:path=/static-assets/pdf/content-code-examples/how-to/java-create-pdf-tutorial/maven-full.xml
<dependency>
<groupId>com.ironsoftware</groupId>
<artifactId>ironpdf</artifactId>
<version>2024.9.1</version>
</dependency>
절약 후 mvn install를 실행하거나 IDE에서 종속성을 자동으로 해결하도록 하십시오. Maven이 Maven Central에서 IronPDF를 다운로드하므로, 개인 저장소 구성은 필요 없습니다.
Gradle 프로젝트에 IronPDF를 어떻게 추가하나요?
dependencies 파일의 build.gradle 블록에 다음 줄을 추가하십시오:
//:path=/static-assets/pdf/content-code-examples/how-to/java-create-pdf-tutorial/gradle-dependency.gradle
implementation 'com.ironsoftware:ironpdf:2024.9.1'
gradle build을 실행하여 라이브러리를 가져오십시오. Check Maven Central for the latest published version.
필요한 가져오기 및 구성은 무엇인가요?
이 가져오기 문을 Java 소스 파일 위에 추가하세요:
//:path=/static-assets/pdf/content-code-examples/how-to/java-create-pdf-tutorial/imports.java
import com.ironsoftware.ironpdf.*;
import com.ironsoftware.ironpdf.render.ChromePdfRenderOptions;
import com.ironsoftware.ironpdf.render.PaperOrientation;
import com.ironsoftware.ironpdf.render.PaperSize;
import com.ironsoftware.ironpdf.security.SecurityOptions;
import com.ironsoftware.ironpdf.security.SecurityManager;
import java.io.IOException;
import java.nio.file.Paths;
//:path=/static-assets/pdf/content-code-examples/how-to/java-create-pdf-tutorial/imports.java
import com.ironsoftware.ironpdf.*;
import com.ironsoftware.ironpdf.render.ChromePdfRenderOptions;
import com.ironsoftware.ironpdf.render.PaperOrientation;
import com.ironsoftware.ironpdf.render.PaperSize;
import com.ironsoftware.ironpdf.security.SecurityOptions;
import com.ironsoftware.ironpdf.security.SecurityManager;
import java.io.IOException;
import java.nio.file.Paths;
PDF를 생성하기 전에 main 메서드 또는 애플리케이션 시작 시점에 라이선스 키를 설정하십시오:
//:path=/static-assets/pdf/content-code-examples/how-to/java-create-pdf-tutorial/license-setup.java
License.setLicenseKey("Your-License-Key");
//:path=/static-assets/pdf/content-code-examples/how-to/java-create-pdf-tutorial/license-setup.java
License.setLicenseKey("Your-License-Key");
참고: 유효한 라이센스 키가 없으면 PDF에 체험판 워터마크가 추가됩니다. 라이센스 구매 또는 무료 체험 시작하여 제거하세요. Java에서 라이센스 키 사용에 대한 추가 구성 옵션을 참조하세요.
Java에서 HTML 문자열로부터 PDF를 어떻게 생성하나요?
HTML 문자열은 PdfDocument.renderHtmlAsPdf()로 직접 전달하십시오. IronPDF는 메모리 내의 완성된 문서를 나타내는 PdfDocument 인스턴스를 반환합니다. saveAs()을 호출하여 디스크에 기록합니다.
//:path=/static-assets/pdf/content-code-examples/how-to/java-create-pdf-tutorial/html-string-to-pdf.java
// HTML content with inline CSS
String htmlContent = "<h1>Hello World!</h1><p>This is an example HTML string.</p>";
// Render HTML string to PDF
PdfDocument pdf = PdfDocument.renderHtmlAsPdf(htmlContent);
// Save to disk
pdf.saveAs(Paths.get("html.pdf"));
//:path=/static-assets/pdf/content-code-examples/how-to/java-create-pdf-tutorial/html-string-to-pdf.java
// HTML content with inline CSS
String htmlContent = "<h1>Hello World!</h1><p>This is an example HTML string.</p>";
// Render HTML string to PDF
PdfDocument pdf = PdfDocument.renderHtmlAsPdf(htmlContent);
// Save to disk
pdf.saveAs(Paths.get("html.pdf"));
renderHtmlAsPdf()는 웹 폰트, Flexbox, 그리드 레이아웃, JavaScript 실행을 포함하여 HTML5 및 CSS3 사양을 완벽하게 지원합니다. 다음 예제는 사용자 정의 스타일이 포함된 다중 줄 HTML 템플릿을 사용합니다:
//:path=/static-assets/pdf/content-code-examples/how-to/java-create-pdf-tutorial/html-string-styled.java
// Multi-line HTML with CSS styling using a text block (Java 13+)
String styledHtml = """
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: Arial, sans-serif; margin: 40px; }
h1 { color: #2563eb; border-bottom: 2px solid #e5e7eb; padding-bottom: 8px; }
.summary { background: #f3f4f6; padding: 16px; border-radius: 4px; }
</style>
</head>
<body>
<h1>Invoice #1042</h1>
<div class="summary">
<p>Amount due: $1,250.00</p>
<p>Due date: 2024-06-01</p>
</div>
</body>
</html>
""";
PdfDocument invoice = PdfDocument.renderHtmlAsPdf(styledHtml);
invoice.saveAs(Paths.get("invoice.pdf"));
//:path=/static-assets/pdf/content-code-examples/how-to/java-create-pdf-tutorial/html-string-styled.java
// Multi-line HTML with CSS styling using a text block (Java 13+)
String styledHtml = """
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: Arial, sans-serif; margin: 40px; }
h1 { color: #2563eb; border-bottom: 2px solid #e5e7eb; padding-bottom: 8px; }
.summary { background: #f3f4f6; padding: 16px; border-radius: 4px; }
</style>
</head>
<body>
<h1>Invoice #1042</h1>
<div class="summary">
<p>Amount due: $1,250.00</p>
<p>Due date: 2024-06-01</p>
</div>
</body>
</html>
""";
PdfDocument invoice = PdfDocument.renderHtmlAsPdf(styledHtml);
invoice.saveAs(Paths.get("invoice.pdf"));
위의 송장 예제는 Java 텍스트 블록(Java 13부터 사용 가능)을 사용하여 더 깔끔한 다중 줄 HTML을 제공합니다. 구버전 Java의 경우, HTML 문자열을 수동으로 연결하거나 renderHtmlFileAsPdf()을 사용하여 파일에서 불러와야 합니다. JavaScript 렌더링을 포함한 HTML에서 PDF로 변환의 전체적인 내용을 보려면 HTML에서 PDF로의 튜토리얼 for Java를 참조하세요.
Java에서 로컬 HTML 파일로부터 PDF를 어떻게 생성하나요?
로컬 파일 시스템에 저장된 HTML 파일을 변환하려면 PdfDocument.renderHtmlFileAsPdf()를 사용하십시오. 경로를 문자열로 전달하세요; 상대 경로는 현재 작업 디렉토리를 기준으로 해석됩니다:
//:path=/static-assets/pdf/content-code-examples/how-to/java-create-pdf-tutorial/html-file-to-pdf.java
// Convert a local HTML file to PDF
PdfDocument filePdf = PdfDocument.renderHtmlFileAsPdf("invoice-template.html");
// Save the converted document
filePdf.saveAs(Paths.get("invoice_output.pdf"));
//:path=/static-assets/pdf/content-code-examples/how-to/java-create-pdf-tutorial/html-file-to-pdf.java
// Convert a local HTML file to PDF
PdfDocument filePdf = PdfDocument.renderHtmlFileAsPdf("invoice-template.html");
// Save the converted document
filePdf.saveAs(Paths.get("invoice_output.pdf"));
IronPDF는 모든 참조된 자산(외부 CSS 파일, 로컬 이미지, JavaScript 라이브러리)을 HTML 파일의 디렉토리를 기준으로 해석합니다. 이는 연결된 스타일시트와 함께 전체 HTML 템플릿을 작성하여 자산 경로를 수정하지 않고 IronPDF를 통해 실행할 수 있음을 의미합니다.
이 메서드는 String 경로와 java.nio.file.Path 객체를 모두 받아들입니다. 프로덕션 사용의 경우, 작업 디렉토리의 모호성을 피하기 위해 절대 경로를 선호하세요. HTML 파일에서 PDF로의 예제를 참조하여 완전한 작동 시연을 보세요.
Java에서 웹 페이지 URL로부터 PDF를 어떻게 생성하나요?
PdfDocument.renderUrlAsPdf()은 실시간 URL을 가져와 Chromium을 사용하여 렌더링한 후 PDF로 반환합니다. 이는 대시보드 스냅샷 캡처, 호스팅된 영수증 페이지에서 PDF 영수증 생성, 웹 콘텐츠 아카이브에 유용합니다:
//:path=/static-assets/pdf/content-code-examples/how-to/java-create-pdf-tutorial/url-to-pdf.java
// Render a live web page to PDF
PdfDocument webPdf = PdfDocument.renderUrlAsPdf("https://ironpdf.com");
webPdf.saveAs(Paths.get("ironpdf-homepage.pdf"));
//:path=/static-assets/pdf/content-code-examples/how-to/java-create-pdf-tutorial/url-to-pdf.java
// Render a live web page to PDF
PdfDocument webPdf = PdfDocument.renderUrlAsPdf("https://ironpdf.com");
webPdf.saveAs(Paths.get("ironpdf-homepage.pdf"));
HTTP 인증이 필요한 페이지의 경우, ChromePdfRenderOptions을 통해 인증 정보를 전달하십시오:
//:path=/static-assets/pdf/content-code-examples/how-to/java-create-pdf-tutorial/url-to-pdf-auth.java
// Configure render options with login credentials
ChromePdfRenderOptions renderOptions = new ChromePdfRenderOptions();
renderOptions.setAuthUsername("username");
renderOptions.setAuthPassword("password");
// Render authenticated page to PDF
PdfDocument securedPdf = PdfDocument.renderUrlAsPdf("https://your-internal-app.com/report", renderOptions);
securedPdf.saveAs(Paths.get("internal-report.pdf"));
//:path=/static-assets/pdf/content-code-examples/how-to/java-create-pdf-tutorial/url-to-pdf-auth.java
// Configure render options with login credentials
ChromePdfRenderOptions renderOptions = new ChromePdfRenderOptions();
renderOptions.setAuthUsername("username");
renderOptions.setAuthPassword("password");
// Render authenticated page to PDF
PdfDocument securedPdf = PdfDocument.renderUrlAsPdf("https://your-internal-app.com/report", renderOptions);
securedPdf.saveAs(Paths.get("internal-report.pdf"));
URL에서 PDF로의 코드 예제에서 세부 사항을 확인하세요. 쿠키나 양식 기반 인증을 사용하는 더 복잡한 로그인 흐름의 경우 웹사이트 로그인 처리를 참조하세요.
페이지 크기, 방향 및 여백을 어떻게 제어하나요?
출력 PDF의 레이아웃을 사용자 정의하려면 ChromePdfRenderOptions를 사용하십시오. 구성된 옵션을 모든 렌더 메소드의 두 번째 인수로 전달하세요. 가장 일반적인 설정은 페이지 방향, 용지 크기 및 여백입니다:
//:path=/static-assets/pdf/content-code-examples/how-to/java-create-pdf-tutorial/pdf-formatting.java
ChromePdfRenderOptions renderOptions = new ChromePdfRenderOptions();
// Set landscape orientation (default is portrait)
renderOptions.setPaperOrientation(PaperOrientation.LANDSCAPE);
// Use US Letter paper size (default is A4)
renderOptions.setPaperSize(PaperSize.LETTER);
// Set margins in millimeters (top, right, bottom, left)
renderOptions.setMarginTop(15);
renderOptions.setMarginRight(15);
renderOptions.setMarginBottom(15);
renderOptions.setMarginLeft(15);
// Include background colors and images
renderOptions.setPrintHtmlBackgrounds(true);
// Apply options when rendering
PdfDocument report = PdfDocument.renderHtmlAsPdf("<h1>Quarterly Report</h1>", renderOptions);
report.saveAs(Paths.get("report.pdf"));
//:path=/static-assets/pdf/content-code-examples/how-to/java-create-pdf-tutorial/pdf-formatting.java
ChromePdfRenderOptions renderOptions = new ChromePdfRenderOptions();
// Set landscape orientation (default is portrait)
renderOptions.setPaperOrientation(PaperOrientation.LANDSCAPE);
// Use US Letter paper size (default is A4)
renderOptions.setPaperSize(PaperSize.LETTER);
// Set margins in millimeters (top, right, bottom, left)
renderOptions.setMarginTop(15);
renderOptions.setMarginRight(15);
renderOptions.setMarginBottom(15);
renderOptions.setMarginLeft(15);
// Include background colors and images
renderOptions.setPrintHtmlBackgrounds(true);
// Apply options when rendering
PdfDocument report = PdfDocument.renderHtmlAsPdf("<h1>Quarterly Report</h1>", renderOptions);
report.saveAs(Paths.get("report.pdf"));
ChromePdfRenderOptions는 DPI, JavaScript 실행 타임아웃, Zoom 비율, CSS 미디어 유형을 포함하여 위에 표시된 설정 외에도 30개 이상의 설정을 제공합니다. 전체 목록은 PDF 생성 설정을 참조하십시오. PaperSize 열거형에 포함되지 않은 사용자 지정 용지 크기에 대해서는 사용자 지정 PDF 용지 크기를 참조하십시오.
Java에서 PDF에 비밀번호 보호를 어떻게 추가하나요?
SecurityOptions는 읽기 및 소유자 암호와 권한 플래그를 제어합니다. 저장하기 전에 문서의 SecurityManager에 SecurityOptions을 전달하십시오:
//:path=/static-assets/pdf/content-code-examples/how-to/java-create-pdf-tutorial/password-protect-basic.java
// Create security settings with a user-facing password
SecurityOptions securityOptions = new SecurityOptions();
securityOptions.setUserPassword("shareable");
// Apply security to the document
PdfDocument urlPdf = PdfDocument.renderUrlAsPdf("https://ironpdf.com");
SecurityManager securityManager = urlPdf.getSecurity();
securityManager.setSecurityOptions(securityOptions);
// Save the password-protected document
urlPdf.saveAs(Paths.get("protected.pdf"));
//:path=/static-assets/pdf/content-code-examples/how-to/java-create-pdf-tutorial/password-protect-basic.java
// Create security settings with a user-facing password
SecurityOptions securityOptions = new SecurityOptions();
securityOptions.setUserPassword("shareable");
// Apply security to the document
PdfDocument urlPdf = PdfDocument.renderUrlAsPdf("https://ironpdf.com");
SecurityManager securityManager = urlPdf.getSecurity();
securityManager.setSecurityOptions(securityOptions);
// Save the password-protected document
urlPdf.saveAs(Paths.get("protected.pdf"));
더 엄격한 제어를 위해 소유자 비밀번호를 설정하고 특정 작업을 제약하세요:
//:path=/static-assets/pdf/content-code-examples/how-to/java-create-pdf-tutorial/password-protect-advanced.java
SecurityOptions advancedSecurity = new SecurityOptions();
// User password: required to open the file
advancedSecurity.setUserPassword("user-open-pass");
// Owner password: required to change security settings
advancedSecurity.setOwnerPassword("owner-admin-pass");
// Restrict editing operations
advancedSecurity.setAllowPrint(false);
advancedSecurity.setAllowCopy(false);
advancedSecurity.setAllowEditContent(false);
advancedSecurity.setAllowEditAnnotations(false);
//:path=/static-assets/pdf/content-code-examples/how-to/java-create-pdf-tutorial/password-protect-advanced.java
SecurityOptions advancedSecurity = new SecurityOptions();
// User password: required to open the file
advancedSecurity.setUserPassword("user-open-pass");
// Owner password: required to change security settings
advancedSecurity.setOwnerPassword("owner-admin-pass");
// Restrict editing operations
advancedSecurity.setAllowPrint(false);
advancedSecurity.setAllowCopy(false);
advancedSecurity.setAllowEditContent(false);
advancedSecurity.setAllowEditAnnotations(false);
PDF 열기 시, 비밀번호를 입력하라는 프롬프트가 나타납니다:
올바른 비밀번호 입력 후, PDF가 열리고 전체 내용이 표시됩니다:
보안 및 메타데이터 설정에서 권한 플래그의 전체 목록을 확인하세요.
Spring Boot 애플리케이션에서 PDF를 어떻게 생성하나요?
IronPDF는 Spring Boot와 직접 통합됩니다. 컨트롤러 메소드에서 PDF를 바이트 배열 HTTP 응답으로 반환합니다; 이 패턴은 수요에 따른 보고서 생성, 송장 다운로드 및 데이터 내보내기에 사용됩니다.
//:path=/static-assets/pdf/content-code-examples/how-to/java-create-pdf-tutorial/spring-boot-controller.java
import com.ironsoftware.ironpdf.*;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
@RestController
@RequestMapping("/api/pdf")
public class PdfController {
@GetMapping("/invoice/{id}")
public ResponseEntity<byte[]> generateInvoice(@PathVariable String id) throws IOException {
// Build HTML dynamically using the invoice ID
String html = """
<html><body>
<h1>Invoice #%s</h1>
<p>Amount due: $500.00</p>
</body></html>
""".formatted(id);
// Render and return as PDF download
PdfDocument pdf = PdfDocument.renderHtmlAsPdf(html);
byte[] pdfBytes = pdf.getBinaryData();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_PDF);
headers.setContentDispositionFormData("attachment", "invoice-" + id + ".pdf");
return ResponseEntity.ok().headers(headers).body(pdfBytes);
}
}
//:path=/static-assets/pdf/content-code-examples/how-to/java-create-pdf-tutorial/spring-boot-controller.java
import com.ironsoftware.ironpdf.*;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
@RestController
@RequestMapping("/api/pdf")
public class PdfController {
@GetMapping("/invoice/{id}")
public ResponseEntity<byte[]> generateInvoice(@PathVariable String id) throws IOException {
// Build HTML dynamically using the invoice ID
String html = """
<html><body>
<h1>Invoice #%s</h1>
<p>Amount due: $500.00</p>
</body></html>
""".formatted(id);
// Render and return as PDF download
PdfDocument pdf = PdfDocument.renderHtmlAsPdf(html);
byte[] pdfBytes = pdf.getBinaryData();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_PDF);
headers.setContentDispositionFormData("attachment", "invoice-" + id + ".pdf");
return ResponseEntity.ok().headers(headers).body(pdfBytes);
}
}
getBinaryData() 메서드는 PDF를 바이트 배열로 반환하며, Spring Boot는 이를 클라이언트로 직접 스트리밍합니다. 임시 파일이 디스크에 기록되지 않습니다. 대량 배포의 경우, 요청 단위가 아닌 License.setLicenseKey() 메서드나 애플리케이션 시작 리스너에서 @PostConstruct를 인스턴스화하십시오.
Java에서 PDF 생성의 다음 단계는 무엇인가요?
이 가이드는 IronPDF를 사용하여 Java에서 PDF를 생성하는 네 가지 방법을 보여주었습니다: HTML 문자열 렌더링, 로컬 파일 변환, URL 캡처, Spring Boot HTTP 응답 스트리밍. 모든 메서드는 동일한 PdfDocument API, 서식 제어를 위한 ChromePdfRenderOptions, 그리고 액세스 보호를 위한 SecurityOptions를 공유합니다.
IronPDF for Java는 워터마크 추가 및 스탬핑, 여러 PDF 파일 병합, 개별 페이지로 PDF 분할, 디지털 서명 추가, JavaScript 차트를 PDF로 렌더링 및 PDF 프로그래밍 출력도 지원합니다.
무료 체험을 시작하세요 PDF를 워터마크 없이 생성하거나, 프로젝트에 맞는 플랜을 선택하기 위해 라이선싱 옵션 보기를 참조하세요. 더 깊이 파보고 싶으신가요? IronPDF for Java 튜토리얼 페이지를 확인하세요.
자주 묻는 질문
Java에서 HTML 문자열에서 PDF를 생성하는 방법은?
HTML 문자열을 PdfDocument.renderHtmlAsPdf()에 전달합니다. 이 메서드는 메모리에 PdfDocument 객체를 반환합니다. 그것을 디스크에 기록하기 위해 pdf.saveAs(Paths.get("output.pdf"))를 호출하세요. IronPDF는 완전한 HTML5, CSS3, JavaScript를 지원합니다.
IronPDF는 어떤 Java 버전을 필요로 하나요?
IronPDF for Java는 JDK 8 이상의 버전을 필요로 합니다. JDK 11 LTS가 프로덕션 배포를 위한 최소 권장 버전입니다.
Maven 프로젝트에 IronPDF를 추가하는 방법은?
pom.xml의 섹션 내에 groupId com.ironsoftware 및 artifactId ironpdf로 종속성 블록을 추가한 뒤 mvn install을 실행합니다.
Java에서 로컬 HTML 파일에서 PDF를 생성하는 방법은?
HTML 파일 경로와 함께 PdfDocument.renderHtmlFileAsPdf()를 호출합니다. IronPDF는 파일의 디렉토리에 상대적인 모든 연결된 CSS, 이미지, JavaScript를 자동으로 해결합니다.
Java에서 URL에서 PDF를 생성할 수 있나요?
네. 대상 URL과 함께 PdfDocument.renderUrlAsPdf()를 호출합니다. IronPDF는 Chromium을 사용하여 페이지를 가져오고 PdfDocument를 반환합니다. HTTP 인증이 필요한 페이지의 경우 ChromePdfRenderOptions를 통해 자격 증명을 전달하세요.
Java에서 IronPDF로 PDF를 비밀번호로 보호하는 방법은?
SecurityOptions 객체를 생성하고, setUserPassword()에 비밀번호를 설정한 후 saveAs()를 호출하기 전에 그 옵션을 urlPdf.getSecurity().setSecurityOptions()에 전달하세요.
Spring Boot 애플리케이션에서 IronPDF를 사용하는 방법은?
@RestController 메서드에 PDF 생성 로직을 주입합니다. PdfDocument.renderHtmlAsPdf()를 호출한 다음 pdf.getBinaryData()를 사용하여 바이트 배열을 얻어 MediaType.APPLICATION_PDF와 함께 ResponseEntity로 반환합니다.
Java에서 IronPDF에 페이지 크기와 방향을 설정하는 방법은?
ChromePdfRenderOptions 객체를 생성하고 setPaperSize()와 setPaperOrientation()을 호출한 다음 렌더링 메서드의 두 번째 인자로 전달합니다. 순서 충돌을 피하려면 페이지 크기를 먼저 설정하세요.
IronPDF가 Java에서 Linux와 macOS에서 실행되나요?
네. IronPDF for Java는 Windows, Linux, macOS에서 실행됩니다. 추가적인 PDF 뷰어나 렌더링 엔진 없이 AWS, Azure, Google Cloud에서의 클라우드 배포도 지원합니다.
라이선스 키 없이도 PDF에 워터마크가 추가되나요?
예. 유효한 라이선스 키가 없으면 IronPDF는 생성된 모든 문서에 체험판 워터마크를 추가합니다. 유효한 키와 함께 애플리케이션 시작 시 License.setLicenseKey()를 호출하여 제거하세요.




