Package com.lowagie.examples.fonts.styles

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

/*
* $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 com.lowagie.text.LwgDocument;
import com.lowagie.text.LwgFont;
import com.lowagie.text.LwgPageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfWriter;
import org.geoforge.demo.GfrFileOutputStream;

/**
* Changing the width of font glyphs.
*/
public class FixedFontWidth {

  /**
   * Changing the width of font glyphs.
   * @param args no arguments needed
   */
  public static void main(String[] args) {
        System.out.println("Fixed Font Width");
        // step 1
        LwgDocument document = new LwgDocument(LwgPageSize.A4, 50, 50, 50, 50);
        try {
          // step 2
            PdfWriter.getInstance(
                    document,
                    new GfrFileOutputStream("com.lowagie.examples.fonts.styles.FixedFontWidth.pdf"));
            // step 3
            document.open();
            // step 4
            BaseFont bf = BaseFont.createFont("Helvetica", "winansi", false, false, null, null);
            int widths[] = bf.getWidths();
            for (int k = 0; k < widths.length; ++k) {
                if (widths[k] != 0)
                    widths[k] = 1000;
            }
            bf.setForceWidthsOutput(true);
            document.add(new Paragraph("A big text to show Helvetica with fixed width.", new LwgFont(bf)));
        }
        catch (Exception de) {
            de.printStackTrace();
        }
        // step 5
        document.close();
  }
}
TOP

Related Classes of com.lowagie.examples.fonts.styles.FixedFontWidth

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.