本篇文章小编给大家分享一下Java实现PDF文件的分割与加密功能代码示例,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
加密文件
/** * 加密文件测试 * @from fhadmin.cn */ @Test public void encryptTest(){ try { String filePath = "D:test像李开复一样思考人生.pdf"; String password = "1234"; PDDocument document = PDDocument.load(new File(filePath)); StandardProtectionPolicy spp = new StandardProtectionPolicy(password, password,new AccessPermission()); document.protect(spp); String newFilePath = "D:test像李开复一样思考人生2.pdf"; document.save(newFilePath); document.close(); } catch (IOException e) { e.printStackTrace(); } }
切割文件
/** * 切割文件测试 * @from fhadmin.cn */ @Test public void extractTest(){ try { String newFilePath = "D:test像李开复一样思考人生2.pdf"; String password = "1234"; PDDocument document = PDDocument.load(new File(newFilePath), password);//带密码读取 //从第一页截取到第二页 PageExtractor pageExtractor = new PageExtractor(document, 1, 2); PDDocument extract = pageExtractor.extract(); extract.save("D:test像李开复一样思考人生free.pdf"); extract.close(); document.close(); } catch (IOException e) { e.printStackTrace(); } }
生成封面图
/** * 切割文件测试 * @from fhadmin.cn */ @Test public void createCoverPicTest(){ try { String pdfPath = "D:test像李开复一样思考人生.pdf"; File file = new File(pdfPath); //order目录 String orderPath = file.getParent(); //转换后的img目录 String bookName = file.getName().substring(0,file.getName().lastIndexOf(".")); String imgPath = orderPath + File.separator +bookName+".png"; log.debug("pdf封面图生成成功:{}", imgPath); PDDocument pdDocument = PDDocument.load(new File(pdfPath)); PDFRenderer renderer = new PDFRenderer(pdDocument); /* 第二位参数越大转换后越清晰,相对转换速度越慢 */ BufferedImage image = renderer.renderImageWithDPI(0, 150); ImageIO.write(image, "png", new File(imgPath)); } catch (IOException e) { e.printStackTrace(); } }
敢达决战官方正版 安卓版v6.7.9
下载敢达决战 安卓版v6.7.9
下载像素火影骨架佐助 (Perseverance Fire Shadow)手机版v1.16
下载要塞英雄 安卓版v33.20.0-39082670-Android
下载梦想城镇vivo最新版本 安卓版v12.0.1
梦想城镇vivo版是这款卡通风模拟经营类手游的渠道服版本,玩
怦然心动的瞬间 安卓版v1.0
怦然心动的瞬间是一款真人向的恋爱互动游戏,在游戏中玩家将扮演
曼尼汉堡店游戏 安卓版v1.0.3
曼尼汉堡店是一款非常好玩的精品恐怖类型冒险游戏,在这款游戏中
现代总统模拟器去广告版 安卓版v1.0.46
现代总统模拟器是一款休闲养成类游戏,可能对于不少的玩家来说都
现代总统模拟器付费完整版 安卓版v1.0.46
现代总统模拟器高级版在商店是需要付费的,相对于普通版本,高级