Adding gray line b/w paragraph in iText 7

I am not sure how to add the gray line like in the image b/w paragraphs in Itext 7.

Should I use rectangle for this with very small width and the whole page length?

Rectangle rect= new Rectangle(1, 400);

How to get whole page length as opposed to hard code the same?

enter image description here

1 answer

  • answered 2020-09-14 21:07 Alexey Subach

    You can use the following piece of code:

    Document document = new Document(pdfDocument);
    
    document.add(new Paragraph("Hello"));
    document.add(new Div().setHeight(5).setBackgroundColor(ColorConstants.LIGHT_GRAY));
    document.add(new Paragraph("World"));
    
    document.close();
    

    To achieve the result as displayed on the image:

    result