當前位置: 首頁>>代碼示例>>Java>>正文


Java Font類代碼示例

本文整理匯總了Java中com.lowagie.text.Font的典型用法代碼示例。如果您正苦於以下問題:Java Font類的具體用法?Java Font怎麽用?Java Font使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Font類屬於com.lowagie.text包,在下文中一共展示了Font類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createContent

import com.lowagie.text.Font; //導入依賴的package包/類
public void createContent(WebInput wi, DocInfo di)throws ControllerException {
	Document pdfDoc = di.getPdfDocument();
	try {
		pdfDoc.add(new Paragraph("Hello World!"));
		try {
			BaseFont bf = BaseFont.createFont("STSong-Light",
					"UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
			Font FontChinese = new Font(bf, 12, Font.NORMAL);
			String info=wi.getParameter("info");
			Paragraph p0 = new Paragraph(info, FontChinese);
			pdfDoc.add(p0);
			Paragraph p1 = new Paragraph("Beetle Web Framework 頁麵生成PDF文件演示!", FontChinese);
			pdfDoc.add(p1);
		} catch (Exception ex1) {
			throw new ControllerException(ex1);
		}
	} catch (DocumentException ex) {
		throw new ControllerException(ex);
	}
}
 
開發者ID:jbeetle,項目名稱:BJAF3.x,代碼行數:21,代碼來源:GenPdfController.java

示例2: createDoc

import com.lowagie.text.Font; //導入依賴的package包/類
public void createDoc() throws FileNotFoundException{
	 /** 創建Document對象(word文檔)  */
       Rectangle rectPageSize = new Rectangle(PageSize.A4);
       rectPageSize = rectPageSize.rotate();
       // 創建word文檔,並設置紙張的大小
       doc = new Document(PageSize.A4);
       file=new File(path+docFileName);
       fileOutputStream=new FileOutputStream(file);
       /** 建立一個書寫器與document對象關聯,通過書寫器可以將文檔寫入到輸出流中 */
       RtfWriter2.getInstance(doc, fileOutputStream );
       doc.open();
       //設置頁邊距,上、下25.4毫米,即為72f,左、右31.8毫米,即為90f  
       doc.setMargins(90f, 90f, 72f, 72f);
       //設置標題字體樣式,粗體、二號、華文中宋  
       tfont  = DocStyleUtils.setFontStyle("華文中宋", 22f, Font.BOLD);  
       //設置正文內容的字體樣式,常規、三號、仿宋_GB2312  
       bfont = DocStyleUtils.setFontStyle("仿宋_GB2312", 16f, Font.NORMAL);
}
 
開發者ID:wkeyuan,項目名稱:DWSurvey,代碼行數:19,代碼來源:DocExportUtil.java

示例3: textWidth

import com.lowagie.text.Font; //導入依賴的package包/類
protected static float textWidth(Font font, TimetableGridCell cell, boolean showRoom, boolean showInstructor, boolean showTime, boolean showPreference, boolean showDate) {
	float width = 0;
	if (cell.getNrNames() > 0) {
		for (String name: cell.getNames())
			width = Math.max(width, font.getBaseFont().getWidthPoint(name, font.getSize()));
	}
	if (showTime && cell.hasTime()) width = Math.max(width, font.getBaseFont().getWidthPoint(cell.getTime(), font.getSize()));
       if (showDate && cell.hasDate()) width = Math.max(width, font.getBaseFont().getWidthPoint(cell.getDate(), font.getSize()));
       if (showRoom && cell.getNrRooms() > 0)
       	for (String room: cell.getRooms())
       		width = Math.max(width, font.getBaseFont().getWidthPoint(room, font.getSize()));
       if (showInstructor && cell.getNrInstructors() > 0)
       	for (String instructor: cell.getInstructors())
       		width = Math.max(width, font.getBaseFont().getWidthPoint(instructor, font.getSize()));
       if (showPreference && cell.hasPreference()) 
       	width = Math.max(width, font.getBaseFont().getWidthPoint(cell.getPreference().replaceAll("\\<[^>]*>",""), font.getSize()));
       return width;
}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:19,代碼來源:ExportTimetablePDF.java

示例4: toPdf

import com.lowagie.text.Font; //導入依賴的package包/類
/**
 * Returns the PDF representation of this <CODE>PdfOutline</CODE>.
 *
 * @param writer the encryption information
 * @param os
 * @throws IOException
 */

public void toPdf(PdfWriter writer, OutputStream os) throws IOException {
    if (color != null && !color.equals(Color.black)) {
        put(PdfName.C, new PdfArray(new float[]{color.getRed()/255f,color.getGreen()/255f,color.getBlue()/255f}));
    }
    int flag = 0;
    if ((style & Font.BOLD) != 0)
        flag |= 2;
    if ((style & Font.ITALIC) != 0)
        flag |= 1;
    if (flag != 0)
        put(PdfName.F, new PdfNumber(flag));
    if (parent != null) {
        put(PdfName.PARENT, parent.indirectReference());
    }
    if (destination != null && destination.hasPage()) {
        put(PdfName.DEST, destination);
    }
    if (action != null)
        put(PdfName.A, action);
    if (count != 0) {
        put(PdfName.COUNT, new PdfNumber(count));
    }
    super.toPdf(writer, os);
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:33,代碼來源:PdfOutline.java

示例5: createfont

import com.lowagie.text.Font; //導入依賴的package包/類
/**
 * Create a font via the <code>FontFactory</code>
 * 
 * @param fontName The font name to create
 * @return The created <code>Font</code> object
 * 
 * @since 2.0.8
 */
private Font createfont(String fontName) {
	Font f1 = null;
	int pos=-1;
	do {
		f1 = FontFactory.getFont(fontName);
		
		if(f1.getBaseFont() != null) break;	// found a font, exit the do/while
		
		pos = fontName.lastIndexOf(' ');	// find the last space
		if(pos>0) {
			fontName = fontName.substring(0, pos );	// truncate it to the last space
		}
	} while(pos>0);
	return f1;
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:24,代碼來源:RtfDestinationFontTable.java

示例6: start

import com.lowagie.text.Font; //導入依賴的package包/類
public void start() throws DocumentException,IOException {
    //Create the font we are going to print to
    bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    font = new Font(bf, FONTSIZE, Font.NORMAL);
    boldFont = new Font(bf,FONTSIZE,Font.BOLD);

    //Create the document we are going to write to
    document = new Document();
    writer = PdfWriterFactory.newInstance(document, os, FontSettings.HELVETICA_10PT);
    // writer = PdfWriter.getInstance(document,os);
    // writer.setPageEvent(new EndPage());
    writer.setStrictImageSequence(true);

    document.setPageSize(PageSize.LETTER);
    document.open();
}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:17,代碼來源:PdfRecordPrinter.java

示例7: setToDefaultFamily

import com.lowagie.text.Font; //導入依賴的package包/類
/**
 * Sets the correct font name from the family name.
 * 
 * @param familyname The family name to set the name to.
 */
private void setToDefaultFamily(String familyname){
    switch (Font.getFamilyIndex(familyname)) {
        case Font.COURIER:
            this.fontName = "Courier";
            break;
        case Font.HELVETICA:
            this.fontName = "Arial";
            break;
        case Font.SYMBOL:
            this.fontName = "Symbol";
            this.charset = 2;
            break;
        case Font.TIMES_ROMAN:
            this.fontName = "Times New Roman";
            break;
        case Font.ZAPFDINGBATS:
            this.fontName = "Windings";
            break;
        default:
            this.fontName = familyname;
    }
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:28,代碼來源:RtfFont.java

示例8: compareTo

import com.lowagie.text.Font; //導入依賴的package包/類
/**
 * Compares this <code>RtfFont</code> to either a {@link com.lowagie.text.Font} or
 * an <code>RtfFont</code>.
 * 
 * @since 2.1.0
 */
public int compareTo(Object object) {
    if (object == null) {
        return -1;
    }
    if(object instanceof RtfFont) {
        if(this.getFontName().compareTo(((RtfFont) object).getFontName()) != 0) {
            return 1;
        } else {
            return super.compareTo(object);
        }
    } else if(object instanceof Font) {
        return super.compareTo(object);
    } else {
        return -3;
    }
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:23,代碼來源:RtfFont.java

示例9: main

import com.lowagie.text.Font; //導入依賴的package包/類
/**
 * Using a True Type Font.
 */
@Test
public void main() throws Exception {


	// 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,PdfTestBase.getOutputStream("truetype.pdf"));

	// step 3: we open the document
	document.open();

	String f = new File(PdfTestBase.RESOURCES_DIR + "liberation-fonts-ttf/LiberationMono-Regular.ttf").getAbsolutePath();
	// step 4: we add content to the document
	BaseFont bfComic = BaseFont.createFont(f, BaseFont.CP1252,	BaseFont.NOT_EMBEDDED);
	Font font = new Font(bfComic, 12);
	String text1 = "This is the quite popular Liberation Mono.";
	document.add(new Paragraph(text1, font));

	// step 5: we close the document
	document.close();
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:29,代碼來源:TrueTypeTest.java

示例10: main

import com.lowagie.text.Font; //導入依賴的package包/類
/**
    * Specifying an encoding.
    */
@Test
   public void main() throws Exception {
       
       
       // step 1: creation of a document-object
       Document document = new Document();
       
           
           // step 2: creation of the writer
           PdfWriter.getInstance(document, PdfTestBase.getOutputStream("fontencoding.pdf"));
           
           // step 3: we open the document
           document.open();
           
           // step 4: we add content to the document
           BaseFont helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
           Font font = new Font(helvetica, 12, Font.NORMAL);
           Chunk chunk = new Chunk("Sponsor this example and send me 1\u20ac. These are some special characters: \u0152\u0153\u0160\u0161\u0178\u017D\u0192\u02DC\u2020\u2021\u2030", font);
           document.add(chunk);
       
       // step 5: we close the document
       document.close();
   }
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:27,代碼來源:FontEncodingTest.java

示例11: main

import com.lowagie.text.Font; //導入依賴的package包/類
/**
 * Using FontSelector.
 */
@Test
public void main() throws Exception {
	// step 1
	Document document = new Document();
	// step 2
	PdfWriter.getInstance(document, PdfTestBase.getOutputStream("fontselection.pdf"));
	// step 3
	document.open();
	// step 4
	String text = "This text is the first verse of \u275dThe Iliad\u275e. It's not polytonic as it should be "
			+ "with \u2798 and \u279a entoation variants but that's all we have for now.\n\n"
			+ "\u2766\u00a0\u00a0\u039c\u03b7\u03bd\u03b9\u03bd \u03b1\u03b5\u03b9\u03b4\u03b5, \u03b8\u03b5\u03b1, \u03a0\u03b7\u03bb\u03b7\u03b9\u03b1\u03b4\u03b5\u03c9 \u0391\u03c7\u03b9\u03bb\u03b7\u03bf\u03c2";
	FontSelector sel = new FontSelector();
	sel.addFont(new Font(Font.TIMES_ROMAN, 12));
	sel.addFont(new Font(Font.ZAPFDINGBATS, 12));
	sel.addFont(new Font(Font.SYMBOL, 12));
	Phrase ph = sel.process(text);
	document.add(new Paragraph(ph));
	// step 5
	document.close();

}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:26,代碼來源:FontSelectionTest.java

示例12: writePageAnchor

import com.lowagie.text.Font; //導入依賴的package包/類
protected void writePageAnchor(int pageIndex) throws DocumentException 
{
	Map<Attribute,Object> attributes = new HashMap<Attribute,Object>();
	fontUtil.getAttributesWithoutAwtFont(attributes, new JRBasePrintText(jasperPrint.getDefaultStyleProvider()));
	Font pdfFont = getFont(attributes, getLocale(), false);
	Chunk chunk = new Chunk(" ", pdfFont);
	
	chunk.setLocalDestination(JR_PAGE_ANCHOR_PREFIX + reportIndex + "_" + (pageIndex + 1));

	tagHelper.startPageAnchor();
	
	ColumnText colText = new ColumnText(pdfContentByte);
	colText.setSimpleColumn(
		new Phrase(chunk),
		0,
		pageFormat.getPageHeight(),
		1,
		1,
		0,
		Element.ALIGN_LEFT
		);

	colText.go();

	tagHelper.endPageAnchor();
}
 
開發者ID:TIBCOSoftware,項目名稱:jasperreports,代碼行數:27,代碼來源:JRPdfExporter.java

示例13: main

import com.lowagie.text.Font; //導入依賴的package包/類
/**
 * Extended font example.
 * 
 * 
 */
@Test
public void main() throws Exception {
	Document document = new Document();
	RtfWriter2.getInstance(document, PdfTestBase.getOutputStream("ExtendedFont.rtf"));
	document.open();

	// Create a RtfFont with the desired font name.
	RtfFont msComicSans = new RtfFont("Comic Sans MS");

	// Use the RtfFont like any other Font.
	document.add(new Paragraph("This paragraph uses the" + " Comic Sans MS font.", msComicSans));

	// Font size, font style and font colour can also be specified.
	RtfFont bigBoldGreenArial = new RtfFont("Arial", 36, Font.BOLD, Color.GREEN);

	document.add(new Paragraph("This is a really big bold green Arial text", bigBoldGreenArial));
	document.close();
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:24,代碼來源:ExtendedFontTest.java

示例14: testSimplePdf

import com.lowagie.text.Font; //導入依賴的package包/類
@Test
public void testSimplePdf() throws FileNotFoundException, DocumentException {

	BaseFont font = null;
	try {
		font = BaseFont.createFont("LiberationSerif-Regular.ttf", BaseFont.IDENTITY_H, false);
	}
	catch (IOException ioe) {
		// nop
	}
	Document document = null;
	try {
		document = PdfTestBase.createPdf("unicode.pdf");
		// new page with a rectangle
		document.open();			
		Element unicodeParagraph = new Paragraph(INPUT, new Font(font, 12));
		document.add(unicodeParagraph);
	} 
	finally {
		// close document
		if (document != null)
			document.close();
	}
}
 
開發者ID:albfernandez,項目名稱:itext2,代碼行數:25,代碼來源:UnicodePdfTest.java

示例15: PdfRecordPrinter

import com.lowagie.text.Font; //導入依賴的package包/類
public PdfRecordPrinter(HttpServletRequest request, OutputStream os) throws DocumentException,IOException {
    this.request = request;
    this.os = os;
    formatter = new SimpleDateFormat("dd-MMM-yyyy");

    //Create the font we are going to print to
    bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    font = new Font(bf, FONTSIZE, Font.NORMAL);
    boldFont = new Font(bf,FONTSIZE,Font.BOLD);

    //Create the document we are going to write to
    document = new Document();
    writer = PdfWriter.getInstance(document,os);
    writer.setPageEvent(new EndPage());
    writer.setStrictImageSequence(true);

    document.setPageSize(PageSize.LETTER);
    
    document.open();
}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:21,代碼來源:PdfRecordPrinter.java


注:本文中的com.lowagie.text.Font類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。