Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javax.imageio.IIOException:写入PNG文件时发生I/O错误_Java_Spring_Web Services_Tomcat_Jpedal - Fatal编程技术网

javax.imageio.IIOException:写入PNG文件时发生I/O错误

javax.imageio.IIOException:写入PNG文件时发生I/O错误,java,spring,web-services,tomcat,jpedal,Java,Spring,Web Services,Tomcat,Jpedal,我正在使用Jpedal工具将PDF转换为图像。 当PDF页面数量非常大,我们对其进行处理以进行转换时,tomcat就会停止,并抛出异常- javax.imageio.IIOException: I/O error writing PNG file. 谁能帮我一下吗 public boolean createPDF2ImageTask(String sourcePDFAbsPath, String destinationImageAbsPath, Float scalingFactor, S

我正在使用Jpedal工具将PDF转换为图像。 当PDF页面数量非常大,我们对其进行处理以进行转换时,tomcat就会停止,并抛出异常-

  javax.imageio.IIOException: I/O error writing PNG file.
谁能帮我一下吗

public boolean createPDF2ImageTask(String sourcePDFAbsPath, String destinationImageAbsPath, Float scalingFactor, String fileFormat, int softLimitInKB) throws Exception
    { 

        System.setProperty("org.jpedal.flattenForm","true");
        logger.info("createPDF2ImageTask ( sourcePDFAbsPath = "+sourcePDFAbsPath+" , destinationImageAbsPath = "+destinationImageAbsPath+ ", scalingFactor = "+scalingFactor+ " , fileFormat = "+fileFormat+ " softLimitInKB ="+softLimitInKB );
        boolean status = true;
        Float newScalingFactor;
        int sizeOfImageInKB;

        //PdfDecoder object provides the conversion 

        PdfDecoderServer decoder = null;
        Map mapValues = null;
        BufferedImage imageToSave = null;
        BufferedOutputStream bufferedOutputStream = null;
        long startTime = System.currentTimeMillis();
        try
        {

            Helper.deleteFile(destinationImageAbsPath);

            //mappings for non-embedded fonts to use
            FontMappings.setFontReplacements();

            decoder = new PdfDecoderServer(true);
            decoder.openPdfFile(sourcePDFAbsPath);


            mapValues = new HashMap();


            mapValues.put(JPedalSettings.EXTRACT_AT_BEST_QUALITY_MAXSCALING, 2);

            //alternatively secify a page size (aspect ratio preserved so will do best fit)
            //set a page size (JPedal will put best fit to this)
            PdfPageData pageData = decoder.getPdfPageData();
            int width = (int)(scalingFactor*pageData.getCropBoxWidth(1));
            int height = (int)(scalingFactor*pageData.getCropBoxHeight(1));
            logger.info("width = "+ width + "   height= "+height);          
            mapValues.put(JPedalSettings.EXTRACT_AT_PAGE_SIZE, new String[]{String.valueOf(width),String.valueOf(height)});

            //which takes priority (default is false)
            mapValues.put(JPedalSettings.PAGE_SIZE_OVERRIDES_IMAGE, Boolean.TRUE);

            PdfDecoderServer.modifyJPedalParameters(mapValues);                              

            /////////////////////////////////////////////////////////////////////////////////////

            try
            {
                imageToSave = decoder.getPageAsHiRes(1, null, false);
                decoder.flushObjectValues(true);
                if(imageToSave != null)
                {
                    logger.info("Start saving image as a file");
                    bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(new File(destinationImageAbsPath)));

                    ImageIO.write(imageToSave, fileFormat, bufferedOutputStream);

                }
                else
                {
                    throw new Exception("imageToSave is null, Exception in extractPageAsImage ");
                }
            }
            catch(Exception e)
            {
                logger.error("Exception in extractPageAsImage :: "+e);
                logger.error("Exception stack trace in extractPageAsImage :: ",e);
                throw new Exception("Exception in extractPageAsImage :: "+e);
            }
它在extractPageAsImage::javax.imageio.IIOException中引发异常-异常:写入PNG文件时发生I/O错误


也许您可以通过增加Tomcat实例的内存来解决这个问题。在Unix平台上,这可以通过在
setenv.sh
中添加一些Java选项来实现:

export JAVA_OPTS="$JAVA_OPTS -Xms128m -Xmx2048m -XX:MaxPermSize=512m"
或者在文件
setenv.bat
中的窗口上:

set "JAVA_OPTS=%JAVA_OPTS% -Xms128m -Xmx2048m -XX:MaxPermSize=512m" 
请注意,上面示例中的数字只是示例,因为它们取决于平台上可用的内存


有关如何在您的平台上配置Tomcat的更多详细信息,请参阅。

也许您可以通过增加Tomcat实例的内存来解决这个问题。在Unix平台上,这可以通过在
setenv.sh
中添加一些Java选项来实现:

export JAVA_OPTS="$JAVA_OPTS -Xms128m -Xmx2048m -XX:MaxPermSize=512m"
或者在文件
setenv.bat
中的窗口上:

set "JAVA_OPTS=%JAVA_OPTS% -Xms128m -Xmx2048m -XX:MaxPermSize=512m" 
请注意,上面示例中的数字只是示例,因为它们取决于平台上可用的内存


有关如何在您的平台上配置Tomcat的更多详细信息,请参阅。

请发布堆栈跟踪。最好
抛出新异常(“extractPageAsImage中的异常”,e)而不是
抛出新异常(“extractPageAsImage:中的异常::”+e)@LarsGendner嗨,这些是以前的日志。现在在处理过程中,它意外地停止了tomcat,之后没有打印任何日志。请发布堆栈跟踪。最好
抛出新异常(“extractPageAsImage中的异常”,e)而不是
抛出新异常(“extractPageAsImage:中的异常::”+e)@LarsGendner嗨,这些是以前的日志。现在,在处理过程中,它意外地停止了tomcat,之后不会打印任何日志。