Drawing Rectangle : Rectangle « PDF RTF « Java






Drawing Rectangle

Drawing Rectangle
import java.io.FileOutputStream;
import java.io.IOException;

import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfTemplate;
import com.lowagie.text.pdf.PdfWriter;

public class DrawRectanglePDF {
  public static void main(String[] args) {
    Document document = new Document();
    try {
      PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("DrawRectanglePDF.pdf"));
      document.open();

      PdfContentByte cb = writer.getDirectContent();
      PdfTemplate template = cb.createTemplate(500, 200);
      template.setLineWidth(2f);
      template.rectangle(2.5f, 2.5f, 495f, 95f);
      template.stroke();
      template.setLineWidth(12f);

      cb.addTemplate(template, 0, 1, -1, 0, 500, 200);
    } catch (Exception e) {
      System.err.println(e.getMessage());
    }
    document.close();
  }
}
           
       








itext.zip( 1,748 k)

Related examples in the same category

1.Shape: RectangleShape: Rectangle
2.Adding Rectangle to a ColumnAdding Rectangle to a Column