PDF에 바닥글 추가

PDF에 바닥글 추가

문서의 모든 페이지에 반복되는 바닥글 내용이 필요한 경우 PdfFileStamp를 사용하세요.

단계

  1. PdfFileStamp 인스턴스를 생성하고 소스 PDF를 바인딩하세요.
  2. FormattedText 또는 이미지 스트림으로 바닥글 콘텐츠를 작성하세요.
  3. 적절한 addFooter 오버로드를 호출하세요.
  4. 업데이트된 파일을 저장하고 Facade 개체를 닫으세요.

자바 예제

public static void addTextFooter(Path inputFile, Path outputFile) {
    PdfFileStamp pdfStamper = new PdfFileStamp();
    try {
        pdfStamper.bindPdf(inputFile.toString());
        FormattedText text = new FormattedText("Sample Footer");
        pdfStamper.addFooter(text, 20);
        pdfStamper.save(outputFile.toString());
    } finally {
        pdfStamper.close();
    }
}

public static void addImageFooter(Path inputFile, Path imageFile, Path outputFile) throws Exception {
    PdfFileStamp pdfStamper = new PdfFileStamp();
    try (InputStream imageStream = Files.newInputStream(imageFile)) {
        pdfStamper.bindPdf(inputFile.toString());
        pdfStamper.addFooter(imageStream, 20);
        pdfStamper.save(outputFile.toString());
    } finally {
        pdfStamper.close();
    }
}

public static void addFooterWithMargins(Path inputFile, Path outputFile) {
    PdfFileStamp pdfStamper = new PdfFileStamp();
    try {
        pdfStamper.bindPdf(inputFile.toString());
        FormattedText text = new FormattedText("This footer has margins on all sides.");
        pdfStamper.addFooter(text, 20, 20, 20);
        pdfStamper.save(outputFile.toString());
    } finally {
        pdfStamper.close();
    }
}