使用pdfbox添加图片

public void test2() throws IOException {
        String pdfPath = "/Users/zhouyang/Desktop/pdf.pdf";
        String pdfPath1 = "/Users/zhouyang/Desktop/pdf1.pdf";
        String logoPath = "/Users/zhouyang/Desktop/sysush_logo.jpeg";
        File file = new File(pdfPath);
        PDDocument doc = PDDocument.load(file);
        PDPage page = doc.getPage(0);
        PDImageXObject pdImage = PDImageXObject.createFromFile(logoPath,doc);
        PDPageContentStream contents = new PDPageContentStream(doc, page, PDPageContentStream.AppendMode.APPEND,false,false);
        contents.drawImage(pdImage, 200, 700, 200, 50);
        contents.close();
        doc.save(pdfPath1);
        doc.close();
    }

posted on 2023-09-28 16:54  荷楠仁  阅读(115)  评论(0编辑  收藏  举报

导航