/** * Example written by Bruno Lowagie in answer to: * http://thread.gmane.org/gmane.comp.java.lib.itext.general/65892 * * Some text displayed using a Small Caps font. */ package sandbox.fonts; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Font; import com.itextpdf.text.Paragraph; import com.itextpdf.text.pdf.BaseFont; import com.itextpdf.text.pdf.PdfWriter; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import sandbox.WrapToTest; @WrapToTest public class SmallCapsExample { public static final String DEST = "results/fonts/small_caps.pdf"; public static final String FONT = "resources/fonts/Delicious-SmallCaps.otf"; public static void main(String[] args) throws IOException, DocumentException { File file = new File(DEST); file.getParentFile().mkdirs(); new SmallCapsExample().createPdf(DEST); } public void createPdf(String dest) throws IOException, DocumentException { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(DEST)); document.open(); BaseFont bf = BaseFont.createFont(FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Font f = new Font(bf, 12); Paragraph p = new Paragraph("This is some text displayed using a Small Caps font.", f); document.add(p); document.close(); } }