AccessPermission permission, boolean nonSeq) throws IOException
{
PDDocument document = PDDocument.load(new ByteArrayInputStream(inputFileAsByteArray));
String prefix = "Simple-";
int numSrcPages = document.getNumberOfPages();
PDFRenderer pdfRenderer = new PDFRenderer(document);
ArrayList<BufferedImage> srcImgTab = new ArrayList<BufferedImage>();
ArrayList<ByteArrayOutputStream> srcContentStreamTab = new ArrayList<ByteArrayOutputStream>();
for (int i = 0; i < numSrcPages; ++i)
{
srcImgTab.add(pdfRenderer.renderImage(i));
COSStream contentStream = document.getPage(i).getContentStream();
InputStream unfilteredStream = contentStream.getUnfilteredStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copy(unfilteredStream, baos);
unfilteredStream.close();
srcContentStreamTab.add(baos);
}
PDDocument encryptedDoc = encrypt(keyLength, sizePriorToEncr, document,
prefix, permission, nonSeq, userpassword, ownerpassword);
Assert.assertEquals(numSrcPages, encryptedDoc.getNumberOfPages());
pdfRenderer = new PDFRenderer(encryptedDoc);
for (int i = 0; i < encryptedDoc.getNumberOfPages(); ++i)
{
// compare rendering
BufferedImage bim = pdfRenderer.renderImage(i);
ValidateXImage.checkIdent(bim, srcImgTab.get(i));
// compare content streams
COSStream contentStreamDecr = encryptedDoc.getPage(i).getContentStream();
InputStream unfilteredStream = contentStreamDecr.getUnfilteredStream();