How to insert blank lines in PDF?

I am creating a PDF using iText. I want to insert blank lines between paragraphs and tables.

How can I achieve this?


Solution 1:

You can trigger a newline by inserting Chunk.NEWLINE into your document. Here's an example.

public static void main(String args[]) {
    try {
        // create a new document
        Document document = new Document( PageSize.A4, 20, 20, 20, 20 );
        PdfWriter.getInstance( document, new FileOutputStream( "HelloWorld.pdf" ) );

        document.open();

        document.add( new Paragraph( "Hello, World!" ) );
        document.add( new Paragraph( "Hello, World!" ) );

        // add a couple of blank lines
        document.add( Chunk.NEWLINE );
        document.add( Chunk.NEWLINE );

        // add one more line with text
        document.add( new Paragraph( "Hello, World!" ) );

        document.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
}

Below is a screen shot showing part of the PDF that the code above produces.

Hello PDF with blank lines inserted

Solution 2:

And to insert blank line between tables you can use these both methods

table.setSpacingBefore();      

table.setSpacingAfter();       

Solution 3:

You can use "\n" in Paragraph

document.add(new Paragraph("\n\n"));