Suppose that you have the following text file: jekyll_hyde.txt
How do we convert it to a PDF that looks like this:
When using iText 7, you'd need code like this:
public void createPdf(String dest) throws IOException {
PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
Document document = new Document(pdf)
.setTextAlignment(TextAlignment.JUSTIFIED);
Rectangle[] columns = {
new Rectangle(36, 36, 254, 770),
new Rectangle(305, 36, 254, 770)};
document.setRenderer(new ColumnDocumentRenderer(document, columns));
BufferedReader br = new BufferedReader(new FileReader(TEXT));
String line;
PdfFont normal = PdfFontFactory.createFont(FontConstants.TIMES_ROMAN);
PdfFont bold = PdfFontFactory.createFont(FontConstants.TIMES_BOLD);
boolean title = true;
while ((line = br.readLine()) != null) {
document.add(new Paragraph(line).setFont(title ? bold : normal));
title = line.isEmpty();
}
document.close();
}
Source: developers.itextpdf.com and the iText 7: Building Blocks tutorial.