Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert blank lines in PDF?

Tags:

itext

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

How can I achieve this?

like image 489
Thanuja Avatar asked Nov 11 '10 19:11

Thanuja


People also ask

Can you add grid lines to a PDF?

Choose View > Show/Hide > Rulers & Grids > Rulers. Do one of the following: Drag down from the horizontal ruler to create a horizontal guide, or drag right from the vertical ruler to create a vertical guide.

Can we draw a line in PDF?

Draw on any PDF document. Select the marker icon in the Comment toolbar to activate the Draw Free Form tool. Draw on the PDF. You can change line color, thickness, and opacity in the Comment toolbar. Once you're finished, save your PDF.


1 Answers

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

like image 197
Bill the Lizard Avatar answered Sep 23 '22 06:09

Bill the Lizard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!