import java.io.FileOutputStream;
import java.util.ArrayList;
import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.ColumnText;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfLayer;
import com.lowagie.text.pdf.PdfWriter;
public class MainClass {
public static void main(String[] args) throws Exception {
Document document = new Document();
PdfWriter writer = PdfWriter
.getInstance(document, new FileOutputStream("2.pdf"));
writer.setPdfVersion(PdfWriter.VERSION_1_5);
document.open();
PdfContentByte cb = writer.getDirectContent();
PdfLayer nested = new PdfLayer("Nested Layers", writer);
PdfLayer nested_1 = new PdfLayer("Nested Layer 1", writer);
PdfLayer nested_2 = new PdfLayer("Nested Layer 2", writer);
nested.addChild(nested_1);
nested.addChild(nested_2);
cb.beginLayer(nested);
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("nested layers"), 50, 775, 0);
cb.endLayer();
cb.beginLayer(nested_1);
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("nested layer 1"), 100, 800, 0);
cb.endLayer();
cb.beginLayer(nested_2);
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("nested layer 2"), 100, 750, 0);
cb.endLayer();
document.close();
}
}