Paint line : Line « PDF « Java Tutorial






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.PdfImportedPage;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfWriter;

public class MainClass {
  public static void main(String[] args) throws Exception {
    Document document = new Document(PageSize.A4);
    PdfReader reader = new PdfReader("1.pdf");
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("my.pdf"));
    document.open();
    PdfContentByte cb = writer.getDirectContent();
    PdfImportedPage page = writer.getImportedPage(reader, 1);
    cb.addTemplate(page, -0.5f, 0f, 0f, -0.5f, PageSize.A4.width() / 2, PageSize.A4.height());

    cb.setLineDash(20, 10, 10);
    cb.moveTo(0, PageSize.A4.height() / 2f);
    cb.lineTo(PageSize.A4.width(), PageSize.A4.height() / 2f);
    cb.stroke();
    cb.moveTo(PageSize.A4.width() / 2f, 0);
    cb.lineTo(PageSize.A4.width() / 2f, PageSize.A4.height());
    cb.stroke();
    document.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