Package com.lowagie.examples.fonts.styles

Source Code of com.lowagie.examples.fonts.styles.FontStylePropagation

/*
* $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.styles;

import java.io.IOException;

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

/**
* Explains the mechanism of Font Style Propagation.
*
* @author blowagie
*/

public class FontStylePropagation {

  /**
   * Explains the mechanism of Font Style Propagation
   *
   * @param args no arguments needed here
   */
  public static void main(String[] args) {

    System.out.println("Font Style Propagation");

    // 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.styles.FontStylePropagation.pdf"));

      // step 3: we open the document
      document.open();
      // step 4:
      LwgPhrase myPhrase = new LwgPhrase("Hello 1! ", new LwgFont(LwgFont.TIMES_ROMAN, 8, LwgFont.BOLD));
            myPhrase.add(new LwgPhrase("some other font ", new LwgFont(LwgFont.HELVETICA, 8)));
            myPhrase.add(new LwgPhrase("This is the end of the sentence.\n", new LwgFont(LwgFont.TIMES_ROMAN, 8, LwgFont.ITALIC)));
            document.add(myPhrase);
           
            myPhrase = new LwgPhrase(12);
            myPhrase.add(new LwgPhrase("Hello 2! ", new LwgFont(LwgFont.TIMES_ROMAN, 8, LwgFont.BOLD)));
            myPhrase.add(new LwgPhrase("This is the end of the sentence.\n", new LwgFont(LwgFont.TIMES_ROMAN, 8, LwgFont.ITALIC)));
            document.add(myPhrase);
           
            myPhrase = new LwgPhrase("Hello 3! ", FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, LwgFont.BOLD));
            myPhrase.add(new LwgPhrase("some other font ", FontFactory.getFont(FontFactory.HELVETICA, 8)));
            myPhrase.add(new LwgPhrase("This is the end of the sentence.\n", FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, LwgFont.ITALIC)));
            document.add(myPhrase);
           
            Paragraph myParagraph = new Paragraph("Hello 1bis! ", new LwgFont(LwgFont.TIMES_ROMAN, 8, LwgFont.BOLD));
            myParagraph.add(new Paragraph("This is the end of the sentence.", new LwgFont(LwgFont.TIMES_ROMAN, 8, LwgFont.ITALIC)));
            document.add(myParagraph);
           
            myParagraph = new Paragraph(12);
            myParagraph.add(new Paragraph("Hello 3bis! ", new LwgFont(LwgFont.TIMES_ROMAN, 8, LwgFont.BOLD)));
            myParagraph.add(new Paragraph("This is the end of the sentence.", new LwgFont(LwgFont.TIMES_ROMAN, 8, LwgFont.ITALIC)));
            document.add(myParagraph);
    } 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.styles.FontStylePropagation

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.