Java实现png图片转pdf

一 概述

       实现原理为将图片放入指定的pdf文件中。
参考文档https://pan.baidu.com/s/11DpS-DOyRrwrYuEIGl7vWwicon-default.png?t=L9C2https://pan.baidu.com/s/11DpS-DOyRrwrYuEIGl7vWw         提取码:yfs2

        参考资料:iText 帮助文档.pdf (book118.com)icon-default.png?t=L9C2https://max.book118.com/html/2018/1109/6115022130001230.shtm

二 依赖引入

     
        
        
            com.itextpdf
            itextpdf
            5.5.13
        
        
        
            com.itextpdf
            itext-asian
            5.2.0
        

二 实现方式

//生成指定宽高的pdf文件
Document document = new Document(new Rectangle(makeupW, makeupH));
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("PDF文件生成位置");
            writer.setPdfVersion(PdfName.P);
            document.open();
            Image image = Image.getInstance("图片资源位置");
            image.setAbsolutePosition(0,0);
            //将图片放入pdf文件
            document.add(image);
            document.close();

你可能感兴趣的:(Java,java,itextpdf)