/* * $Id: FontFactoryStyles.java,v 1.2 2005/04/08 12:56:46 blowagie Exp $ * $Name: $ * * This code is part of the 'iText Tutorial'. * You can find the complete tutorial at the following address: * http://itext.sourceforge.net/tutorial/ * * This code is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * itext-questions@lists.sourceforge.net */ package com.lowagie.examples.fonts.getting; import itext_test.Configuration; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import com.lowagie.text.Document; import com.lowagie.text.DocumentException; import com.lowagie.text.Font; import com.lowagie.text.FontFactory; import com.lowagie.text.Phrase; import com.lowagie.text.pdf.PdfWriter; /** * Changing the style of a FontFactory Font. */ public class FontFactoryStyles { /** * Changing the style of a FontFactory Font. * @param args no arguments needed */ public static void main(String[] args) throws Exception { System.out.println("Changing the style of a FontFactory font"); // step 1: creation of a document-object Document document = new Document(); // step 2: creation of the writer PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("fontfactorystyles.pdf")); // step 3: we open the document document.open(); // step 4: we add some content FontFactory.register(Configuration.fontsDirectory + File.separator + "arial.ttf"); FontFactory.register(Configuration.fontsDirectory + File.separator + "arialbd.ttf"); FontFactory.register(Configuration.fontsDirectory + File.separator + "ariali.ttf"); FontFactory.register(Configuration.fontsDirectory + File.separator + "arialbi.ttf"); Phrase myPhrase = new Phrase("This is font family Arial ", FontFactory.getFont("Arial", 8)); myPhrase.add(new Phrase("italic ", FontFactory.getFont("Arial", 8, Font.ITALIC))); myPhrase.add(new Phrase("bold ", FontFactory.getFont("Arial", 8, Font.BOLD))); myPhrase.add(new Phrase("bolditalic", FontFactory.getFont("Arial", 8, Font.BOLDITALIC))); document.add(myPhrase); // step 5: we close the document document.close(); } }