Tuesday 15, Apr 2025
We are moved to new domain
Click -> www.ehowtonow.com
Saturday, 3 June 2017

iText PDF 5 - Phrase and Paragraph examples

To create PDF file we need iText 5 jar. Download iText Jars from iText Website or Maven Repository

Maven Dependency

2.<dependency>
3. <groupid>com.itextpdf</groupid>
4. <artifactid>itextpdf</artifactid>
5. <version>5.5.11</version>
6.</dependency>

ParagraphSpacingBefore.java
01.package com.javatutorialcorner.itextpdf;
02. 
03.import com.itextpdf.text.Document;
04.import com.itextpdf.text.DocumentException;
05.import com.itextpdf.text.Paragraph;
06.import com.itextpdf.text.pdf.PdfWriter;
07.import java.io.File;
08.import java.io.FileOutputStream;
09.import java.io.IOException;
10. 
11.public class ParagraphSpacingBefore {
12.  
13. public static final String DEST = "C:/JTC/ParagraphSpacingBefore.pdf";
14.  
15.    public static void main(String[] args) throws IOException,
16.            DocumentException {
17.        File file = new File(DEST);
18.        file.getParentFile().mkdirs();
19.        new ParagraphSpacingBefore().createPdf(DEST);
20.    }
21.    public void createPdf(String filename) throws IOException, DocumentException {
22.        Document document = new Document();
23.        PdfWriter.getInstance(document, new FileOutputStream(filename));
24.        document.open();
25.        Paragraph paragraph1 = new Paragraph("First paragraph");
26.        Paragraph paragraph2 = new Paragraph("Second paragraph");
27.        paragraph2.setSpacingBefore(380f);
28.        document.add(paragraph1);
29.        document.add(paragraph2);
30.        document.close();
31.    }
32.}

Output




Reference : iText Website

Shop and help us

Flipkart Offer Snapdeal offer Amazon.in offer Amazon.com offer

Related Posts:

  • Blogger Comments
  • Facebook Comments
  • Disqus Comments

0 comments:

Post a Comment

Item Reviewed: iText PDF 5 - Phrase and Paragraph examples Rating: 5 Reviewed By: eHowToNow