if (size == null) {
throw new DocumentException("Parameter 'size' must be set");
}
PdfReader reader = IText.read(source);
int pageCount = reader.getNumberOfPages();
List<InputStream> list = new LinkedList<InputStream>();
Document document = null;
ByteArrayOutputStream outputStream = null;
PdfCopy writer = null;
int iSize = size.intValue();
for (int i = 1; i <= pageCount; i++) {
if ((document == null) || ((i % iSize) == 0)) {
if (document != null) {
document.close();
writer.close();
list.add(new ByteArrayInputStream(outputStream.toByteArray()));
}
document = new Document(reader.getPageSizeWithRotation(1));
outputStream = new ByteArrayOutputStream();
writer = new PdfCopy(document, outputStream);
}
PdfImportedPage page = writer.getImportedPage(reader, i);
writer.addPage(page);
}
if (document != null) {
document.close();
writer.close();
list.add(new ByteArrayInputStream(outputStream.toByteArray()));
}
reader.close();
return new DocumentOutput(Collections.toArray(list, InputStream.class));
} catch (IOException e) {
throw new PDFException(e);
} catch (DocumentException e) {