请将pdf转换为tiff时建议如何解决以下错误.pdf有多个扫描页面(扫描示例应用程序表单并转换为PDF)。如果pdf页面在一个页面中有两个或更多扫描图像,请考虑pdf页面然后下面的错误即将来临。 sun.awt.image.ImageFormatException:没想到会有多次扫描。
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)
我们正在使用icepdf-viewer.jar,jai_core.jar,jai_imageio.jar和icepdf-core.jar ,下面是代码剪切
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();
}
}
}