icepdf 一旦执行PDF转图片 会使远程调用接口的时候报错

122 阅读1分钟

pom.xml引用

<dependency>
    <groupId>org.icepdf.os</groupId>
    <artifactId>icepdf-core</artifactId>
    <version>6.1.2</version>
    <exclusions>
        <exclusion>
            <groupId>javax.media</groupId>
            <artifactId>jai_core</artifactId>
        </exclusion>
    </exclusions>
</dependency>

pdf转图片

public static String pdfToImage(String pdfPath){

    String nowFilePath = null;
    try{
        String imagePath = pdfPath+".png";
        if(StringUtils.endsWith(StringUtils.lowerCase(pdfPath), ".pdf")){
            imagePath = StringUtils.replace(pdfPath, ".pdf", ".png");
        }

        Document document = new Document();
        document.setFile(pdfPath);
        float scale = 0.8f;//缩放比例
        float rotation = 0f;//旋转角度
        BufferedImage image = (BufferedImage)document.getPageImage(0, GraphicsRenderingHints.SCREEN, Page.BOUNDARY_CROPBOX, rotation, scale);
        RenderedImage rendImage = image;
        File file = new File(imagePath);
        ImageIO.write(rendImage, "png", file);
        image.flush();
        document.dispose();
        nowFilePath = imagePath;
    }catch (Throwable t){
        t.printStackTrace();
    }
    return nowFilePath;
}

转图片之后再次执行web接口请求之后报错;如果不转图片则不会报错

pdfToImage('xxxxxxx.pdf');
RestTemplate restTemplate = new RestTemplate();
String res = restTemplate.getForObject(apiUrl, String.class);

哪位大哥知道是怎么回事吗?跪求告知