java 读取文件夹图片格式_32:JAVA-------读取文件夹,并文件解析,pdf转图片

importjava.awt.image.BufferedImage;importjava.awt.image.RenderedImage;importjava.io.File;importjava.io.IOException;importjavax.imageio.ImageIO;importorg.icepdf.core.pobjects.Document;importorg.icepdf.core.util.GraphicsRenderingHints;/** pdf 转 图片*/

public classPdfToHtml {public static voidpdf2Pic(String wor_id,String pdfPath, String path){

Document document= newDocument();

document.setFile(pdfPath);float scale = 2.5f;//缩放比例

float rotation = 0f;//旋转角度

for (int i = 0; i < document.getNumberOfPages(); i++) {

BufferedImage image=(BufferedImage)

document.getPageImage(i, GraphicsRenderingHints.SCREEN, org.icepdf.core.pobjects.Page.BOUNDARY_CROPBOX, rotation, scale);

RenderedImage rendImage=image;try{

String imgName= wor_id+i + ".png";

System.out.println(imgName);

File file= new File(path +imgName);

ImageIO.write(rendImage,"png", file);

}catch(IOException e) {

e.printStackTrace();

}

image.flush();

}

document.dispose();

}public staticString GetSql(String path){

File rootDir= newFile(path);if(!rootDir.isDirectory()){

String paths=rootDir.getAbsolutePath().replace("\\", "/");

String[] pathth=paths.split("/");//String filePath = "E:/项目/打牌啦/合同/test/pdf/pdf/basefile.pdf";//pdf2Pic(filePath, "E:/项目/打牌啦/合同/test/pdf/pdf/");//文件名E:/项目/contract/newFile/allpdf/100018815561398.pdf

System.out.println("文件名"+pathth[5]);

String paththth=pathth[5].replace(".pdf", "").trim();

String newPath="E:/项目/contract/newFile/allpdfImage/";

PdfToHtml.pdf2Pic(paththth,paths,newPath);

}else{

String[] fileList=rootDir.list();for (int i = 0; i < fileList.length; i++) {

path= rootDir.getAbsolutePath()+"\\"+fileList[i];try{

Thread.currentThread().sleep(3000);

}catch(InterruptedException e) {

e.printStackTrace();

}

GetSql(path);

}

}return null;

}//WordTOPDFUtil.wordPdf("3518812344444");

public static voidmain(String[] args) {//TODO Auto-generated method stub//String path ="E:/项目/contract/newFile/pdf1/";

String path="E:/项目/contract/newFile/allpdf/";

GetSql(path);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值