m0_58371349 2021-08-05 10:38 采纳率: 0%
浏览 58

java实现在pdf文件中定位添加图片

所有文件不能存盘,获取文件的方法只有网络地址。
签名图片是前端传回来的base64字符串,使用技术有限制pdfbox,希望得到代码。

  • 写回答

1条回答 默认 最新

  • 关注

    base64编码字符直接保存为文件就可以了。

    /**
         * 将BASE64字符串恢复为二进制数据
         * 
         * @param base64String
         * @return
         */
        public static byte[] decode(String base64String) {
            try {
                return Base64.decodeBase64(base64String.getBytes("UTF-8"));
            } catch (UnsupportedEncodingException e) {
                return null;
            }
        }
    /**
         * 将base64字符解码保存文件
         * 
         * @param base64Code
         * @param targetPath
         * @throws Exception
         */
    
        public static void decoderBase64File(String base64Code, String targetPath) throws Exception {
            byte[] buffer = decode(base64Code);
            FileOutputStream out = new FileOutputStream(targetPath);
            out.write(buffer);
            out.close();
        }
    
    评论

报告相同问题?

问题事件

  • 创建了问题 8月5日