클래식 텍스트 머리글 및 바닥글 추가
import {PdfDocument, AffixFonts} from "@ironsoftware/ironpdf";

(async () => {
    // Configure render options
    const options = {
        firstPageNumber: 1, // Use 2 if a cover page will be appended

        // Add a header to every page
        textHeader: {
            dividerLine: true,
            centerText: "{html-title}",
            font: AffixFonts.Helvetica, // Use the font name or font file path
            fontSize: 12,
        },

        // Add a footer
        textFooter: {
            dividerLine: true,
            leftText: "{date} {time}",
            rightText: "{page} of {total-pages}",
            font: AffixFonts.Arial, // Use the font name or font file path
            fontSize: 10,
        },
        // Mergeable fields are: {page} {total-pages} {url} {date} {time} {html-title} & {pdf-title}

        margin: {
            top: 25, // Create 25mm space for the header
            bottom: 25, // Create 25mm space for the footer
        },
    };

    // Define HTML content
    const htmlContent = "<h1>Hello IronPDF</h1>";

    // Render HTML content to a PDF with headers and footers
    const pdf = await PdfDocument.fromHtml(htmlContent, {renderOptions: options });

    // Save the PDF with headers and footers
    await pdf.saveAs("header_footer.pdf");
})();
npm i @ironsoftware/ironpdf
클래식 텍스트 머리글 및 바닥글 추가

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

HTML 콘텐츠를 렌더링할 때 PDF 문서에 텍스트 머리글과 바닥글을 추가하는 방법을 알아보세요.

텍스트 머리글과 바닥글을 포함하려면 렌더링 옵션 객체에 지정해야 합니다. 구분선, HTML 제목을 표시하는 가운데 정렬된 텍스트, 폰트 설정 및 폰트 크기로 헤더 내용을 정의합니다. 유사하게 textFooter 속성을 사용하여 푸터를 정의합니다. {page}, {total-pages}, {url}, {date}, {time}, {html-title}, {pdf-title} 같은 필드를 활용하여 콘텐츠를 개인화할 수 있습니다.

머리글과 바닥글에 맞게 여백을 적절히 조정하세요.

HTML 콘텐츠를 PDF로 변환하기 위해 PdfDocument.fromHtml 메서드를 사용하세요. renderOptions 객체를 옵션으로 전달하세요.

HTML에서 PDF를 생성하는 방법에 대한 자세한 내용은 IronPDF 문서를 참조하십시오.

머리글과 바닥글이 포함된 최종 PDF 문서는 "header_footer.pdf"라는 이름으로 저장됩니다.

GitHub 에서 헤더 및 푸터 예제 코드를 살펴보세요.
GitHub에서 보기

시작할 준비 되셨나요?

버전:2026.10방금 출시