Add shape to an existing Pdf document : Line « PDF « Java Tutorial






import java.io.FileOutputStream;

import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;

public class MainClass {
  public static void main(String[] args) throws Exception {
    PdfReader reader = new PdfReader("HelloWorldRead.pdf");
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("HelloWorldStamper2.pdf"));
    
    int total = reader.getNumberOfPages() + 1;
    for (int i = 1; i < total; i++) {
      stamper.setRotateContents(false);
      PdfContentByte over = stamper.getOverContent(i);

      over.setRGBColorStroke(0xFF, 0x00, 0x00);
      over.setLineWidth(5f);
      over.ellipse(250, 450, 350, 550);
      over.stroke();
      
    }
    stamper.close();
  }

}








29.43.Line
29.43.1.set LineCap
29.43.2.Add shape to an existing Pdf document
29.43.3.Paint line
29.43.4.Set line width
29.43.5.PdfContentByte.LINE_CAP_BUTT
29.43.6.PdfContentByte.LINE_CAP_ROUND
29.43.7.PdfContentByte.LINE_CAP_PROJECTING_SQUARE
29.43.8.PdfContentByte.LINE_JOIN_MITER
29.43.9.Miter Limit
29.43.10.Line Dash