클래식 텍스트 머리글 및 바닥글 추가

import com.ironsoftware.ironpdf.PdfDocument;
import com.ironsoftware.ironpdf.font.FontTypes;
import com.ironsoftware.ironpdf.headerfooter.TextHeaderFooter;
import com.ironsoftware.ironpdf.headerfooter.HeaderFooterOptions;
import java.io.IOException;

// Initialize HeaderFooterOptions object.
HeaderFooterOptions options = new HeaderFooterOptions();
PdfDocument pdf = PdfDocument.renderUrlAsPdf("http://www.google.com");

// Add a header to every page easily
// Mergeable fields are:
// {page} {total-pages} {url} {date} {time} {html-title} & {pdf-title}
options.setFirstPageNumber(1); // use 2 if a coverpage  will be appended
TextHeaderFooter textHeader = new TextHeaderFooter();
textHeader.setDrawDividerLine(true);
textHeader.setCenterText("{url}");
textHeader.setFont(FontTypes.getHelvetica());
textHeader.setFontSize(12);
pdf.addTextHeader(textHeader, options);

// Add a footer too
TextHeaderFooter textFooter = new TextHeaderFooter();
textFooter.setDrawDividerLine(true);
textFooter.setFont(FontTypes.getArial());
textFooter.setFontSize(10);
textFooter.setLeftText("{date} {time}");
textFooter.setRightText("{page} of {total-pages}");
pdf.addTextFooter(textFooter, options);

try {
    pdf.saveAs(Paths.get("assets/text_headers_footers.pdf"));
} catch (IOException e) {
    System.out.println("Failed to save PDF");
    throw new RuntimeException(e);
}
mvn install
클래식 텍스트 머리글 및 바닥글 추가

클래식 텍스트 머리글 및 바닥글 추가

이 코드 예제는 IronPDF 사용하여 개발자가 파일 시스템에서 불러오거나 HTML 콘텐츠에서 생성된 PDF 문서에 대한 머리글과 바닥글을 정의하는 방법을 보여줍니다.

TextHeaderFooter 클래스는 개발자가 PDF 문서의 헤더 또는 푸터의 왼쪽, 오른쪽 또는 중앙 영역에 포함될 텍스트를 지정할 수 있도록 합니다. 위에서 보여진 것처럼, 개발자는 IronPDF의 내장 템플릿 태그(예: `{date}` `, ` `{time}` `, and ` `{page}`)를 사용하여 빠르게 헤더와 푸터를 구성할 수 있습니다. 사용자는 이러한 태그만 사용할 필요는 없습니다. IronPDF 사용자가 이러한 위치에 어떤 종류든, 어떤 양이든 자유롭게 삽입할 수 있도록 해줍니다.

문서 프레젠테이션을 향상시키기 위해 IronPDF 내에서 훨씬 더 유연한 디자인을 제공하는 TextHeaderFooter 클래스 대신 HtmlHeaderFooter 클래스를 사용하는 것을 고려해 보세요.

Explore the TextHeaderFooter Class Documentation
GitHub에서 보기

시작할 준비 되셨나요?

버전:2026.10방금 출시