Text on layer : Layer « PDF « Java Tutorial






import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.pdf.BaseFont;
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();
    PdfLayer layer = new PdfLayer("Do you see me?", writer);

    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
    PdfContentByte cb = writer.getDirectContent();
    cb.beginText();
    cb.setTextMatrix(50, 790);
    cb.setLeading(24);
    cb.setFontAndSize(bf, 18);
    cb.showText("Do you see me?");
    cb.beginLayer(layer);
    cb.newlineShowText("this is a test");
    cb.endLayer();
    cb.endText();
    document.close();
  }
}








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