zoukankan      html  css  js  c++  java
  • 利用icepdf将pdf文件转为图片

    所需jar 包为icepdf-core.jar、icepdf-extra.jar、icepdf-pro-intl.jar、icepdf-pro.jar和icepdf-viewer.jar。

    示例代码如下:

    package file;
    
    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.pobjects.Page;
    import org.icepdf.core.util.GraphicsRenderingHints;
    
    public class ICEPdfToImage {
        
        public static void main(String[] args) {
    
            String filePath = "e:/test/移动方案.pdf";
            Document document = new Document();
            try {
                document.setFile(filePath);
            } catch (Exception ex) {
            }
    
            // save page caputres to file.
    
            float scale = 2f;
    
            float rotation = 0f;
    
            // Paint each pages content to an image and write the image to file
    
            for (int i = 0; i < document.getNumberOfPages(); i++) {
    
                BufferedImage image = (BufferedImage)document.getPageImage(i, GraphicsRenderingHints.SCREEN,
                        Page.BOUNDARY_CROPBOX, rotation, scale);
                RenderedImage rendImage = image;
    
                // capture the page image to file
    
                try {
    
                    System.out.println("/t capturing page " + i);
    
                    File file = new File("E:\test\移动方案\image_" + i + ".png");
    
                    ImageIO.write(rendImage, "png", file);
    
                } catch (IOException e) {
    
                    e.printStackTrace();
    
                }
    
                image.flush();
    
            }
    
            // clean up resources
    
            document.dispose();
    
        }
    
    }
  • 相关阅读:
    Linux- 恢复.swp文件
    codeforces contest 1111
    bzoj2589【 Spoj 10707】 Count on a tree II
    20190129模拟题
    loj6070【山东集训第一轮Day4】基因
    bzoj4784【zjoi2017】仙人掌
    bzoj4520【cqoi2016】K远点对
    【学习笔记】BEST定理
    bzoj2441【中山市选】小W的问题
    bzoj3203【sdoi2013】保护出题人
  • 原文地址:https://www.cnblogs.com/101key/p/5455505.html
Copyright © 2011-2022 走看看