Sophie

Sophie

distrib > Mandriva > 2007.0 > i586 > media > contrib-release > by-pkgid > 29e0da3ddcddab73ae8621fc62033227 > files > 83

itext-manual-1.4.5-1mdv2007.0.i586.rpm

/*
 * $Id: FixedFontWidth.java,v 1.3 2005/05/09 11:52:08 blowagie Exp $
 * $Name:  $
 *
 * 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.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.Font;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfWriter;

/**
 * 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
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        try {
        	// step 2
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("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 Font(bf)));
        }
        catch (Exception de) {
            de.printStackTrace();
        }
        // step 5
        document.close();
	}
}