c.setCurrentPage(i);
c.setPage(i, currentPage);
    public void createPDF(OutputStream os) throws DocumentException {        List pages = _root.getLayer().getPages();                RenderingContext c = newRenderingContext();        PageBox firstPage = (PageBox)pages.get(0);        com.lowagie.text.Rectangle firstPageSize = new com.lowagie.text.Rectangle(                0, 0,                 firstPage.getWidth(c) / _dotsPerPoint,                 firstPage.getHeight(c) / _dotsPerPoint);                com.lowagie.text.Document doc =             new com.lowagie.text.Document(firstPageSize, 0, 0, 0, 0);        PdfWriter writer = PdfWriter.getInstance(doc, os);                doc.open();                _outputDevice.initializePage(writer.getDirectContent(), firstPageSize.height());                _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.setCurrentPage(i);            paintPage(c, 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.height());            }        }        doc.close();    }