The com.itextpdf.text.Paragraph
class represent a paragraph in PDF document. The following example show you how to create a simple paragraph. First we create a Paragraph
object and then add some texts into it using the Chunk
object.
package org.kodejava.itextpdf;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
public class ParagraphDemo {
public static void main(String[] args) {
Document doc = new Document();
try {
FileOutputStream fos = new FileOutputStream("ParagraphDemo.pdf");
PdfWriter.getInstance(doc, fos);
doc.open();
String content = "The quick brown fox jumps over the lazy dog";
Paragraph paragraph = new Paragraph();
for (int i = 0; i < 20; i++) {
Chunk chunk = new Chunk(content);
paragraph.add(chunk);
}
doc.add(paragraph);
doc.close();
} catch (DocumentException | FileNotFoundException e) {
e.printStackTrace();
}
}
}
Maven Dependencies
<!-- https://search.maven.org/remotecontent?filepath=com/itextpdf/itextpdf/5.5.13.3/itextpdf-5.5.13.3.jar -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.13.3</version>
</dependency>
Latest posts by Wayan (see all)
- How do I build simple search page using ZK and Spring Boot? - March 8, 2023
- How do I calculate days between two dates excluding weekends and holidays? - January 12, 2023
- How do I discover the quarter of a given date? - January 11, 2023