if a big image in pdf,  when save as image jpg, or png, will OutOfMemoryError


private static BufferedImage from8bit(PDImage pdImage, WritableRaster raster)
        throws IOException
{
    InputStream input = pdImage.createInputStream();
    try
    {
        // get the raster's underlying byte buffer
        byte[][] banks = ((DataBufferByte) 
raster.getDataBuffer()).getBankData();
        final int width = pdImage.getWidth();
        final int height = pdImage.getHeight();
        final int numComponents = 
pdImage.getColorSpace().getNumberOfComponents();
        int max = width * height;  // maybe a big image (10000x5000 px) but 
just 1080*1920 px can show on pdf
        byte[] tempBytes = new byte[numComponents];
        for (int i = 0; i < max; i++)
        {
            input.read(tempBytes);
            for (int c = 0; c < numComponents; c++)
            {
                banks[c][i] = tempBytes[0+c];
            }
        }
        // use the color space to convert the image to RGB
        return pdImage.getColorSpace().toRGBImage(raster);
    }
    finally
    {
        IOUtils.closeQuietly(input);
    }
}    




[email protected]

Reply via email to