System.out.println("Automatic grouping and nesting");
try {
// step 1
LwgDocument document = new LwgDocument(LwgPageSize.A4, 50, 50, 50, 50);
// step 2
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("automatic.pdf"));
writer.setPdfVersion(PdfWriter.VERSION_1_5);
writer.setViewerPreferences(PdfWriter.PageModeUseOC);
// step 3
document.open();
// step 4
PdfContentByte cb = writer.getDirectContent();
LwgPhrase explanation = new LwgPhrase("Automatic layer grouping and nesting", new LwgFont(LwgFont.HELVETICA, 20, LwgFont.BOLD, Color.red));
ColumnText.showTextAligned(cb, LwgElement.ALIGN_LEFT, explanation, 50, 650, 0);
PdfLayer l12 = new PdfLayer("Layer nesting", writer);
PdfLayer l1 = new PdfLayer("Layer 1", writer);
PdfLayer l2 = new PdfLayer("Layer 2", writer);