/* * This code is free software. It may only be copied or modified * if you include the following copyright notice: * * --> Copyright 2001 by Bruno Lowagie <-- * --> Copyright 2004 by Kazuya Ujihara <-- * * This code is example code of 'iText .NET'. * See http://www.ujihara.jp/iTextdotNET/examples.html * * 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. */ using System; using com.lowagie.text; using com.lowagie.text.pdf; using System.IO; using GDI=System.Drawing; public class Chap0201 { public static void Main(String[] args) { Console.WriteLine("Chapter 2 example 1: Chunks and fonts"); // step 1: creation of a document-object Document document = new Document(); // step 2: // we create a writer that listens to the document // and directs a PDF-stream to a file PdfWriter.getInstance(document, new FileStream("Chap0201.pdf", FileMode.Create)); // step 3: we open the document document.open(); // step 4: we add content to the document Font[] fonts = new Font[14]; int i = 0; fonts[i++] = FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL); fonts[i++] = FontFactory.getFont(FontFactory.COURIER, 12, Font.BOLD); fonts[i++] = FontFactory.getFont(FontFactory.COURIER, 12, Font.ITALIC); fonts[i++] = FontFactory.getFont(FontFactory.COURIER, 12, Font.BOLD | Font.ITALIC); fonts[i++] = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL); fonts[i++] = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD); fonts[i++] = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.ITALIC); fonts[i++] = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD | Font.ITALIC); fonts[i++] = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL); fonts[i++] = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD); fonts[i++] = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.ITALIC); fonts[i++] = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD | Font.ITALIC); fonts[i++] = FontFactory.getFont(FontFactory.SYMBOL, 12, Font.NORMAL); fonts[i++] = FontFactory.getFont(FontFactory.ZAPFDINGBATS, 12, Font.NORMAL); for (i = 0; i < fonts.Length; i++) { Chunk chunk = new Chunk("This is some", fonts[i]); document.add(new Phrase(chunk)); document.add(new Phrase(new Chunk(" font. ", fonts[i]).setTextRise((i % 2 == 0) ? -6 : 6))); } document.add(new Phrase(new Chunk("This text is underlined", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE)))); document.add(new Phrase(new Chunk("This font is of type ITALIC | STRIKETHRU", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.ITALIC | Font.STRIKETHRU)))); Chunk ck = new Chunk("This text has a yellow background color", FontFactory.getFont(FontFactory.HELVETICA, 12)); ck.setBackground(GDI.Color.Yellow); document.add(new Phrase(ck)); // step 5: we close the document document.close(); } }