HTML 헤더 및 푸터 추가
from ironpdf import *
import os

# Instantiate Renderer
renderer = ChromePdfRenderer()
 
# Build a footer using html to style the text
# mergeable fields are:
# {page} {total-pages} {url} {date} {time} {html-title} & {pdf-title}
renderer.RenderingOptions.HtmlFooter = HtmlHeaderFooter()
renderer.RenderingOptions.HtmlFooter.MaxHeight = 15  # millimeters
renderer.RenderingOptions.HtmlFooter.HtmlFragment = "<center><i>{page} of {total-pages}<i></center>"
renderer.RenderingOptions.HtmlFooter.DrawDividerLine = True
 
# Use sufficient MarginBottom to ensure that the HtmlFooter does not overlap with the main PDF page content.
renderer.RenderingOptions.MarginBottom = 25  # mm
 
# Build a header using an image asset
# Note the use of BaseUrl to set a relative path to the assets
renderer.RenderingOptions.HtmlHeader = HtmlHeaderFooter()
renderer.RenderingOptions.HtmlHeader.MaxHeight = 20  # millimeters
renderer.RenderingOptions.HtmlHeader.HtmlFragment = "<img src='iron.png'>"
renderer.RenderingOptions.HtmlHeader.BaseUrl = os.path.abspath("C:/Users/lyty1/OneDrive/Documents/IronPdfPythonNew")

# Use sufficient MarginTop to ensure that the HtmlHeader does not overlap with the main PDF page content.
renderer.RenderingOptions.MarginTop = 25  # mm
pip install ironpdf
HTML 헤더 및 푸터 추가

HTML 헤더 및 푸터 추가

IronPDF for Python은 스타일을 자유롭게 지정할 수 있는 HTML 헤더와 푸터를 지원합니다. PDF의 헤더와 푸터 영역에서 이미지, 사용자 지정 글꼴, 동적 병합 필드를 비롯한 HTML과 CSS의 모든 조합을 사용할 수 있습니다.

시작하기

각 HtmlHeaderFooter 객체를 생성하고 RenderingOptions.HtmlHeader 및 RenderingOptions.HtmlFooter에 할당하세요. MaxHeight를 설정하여 각 영역의 높이를 제한하고, 페이지 본문과 겹치지 않도록 MarginTop / MarginBottom을 구성하세요.

코드 이해하기

  • HtmlHeaderFooter: HTML 조각을 받아 매 페이지의 헤더 또는 푸터로 렌더링하는 객체입니다.
  • HtmlFragment: 표시할 HTML 콘텐츠입니다. HTML 내에서 {page} 및 {total-pages}와 같은 동적 병합 필드가 지원됩니다.
  • MaxHeight: 헤더나 푸터 영역이 차지할 수 있는 최대 높이(밀리미터)입니다.
  • DrawDividerLine: True일 때, 헤더/푸터와 페이지 콘텐츠 사이에 가로선을 그립니다.
  • BaseUrl: HTML 조각 내의 상대 자산 경로(예: 이미지)를 해결하는 데 사용되는 기본 경로입니다. 절대 경로를 구성하려면 os.path.abspath를 사용하세요.
  • MarginTop / MarginBottom: ???? ??? ??? ?????. ??? ??? ?? ???? ??? ??? ??? ??? MaxHeight ???? ?????.

헤더와 푸터에서 지원되는 HTML

브라우저에서 올바르게 렌더링되는 모든 HTML을 사용할 수 있으며 <img> 태그, <table> 레이아웃, 인라인 스타일 및 Google Fonts 링크를 포함할 수 있습니다.

IronPDF for Python으로 PDF에 헤더와 푸터를 추가하는 방법을 배우세요!

시작할 준비 되셨나요?

버전:2026.11방금 출시