0

Please suggest how to solve below error,while converting pdf to tiff.The pdf has multiple pages with scanned (Example Application form scanned and converted to PDF).Issue with if a pdf page has two or more scanned images in a single pdf page then below error is coming. sun.awt.image.ImageFormatException: Didn't expect more than one scan.

sun.awt.image.ImageFormatException: Didn't expect more than one scan
    at sun.awt.image.JPEGImageDecoder.readImage(Native Method)
    at sun.awt.image.JPEGImageDecoder.produceImage(JPEGImageDecoder.java:119)
    at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:246)
    at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:172)
    at sun.awt.image.ImageFetcher.run(ImageFetcher.java:136)

We are using icepdf-viewer.jar,jai_core.jar,jai_imageio.jar and icepdf-core.jarbelow is the code snipped

public void capturePageTiff(int pageIndex) throws IOException {
    boolean hasPageSizeChanged = hasPageSizeChanged(pageIndex);
    // cache the existing buffer as they are costly to recreate.
    if (hasPageSizeChanged(pageIndex) || bufferedImage == null) {
        if (hasPageSizeChanged) {
            currentPageSize = calculatePageSize(pageIndex, "NEW");
        }
        bufferedImage = new BufferedImage(
                (int) currentPageSize.getWidth(),
                (int) currentPageSize.getHeight(),
                BufferedImage.TYPE_BYTE_BINARY,
                cm);
        imageGraphics = bufferedImage.createGraphics();
        img = new IIOImage(bufferedImage, null, null);
    }
    // finally paint the content.
    Catalog catalog = document.getCatalog();
    //System.out.println("iiii " + pageIndex);
    Page page = catalog.getPageTree().getPage(pageIndex, this);
    // System.out.println(page);
    AffineTransform prePaintTransform = imageGraphics.getTransform();
    page.paint(imageGraphics, GraphicsRenderingHints.PRINT,
            Page.BOUNDARY_CROPBOX,
            rotation, scale, null,
            true, false);//Error is coming here
    catalog.getPageTree().releasePage(page, this);
    imageGraphics.setTransform(prePaintTransform);
    // write the captured page to the tiff.
    if (pageIndex == 0) {
        writer.write(null, img, param);
    } else {           
        try {
            writer.writeInsert(-1, img, param);
        } catch (Exception e) {
            writer.prepareWriteSequence(null);
            writer.writeToSequence(img, param);
            writer.endWriteSequence();
        }
    }
}
4

0 回答 0