Using Layer : Layer « PDF « Java Tutorial






import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.pdf.GrayColor;
import com.lowagie.text.pdf.PdfContentByte;
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"));
    document.open();
    PdfContentByte over = writer.getDirectContent();
    PdfContentByte under = writer.getDirectContentUnder();
    drawLayer(over, 70, 750, 150, 100);
    drawLayer(under, 70, 730, 150, 100);
    document.close();
  }

  public static void drawLayer(PdfContentByte cb, float llx, float lly, float w, float h) {
    cb.saveState();
    cb.setColorFill(new GrayColor(0.9f));
    cb.setColorStroke(new GrayColor(0.2f));
    cb.moveTo(llx, lly);
    cb.lineTo(llx + w / 4, lly + h / 3);
    cb.lineTo(llx + 7 * w / 8, lly + h / 3);
    cb.lineTo(llx + (2 * w) / 3, lly);
    cb.closePathFillStroke();
    cb.restoreState();
  }
}








29.70.Layer
29.70.1.Using Layer
29.70.2.Text on layer
29.70.3.Create PdfLayer
29.70.4.Show hide text with layer
29.70.5.Nested Layers
29.70.6.Grouped layers
29.70.7.Radio Group
29.70.8.not printed layer