public void testCreateFromRandomAccessMulti() throws IOException
{
String tiffPath = "src/test/resources/org/apache/pdfbox/pdmodel/graphics/image/ccittg4multi.tif";
ImageInputStream is = ImageIO.createImageInputStream(new File(tiffPath));
ImageReader imageReader = ImageIO.getImageReaders(is).next();
imageReader.setInput(is);
int countTiffImages = imageReader.getNumImages(true);
assertTrue(countTiffImages > 1);
PDDocument document = new PDDocument();
RandomAccess reader = new RandomAccessFile(new File(tiffPath), "r");
int pdfPageNum = 0;
while (true)
{
PDImageXObject ximage = CCITTFactory.createFromRandomAccess(document, reader, pdfPageNum);
if (ximage == null)
{
break;
}
BufferedImage bim = imageReader.read(pdfPageNum);
validate(ximage, 1, bim.getWidth(), bim.getHeight(), "tiff", PDDeviceGray.INSTANCE.getName());
checkIdent(bim, ximage.getOpaqueImage());
PDPage page = new PDPage(PDRectangle.A4);
float fX = ximage.getWidth() / page.getMediaBox().getWidth();
float fY = ximage.getHeight() / page.getMediaBox().getHeight();
float factor = Math.max(fX, fY);
document.addPage(page);
PDPageContentStream contentStream = new PDPageContentStream(document, page, true, false);
contentStream.drawXObject(ximage, 0, 0, ximage.getWidth() / factor, ximage.getHeight() / factor);
contentStream.close();
++pdfPageNum;
}
assertEquals(countTiffImages, pdfPageNum);
document.save(testResultsDir + "/multitiff.pdf");
document.close();
document = PDDocument.loadNonSeq(new File(testResultsDir, "multitiff.pdf"), null);
assertEquals(countTiffImages, document.getNumberOfPages());
document.close();
imageReader.dispose();
}