_root.getLayer().assignPagePaintingPositions(c, Layer.PAGED_MODE_PRINT);
int pageCount = _root.getLayer().getPages().size();
c.setPageCount(pageCount);
for (int i = 0; i < pageCount; i++) {
PageBox currentPage = (PageBox)pages.get(i);
c.setPage(i, currentPage);
paintPage(c, writer, currentPage);
_outputDevice.finishPage();
if (i != pageCount - 1) {
PageBox nextPage = (PageBox)pages.get(i+1);
com.lowagie.text.Rectangle nextPageSize = new com.lowagie.text.Rectangle(
0, 0,
nextPage.getWidth(c) / _dotsPerPoint,
nextPage.getHeight(c) / _dotsPerPoint);
doc.setPageSize(nextPageSize);
doc.newPage();
_outputDevice.initializePage(
writer.getDirectContent(), nextPageSize.getHeight());
}