Package com.lowagie.examples.fonts

Source Code of com.lowagie.examples.fonts.StandardType1Fonts

/*
* $Id$
*
* This code is part of the 'iText Tutorial'.
* You can find the complete tutorial at the following address:
* http://itextdocs.lowagie.com/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;

import java.io.IOException;

import com.lowagie.text.LwgDocument;
import com.lowagie.text.DocumentException;
import com.lowagie.text.LwgFont;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
import org.geoforge.demo.GfrFileOutputStream;

/**
* Generates a PDF with the 14 Standard Type 1 Fonts.
*
* @author blowagie
*/

public class StandardType1Fonts {

  /**
   * Generates a PDF file with the 14 standard Type 1 Fonts
   *
   * @param args no arguments needed here
   */
  public static void main(String[] args) {

    System.out.println("Standard Type 1 fonts");

    // step 1: creation of a document-object
    LwgDocument document = new LwgDocument();
    try {
      // step 2:
      // we create a writer that listens to the document
      PdfWriter.getInstance(document,
          new GfrFileOutputStream("com.lowagie.examples.fonts.StandardType1Fonts.pdf"));

      // step 3: we open the document
      document.open();
      // step 4:
     
      // the 14 standard fonts in PDF: do not use this Font constructor!
      // this is for demonstration purposes only, use FontFactory!
      LwgFont[] fonts = new LwgFont[14];
      fonts[0] = new LwgFont(LwgFont.COURIER, LwgFont.DEFAULTSIZE, LwgFont.NORMAL);
      fonts[1] = new LwgFont(LwgFont.COURIER, LwgFont.DEFAULTSIZE, LwgFont.ITALIC);
      fonts[2] = new LwgFont(LwgFont.COURIER, LwgFont.DEFAULTSIZE, LwgFont.BOLD);
      fonts[3] = new LwgFont(LwgFont.COURIER, LwgFont.DEFAULTSIZE, LwgFont.BOLD | LwgFont.ITALIC);
      fonts[4] = new LwgFont(LwgFont.HELVETICA, LwgFont.DEFAULTSIZE, LwgFont.NORMAL);
      fonts[5] = new LwgFont(LwgFont.HELVETICA, LwgFont.DEFAULTSIZE, LwgFont.ITALIC);
      fonts[6] = new LwgFont(LwgFont.HELVETICA, LwgFont.DEFAULTSIZE, LwgFont.BOLD);
      fonts[7] = new LwgFont(LwgFont.HELVETICA, LwgFont.DEFAULTSIZE, LwgFont.BOLDITALIC);
      fonts[8] = new LwgFont(LwgFont.TIMES_ROMAN, LwgFont.DEFAULTSIZE, LwgFont.NORMAL);
      fonts[9] = new LwgFont(LwgFont.TIMES_ROMAN, LwgFont.DEFAULTSIZE, LwgFont.ITALIC);
      fonts[10] = new LwgFont(LwgFont.TIMES_ROMAN, LwgFont.DEFAULTSIZE, LwgFont.BOLD);
      fonts[11] = new LwgFont(LwgFont.TIMES_ROMAN, LwgFont.DEFAULTSIZE, LwgFont.BOLDITALIC);
      fonts[12] = new LwgFont(LwgFont.SYMBOL);
      fonts[13] = new LwgFont(LwgFont.ZAPFDINGBATS);
      // add the content
      for (int i = 0; i < 14; i++) {
        document.add(new Paragraph("quick brown fox jumps over the lazy dog", fonts[i]));
      }
    } catch (DocumentException de) {
      System.err.println(de.getMessage());
    } catch (IOException ioe) {
      System.err.println(ioe.getMessage());
    }

    // step 5: we close the document
    document.close();
  }
}
TOP

Related Classes of com.lowagie.examples.fonts.StandardType1Fonts

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.