zoukankan      html  css  js  c++  java
  • 32:JAVA-------读取文件夹,并文件解析,pdf转图片

    import java.awt.image.BufferedImage;
    import java.awt.image.RenderedImage;
    import java.io.File;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    
    import org.icepdf.core.pobjects.Document;
    import org.icepdf.core.util.GraphicsRenderingHints;
    /*
     * pdf 转 图片
     */
    public class PdfToHtml {
        public static void pdf2Pic(String wor_id,String pdfPath, String path){
            Document document = new Document();
            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 static  String GetSql(String path){
              File rootDir = new File(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 void main(String[] args) {
                       // TODO Auto-generated method stub
                      // String path ="E:/项目/contract/newFile/pdf1/";
                         String path="E:/项目/contract/newFile/allpdf/";
                     
                       GetSql(path);
                     }
            
    }
  • 相关阅读:
    卡牌分组
    css字体样式+文本样式
    jQuery---on注册事件的2种方式
    css3神奇的背景控制属性+使用颜色过渡实现漂亮的渐变效果
    js Dom为页面中的元素绑定键盘或鼠标事件
    ES6中Set和WeakSet
    Vue之计算属性Computed和属性监听Watch,Computed和Watch的区别
    JS数据类型和堆栈+变量比较和值的复制+参数传递和类型检测
    复习node中加载静态资源--用express+esj
    种花问题
  • 原文地址:https://www.cnblogs.com/coriander/p/7520411.html
Copyright © 2011-2022 走看看