pdf 전자 서명 추가

3710 단어 자바
사용 하 는 의존:
        
        
            com.itextpdf
            itextpdf
            5.5.13
        
        
            com.itextpdf
            itext-asian
            5.2.0
        
        
            org.bouncycastle
            bcpkix-jdk15on
            1.64
        
        
        
            org.apache.pdfbox
            pdfbox
            2.0.20
        
        

 직접 코드 올 리 기:
package com.secxiot.common.utils;

import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Image;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.PDFRenderer;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;

/**
 *      
 */
public class SignWriteToPDF {
    /**
     * signImagePath     
     * inputPDFPath      
     * outPDFPath       
     */
    public static void setWaterPrint(String outPDFPath, String inputPDFPath, String signImagePath) throws DocumentException, IOException {
        BaseFont baseFont = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        InputStream input = new FileInputStream(new File(inputPDFPath));
        PdfReader reader = new PdfReader(input);

        OutputStream output = new FileOutputStream(new File(outPDFPath));
        PdfStamper stamper = new PdfStamper(reader, output);
        PdfContentByte page = stamper.getOverContent(1);

        //     pdf
       /* page.beginText();
        page.setFontAndSize(baseFont,12);
        BaseColor coler = new BaseColor(0, 0, 0);
        page.setColorFill(coler);
        page.setTextMatrix(100,500); //           
        page.showText("66666666666666666");
        page.endText();*/

        //     pdf
        Image image = Image.getInstance(signImagePath);
        image.setAbsolutePosition(480, 130); //           
        //image.scalePercent(20);//      
        image.setRotationDegrees(90);//     

        image.scaleAbsolute(image.getWidth()/10, image.getWidth()/10);
        page.addImage(image);

        stamper.close();
        reader.close();
        input.close();
    }

    public static void main(String[] args) throws DocumentException, IOException {
        setWaterPrint("H:\\photo\\spatient_sign_48.pdf", "H:\\photo\\spatient_sign.pdf", "H:\\photo\\711664989302785.png");
    }

    /**
     *
     * @param pdfPath pdf   
     * @param imgPath     
     * @param imgType     
     */
    public static void pdfTOimg(String pdfPath, String imgPath, String imgType) {
        File file = new File(pdfPath);
        try {
            PDDocument doc = PDDocument.load(file);
            PDFRenderer renderer = new PDFRenderer(doc);
            int pageCount = doc.getNumberOfPages();
            for(int i=0;i

좋은 웹페이지 즐겨찾기