To create PDF file we need iText 5 jar. Download iText Jars from iText Website or Maven Repository
Bullets.java
Output
Reference : iText Website
Maven Dependency
com.itextpdf itextpdf 5.5.11
Bullets.java
package com.javatutorialcorner.itextpdf; import com.itextpdf.text.Chunk; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Font; import com.itextpdf.text.Font.FontFamily; import com.itextpdf.text.Paragraph; import com.itextpdf.text.Phrase; import com.itextpdf.text.pdf.BaseFont; import com.itextpdf.text.pdf.PdfWriter; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; public class Bullets { public static final String DEST = "C:/JTC/Bullets.pdf"; public static final String FONT = "C:/JTC/FreeSans.ttf"; public static final String[] ITEMS = { "Insurance system", "Agent", "Agency", "Agent Enrollment", "Agent Settings", "Appointment", "Continuing Education", "Hierarchy", "Recruiting", "Contract", "Message", "Correspondence", "Licensing", "Party" }; public static void main(String[] args) throws IOException, DocumentException { File file = new File(DEST); file.getParentFile().mkdirs(); new Bullets().createPdf(DEST); } public void createPdf(String dest) throws DocumentException, IOException { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(dest)); document.open(); Font zapfdingbats = new Font(FontFamily.ZAPFDINGBATS, 8); Font font = new Font(); Chunk bullet = new Chunk(String.valueOf((char) 108), zapfdingbats); Paragraph p = new Paragraph("Items can be split if they don't fit at the end: ", font); for (String item: ITEMS) { p.add(bullet); p.add(new Phrase(" " + item + " ", font)); } document.add(p); document.add(Chunk.NEWLINE); p = new Paragraph("Items can't be split if they don't fit at the end: ", font); for (String item: ITEMS) { p.add(bullet); p.add(new Phrase("\u00a0" + item.replace(' ', '\u00a0') + " ", font)); } document.add(p); document.add(Chunk.NEWLINE); BaseFont bf = BaseFont.createFont(FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Font f = new Font(bf, 12); p = new Paragraph("Items can't be split if they don't fit at the end: ", f); for (String item: ITEMS) { p.add(new Phrase("\u2022\u00a0" + item.replace(' ', '\u00a0') + " ", f)); } document.add(p); document.close(); } }
Output
Reference : iText Website
0 comments:
Post a Comment