Text with an absolute position using java.awt.Graphics2D object : Graphics2D « PDF « Java Tutorial






import java.awt.Graphics2D;
import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.PageSize;
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(PageSize.A4);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(
        "h.pdf"));
    document.open();
    PdfContentByte cb = writer.getDirectContent();
    Graphics2D graphics2D = cb.createGraphics(PageSize.A4.width(), PageSize.A4
        .height());
    graphics2D.drawString("Hello World", 36, 54);
    graphics2D.dispose();
    document.close();
  }
}








29.42.Graphics2D
29.42.1.Text with an absolute position using java.awt.Graphics2D object
29.42.2.Use java.awt.Font to draw strings
29.42.3.Create Graphics2D from PdfTemplate
29.42.4.Draw with Graphics2D