当前位置: 首页>>代码示例>>Java>>正文


Java FontFactory.getFont方法代码示例

本文整理汇总了Java中com.lowagie.text.FontFactory.getFont方法的典型用法代码示例。如果您正苦于以下问题:Java FontFactory.getFont方法的具体用法?Java FontFactory.getFont怎么用?Java FontFactory.getFont使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.lowagie.text.FontFactory的用法示例。


在下文中一共展示了FontFactory.getFont方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createfont

import com.lowagie.text.FontFactory; //导入方法依赖的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

示例2: EvalPDFReportBuilder

import com.lowagie.text.FontFactory; //导入方法依赖的package包/类
public EvalPDFReportBuilder(OutputStream outputStream) {
    document = new Document();
    try {
        pdfWriter = PdfWriter.getInstance(document, outputStream);
        pdfWriter.setStrictImageSequence(true);
        document.open();

        // attempting to handle i18n chars better
        // BaseFont evalBF = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.IDENTITY_H,
        // BaseFont.EMBEDDED);
        // paragraphFont = new Font(evalBF, 9, Font.NORMAL);
        // paragraphFont = new Font(Font.TIMES_ROMAN, 9, Font.NORMAL);

        titleTextFont = new Font(Font.TIMES_ROMAN, 22, Font.BOLD);
        boldTextFont = new Font(Font.TIMES_ROMAN, 10, Font.BOLD);
        questionTextFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, 11, Font.BOLD);
        paragraphFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.NORMAL);
        paragraphFontBold = FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD);
        frontTitleFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, frontTitleSize, Font.NORMAL);
        frontAuthorFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.NORMAL);
        frontInfoFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, 16, Font.NORMAL);
    } catch (Exception e) {
        throw UniversalRuntimeException.accumulate(e, "Unable to start PDF Report");
    }
}
 
开发者ID:sakaicontrib,项目名称:evaluation,代码行数:26,代码来源:EvalPDFReportBuilder.java

示例3: initFont

import com.lowagie.text.FontFactory; //导入方法依赖的package包/类
private static void initFont() {
	String fontName = ServerConfigurationService.getString("pdf.default.font");
	if (StringUtils.isNotBlank(fontName)) {
		FontFactory.registerDirectories();
		if (FontFactory.isRegistered(fontName)) {
			font = FontFactory.getFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
			boldFont = FontFactory.getFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10, Font.BOLD);
		} else {
			log.warn("Can not find font: " + fontName);
		}
	}
	if (font == null) {
		font = new Font();
		boldFont = new Font(Font.COURIER, 10, Font.BOLD);
	}
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:17,代码来源:SpreadsheetDataFileWriterPdf.java

示例4: initTable

import com.lowagie.text.FontFactory; //导入方法依赖的package包/类
/**
 * Initialize the main info holder table.
 * 
 * @throws BadElementException
 *             for errors during table initialization
 */
protected void initTable() throws BadElementException {
	tablePDF = new Table(this.model.getNumberOfColumns());
	tablePDF.setDefaultVerticalAlignment(Element.ALIGN_TOP);
	tablePDF.setCellsFitPage(true);
	tablePDF.setWidth(100);

	tablePDF.setPadding(2);
	tablePDF.setSpacing(0);

	// smallFont = FontFactory.getFont(FontFactory.HELVETICA, 7,
	// Font.NORMAL, new Color(0, 0, 0));
	smallFont = FontFactory.getFont("STSong-Light", "UniGB-UCS2-H", Font.DEFAULTSIZE);
}
 
开发者ID:8090boy,项目名称:gomall.la,代码行数:20,代码来源:SimpleChinesePdfView.java

示例5: preProcessPDF

import com.lowagie.text.FontFactory; //导入方法依赖的package包/类
public void preProcessPDF(Object document) throws IOException,
		BadElementException, DocumentException {
	Document pdf = (Document) document;
	pdf.setPageSize(PageSize.A4);
	pdf.open();

	ServletContext servletContext = (ServletContext) FacesContext
			.getCurrentInstance().getExternalContext().getContext();
	String logo = servletContext.getRealPath("") + File.separator
			+ "resources" + File.separator + "images" + File.separator
			+ "logo" + File.separator + "logo.png";
	Image image = Image.getInstance(logo);
	image.scaleAbsolute(100f, 50f);
	pdf.add(image);
	// add a couple of blank lines
	pdf.add(Chunk.NEWLINE);
	pdf.add(Chunk.NEWLINE);
	Font fontbold = FontFactory.getFont("Times-Roman", 16, Font.BOLD);
	fontbold.setColor(55, 55, 55);
	;
	pdf.add(new Paragraph("Transaction Summary", fontbold));
	// add a couple of blank lines
	pdf.add(Chunk.NEWLINE);
	pdf.add(Chunk.NEWLINE);
}
 
开发者ID:sudheerj,项目名称:primefaces-blueprints,代码行数:26,代码来源:TransactionSummaryController.java

示例6: writeFileNameSectionTitle

import com.lowagie.text.FontFactory; //导入方法依赖的package包/类
protected void writeFileNameSectionTitle(Document pdfDoc, String filenameLine) {
    Font font = FontFactory.getFont(FontFactory.COURIER, 10, Font.BOLD);

    Paragraph paragraph = new Paragraph();
    paragraph.setAlignment(Element.ALIGN_LEFT);
    Chunk chunk = new Chunk(filenameLine, font);
    chunk.setBackground(Color.LIGHT_GRAY, 5, 5, 5, 5);
    paragraph.add(chunk);

    //  blank line
    paragraph.add(new Chunk("", font));

    try {
        pdfDoc.add(paragraph);
    }
    catch (DocumentException e) {
        LOG.error("iText DocumentException thrown when trying to write content.", e);
        throw new RuntimeException("iText DocumentException thrown when trying to write content.", e);
    }
}
 
开发者ID:kuali,项目名称:kfs,代码行数:21,代码来源:CustomerLoadServiceImpl.java

示例7: generateReportErrorLog

import com.lowagie.text.FontFactory; //导入方法依赖的package包/类
/**
 * This method adds any error to the report
 * 
 * @param errorMsg
 */
private void generateReportErrorLog(String errorMsg) {
    try {
        Font font = FontFactory.getFont(FontFactory.HELVETICA, 9, Font.NORMAL);
        Paragraph p1 = new Paragraph();

        int rowsWritten = 0;
        if (!errorMsg.equals("")) {
            this.generateErrorColumnHeaders();

            p1 = new Paragraph(new Chunk(errorMsg, font));
            this.document.add(p1);
            line++;
        }
    }
    catch (Exception de) {
        throw new RuntimeException("DepreciationReport.generateReportErrorLog(List<String> reportLog) - Report Generation Failed: " + de.getMessage());
    }
}
 
开发者ID:kuali,项目名称:kfs,代码行数:24,代码来源:DepreciationReport.java

示例8: main

import com.lowagie.text.FontFactory; //导入方法依赖的package包/类
/**
 * Changing the style of a FontFactory Font.
 * 
 * @param args
 *            no arguments needed
 */
@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("fontfactorystyles.pdf"));

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

	String fontPathBase = new File(PdfTestBase.RESOURCES_DIR + "liberation-fonts-ttf").getAbsolutePath();
	// step 4: we add some content
	FontFactory.register(fontPathBase + "/LiberationSans-Regular.ttf");
	FontFactory.register(fontPathBase + "/LiberationSans-Italic.ttf");
	FontFactory.register(fontPathBase + "/LiberationSans-Bold.ttf");
	FontFactory.register(fontPathBase + "/LiberationSans-BoldItalic.ttf");
	
	
	Phrase myPhrase = new Phrase("This is font family Liberation Sans ", FontFactory.getFont("LiberationSans", 8));
	myPhrase.add(new Phrase("italic ", FontFactory.getFont("Arial", 8, Font.ITALIC)));
	myPhrase.add(new Phrase("bold ", FontFactory.getFont("Arial", 8, Font.BOLD)));
	myPhrase.add(new Phrase("bolditalic", FontFactory.getFont("Arial", 8, Font.BOLDITALIC)));
	document.add(myPhrase);

	// step 5: we close the document
	document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:37,代码来源:FontFactoryStylesTest.java

示例9: main

import com.lowagie.text.FontFactory; //导入方法依赖的package包/类
/**
 * Demonstrates some Paragraph functionality.
 * 
 */
@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
	PdfWriter.getInstance(document, PdfTestBase.getOutputStream("Paragraphs.pdf"));

	// step 3: we open the document
	document.open();
	// step 4:
	Paragraph p1 = new Paragraph(new Chunk("This is my first paragraph. ", FontFactory.getFont(
			FontFactory.HELVETICA, 10)));
	p1.add("The leading of this paragraph is calculated automagically. ");
	p1.add("The default leading is 1.5 times the fontsize. ");
	p1.add(new Chunk("You can add chunks "));
	p1.add(new Phrase("or you can add phrases. "));
	p1.add(new Phrase(
			"Unless you change the leading with the method setLeading, the leading doesn't change if you add text with another leading. This can lead to some problems.",
			FontFactory.getFont(FontFactory.HELVETICA, 18)));
	document.add(p1);
	Paragraph p2 = new Paragraph(new Phrase("This is my second paragraph. ", FontFactory.getFont(
			FontFactory.HELVETICA, 12)));
	p2.add("As you can see, it started on a new line.");
	document.add(p2);
	Paragraph p3 = new Paragraph("This is my third paragraph.", FontFactory.getFont(FontFactory.HELVETICA, 12));
	document.add(p3);

	// step 5: we close the document
	document.close();
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:37,代码来源:ParagraphsTest.java

示例10: newPara

import com.lowagie.text.FontFactory; //导入方法依赖的package包/类
private static Element newPara(String text, int alignment, int type) {
	Font font = FontFactory.getFont("Helvetica", 10, type, Color.BLACK);
	Paragraph p = new Paragraph(text, font);
	p.setAlignment(alignment);
	p.setLeading(font.getSize() * 1.2f);
	return p;
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:8,代码来源:MultiColumnSimpleTest.java

示例11: renderHeaders

import com.lowagie.text.FontFactory; //导入方法依赖的package包/类
/**
 * Effectue le rendu des headers.
 *
 * @param table
 *           MBasicTable
 * @param datatable
 *           Table
 * @throws BadElementException
 *            e
 */
protected void renderHeaders(final MBasicTable table, final Table datatable)
		throws BadElementException {
	final int columnCount = table.getColumnCount();
	final TableColumnModel columnModel = table.getColumnModel();
	// size of columns
	float totalWidth = 0;
	for (int i = 0; i < columnCount; i++) {
		totalWidth += columnModel.getColumn(i).getWidth();
	}
	final float[] headerwidths = new float[columnCount];
	for (int i = 0; i < columnCount; i++) {
		headerwidths[i] = 100f * columnModel.getColumn(i).getWidth() / totalWidth;
	}
	datatable.setWidths(headerwidths);
	datatable.setWidth(100f);

	// table header
	final Font font = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);
	datatable.getDefaultCell().setBorderWidth(2);
	datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
	// datatable.setDefaultCellGrayFill(0.75f);

	String text;
	Object value;
	for (int i = 0; i < columnCount; i++) {
		value = columnModel.getColumn(i).getHeaderValue();
		text = value != null ? value.toString() : "";
		datatable.addCell(new Phrase(text, font));
	}
	// end of the table header
	datatable.endHeaders();
}
 
开发者ID:javamelody,项目名称:javamelody,代码行数:43,代码来源:MPdfWriter.java

示例12: renderList

import com.lowagie.text.FontFactory; //导入方法依赖的package包/类
/**
 * Effectue le rendu de la liste.
 *
 * @param table
 *           MBasicTable
 * @param datatable
 *           Table
 * @throws BadElementException
 *            e
 */
protected void renderList(final MBasicTable table, final Table datatable)
		throws BadElementException {
	final int columnCount = table.getColumnCount();
	final int rowCount = table.getRowCount();
	// data rows
	final Font font = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL);
	datatable.getDefaultCell().setBorderWidth(1);
	datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
	// datatable.setDefaultCellGrayFill(0);
	Object value;
	String text;
	int horizontalAlignment;
	for (int k = 0; k < rowCount; k++) {
		for (int i = 0; i < columnCount; i++) {
			value = getValueAt(table, k, i);
			if (value instanceof Number || value instanceof Date) {
				horizontalAlignment = Element.ALIGN_RIGHT;
			} else if (value instanceof Boolean) {
				horizontalAlignment = Element.ALIGN_CENTER;
			} else {
				horizontalAlignment = Element.ALIGN_LEFT;
			}
			datatable.getDefaultCell().setHorizontalAlignment(horizontalAlignment);
			text = getTextAt(table, k, i);
			datatable.addCell(new Phrase(8, text != null ? text : "", font));
		}
	}
}
 
开发者ID:javamelody,项目名称:javamelody,代码行数:39,代码来源:MPdfWriter.java

示例13: createWriter

import com.lowagie.text.FontFactory; //导入方法依赖的package包/类
/**
 * We create a writer that listens to the document and directs a RTF-stream to out
 *
 * @param table
 *           MBasicTable
 * @param document
 *           Document
 * @param out
 *           OutputStream
 * @return DocWriter
 */
@Override
protected DocWriter createWriter(final MBasicTable table, final Document document,
		final OutputStream out) {
	final RtfWriter2 writer = RtfWriter2.getInstance(document, out);

	// title
	final String title = buildTitle(table);
	if (title != null) {
		final HeaderFooter header = new RtfHeaderFooter(new Paragraph(title));
		header.setAlignment(Element.ALIGN_LEFT);
		header.setBorder(Rectangle.NO_BORDER);
		document.setHeader(header);
		document.addTitle(title);
	}

	// advanced page numbers : x/y
	final Paragraph footerParagraph = new Paragraph();
	final Font font = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL);
	footerParagraph.add(new RtfPageNumber(font));
	footerParagraph.add(new Phrase(" / ", font));
	footerParagraph.add(new RtfTotalPageNumber(font));
	footerParagraph.setAlignment(Element.ALIGN_CENTER);
	final HeaderFooter footer = new RtfHeaderFooter(footerParagraph);
	footer.setBorder(Rectangle.TOP);
	document.setFooter(footer);

	return writer;
}
 
开发者ID:javamelody,项目名称:javamelody,代码行数:40,代码来源:MRtfWriter.java

示例14: getConversationPDF

import com.lowagie.text.FontFactory; //导入方法依赖的package包/类
public ByteArrayOutputStream getConversationPDF(Conversation conversation) {
    Font red = FontFactory
        .getFont(FontFactory.HELVETICA, 12f, Font.BOLD, new Color(0xFF, 0x00, 0x00));
    Font blue = FontFactory
        .getFont(FontFactory.HELVETICA, 12f, Font.ITALIC, new Color(0x00, 0x00, 0xFF));
    Font black = FontFactory.getFont(FontFactory.HELVETICA, 12f, Font.BOLD, Color.BLACK);

    Map<String, Font> colorMap = new HashMap<String, Font>();
    if (conversation != null) {
        Collection<JID> set = conversation.getParticipants();
        int count = 0;
        for (JID jid : set) {
            if (conversation.getRoom() == null) {
                if (count == 0) {
                    colorMap.put(jid.toString(), blue);
                }
                else {
                    colorMap.put(jid.toString(), red);
                }
                count++;
            }
            else {
                colorMap.put(jid.toString(), black);
            }
        }
    }


    return buildPDFContent(conversation, colorMap);
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:31,代码来源:ConversationUtils.java

示例15: generateReport

import com.lowagie.text.FontFactory; //导入方法依赖的package包/类
/**
 * Generates transaction report
 * 
 * @param errorSortedList list of error'd transactions
 * @param reportErrors map containing transactions and the errors associated with each transaction
 * @param reportSummary list of summary objects
 * @param runDate date report is run
 * @param title title of report
 * @param fileprefix file prefix of report file
 * @param destinationDirectory destination of where report file will reside
 */
public void generateReport(List<Transaction> errorSortedList, Map<Transaction, List<Message>> reportErrors, List<Summary> reportSummary, Date runDate, String title, String fileprefix, String destinationDirectory) {
    LOG.debug("generateReport() started");

    Font headerFont = FontFactory.getFont(FontFactory.COURIER, 8, Font.BOLD);
    Font textFont = FontFactory.getFont(FontFactory.COURIER, 8, Font.NORMAL);

    Document document = new Document(PageSize.A4.rotate());

    PageHelper helper = new PageHelper();
    helper.runDate = runDate;
    helper.headerFont = headerFont;
    helper.title = title;

    try {
        DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class);
        
        String filename = destinationDirectory + "/" + fileprefix + "_";
        filename = filename + dateTimeService.toDateTimeStringForFilename(runDate);
        filename = filename + ".pdf";
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
        writer.setPageEvent(helper);

        document.open();
        appendReport(document, headerFont, textFont, errorSortedList, reportErrors, reportSummary, runDate);
    }
    catch (DocumentException de) {
        LOG.error("generateReport() Error creating PDF report", de);
        throw new RuntimeException("Report Generation Failed: " + de.getMessage());
    }
    catch (FileNotFoundException fnfe) {
        LOG.error("generateReport() Error writing PDF report", fnfe);
        throw new RuntimeException("Report Generation Failed: Error writing to file " + fnfe.getMessage());
    }
    finally {
        if ((document != null) && document.isOpen()) {
            document.close();
        }
    }
}
 
开发者ID:VU-libtech,项目名称:OLE-INST,代码行数:51,代码来源:TransactionReport.java


注:本文中的com.lowagie.text.FontFactory.getFont方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。