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


Java Font.setColor方法代码示例

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


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

示例1: buildPdfPCell

import com.itextpdf.text.Font; //导入方法依赖的package包/类
private PdfPCell buildPdfPCell(HeaderFooter phf,String text,int type){
	PdfPCell cell=new PdfPCell();
	cell.setPadding(0);
	cell.setBorder(Rectangle.NO_BORDER);
	Font font=FontBuilder.getFont(phf.getFontFamily(), phf.getFontSize(), phf.isBold(), phf.isItalic(),phf.isUnderline());
	String fontColor=phf.getForecolor();
	if(StringUtils.isNotEmpty(fontColor)){
		String[] color=fontColor.split(",");
		font.setColor(Integer.valueOf(color[0]), Integer.valueOf(color[1]), Integer.valueOf(color[2]));			
	}
	Paragraph graph=new Paragraph(text,font);
	cell.setPhrase(graph);
	switch(type){
	case 1:
		cell.setHorizontalAlignment(Element.ALIGN_LEFT);
		break;
	case 2:
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		break;
	case 3:
		cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
		break;
	}
	cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
	return cell;
}
 
开发者ID:youseries,项目名称:ureport,代码行数:27,代码来源:PageHeaderFooterEvent.java

示例2: onEndPage

import com.itextpdf.text.Font; //导入方法依赖的package包/类
/**
 * Adds a header to every page
 * @see com.itextpdf.text.pdf.PdfPageEventHelper#onEndPage(
 *      com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document)
 */
public void onEndPage(PdfWriter writer, Document document) {
	PdfPTable table = new PdfPTable(3);
	try {
		table.setWidths(new int[]{40,5,10});
		table.setTotalWidth(100);
		table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
		table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
		Font font=new Font(chineseFont,8);
		font.setColor(new BaseColor(55,55,55));
		Paragraph paragraph=new Paragraph("第   "+writer.getPageNumber()+" 页   共",font);
		paragraph.setAlignment(Element.ALIGN_RIGHT);
		table.addCell(paragraph);
		Image img=Image.getInstance(total);
		img.scaleAbsolute(28, 28);
		PdfPCell cell = new PdfPCell(img);
		cell.setBorder(Rectangle.NO_BORDER);
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		table.addCell(cell);
		PdfPCell c = new PdfPCell(new Paragraph("页",font));
		c.setHorizontalAlignment(Element.ALIGN_LEFT);
		c.setBorder(Rectangle.NO_BORDER);
		table.addCell(c);
		float center=(document.getPageSize().getWidth())/2-120/2;
		table.writeSelectedRows(0, -1,center,30, writer.getDirectContent());
	}
	catch(DocumentException de) {
		throw new ExceptionConverter(de);
	}
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:35,代码来源:PdfReportPageNumber.java

示例3: getFont

import com.itextpdf.text.Font; //导入方法依赖的package包/类
public Font getFont(final String fontname, final String encoding,
		final boolean embedded, final float size, final int style,
		final BaseColor color) {
	BaseFont bf = null;
	try {
		bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",
				BaseFont.NOT_EMBEDDED);
	} catch (Exception e) {
		e.printStackTrace();
	}
	Font font = new Font(bf, size, style, color);
	font.setColor(color);
	return font;
}
 
开发者ID:jeffreyning,项目名称:nh-micro,代码行数:15,代码来源:AsianFontProvider.java

示例4: createFont

import com.itextpdf.text.Font; //导入方法依赖的package包/类
protected Font createFont(TextChunk textChunk) {
	Font font = new Font(chineseFont);
	if (textChunk.getFontColor() != null) {
		int[] colors = textChunk.getFontColor();
		font.setColor(new BaseColor(colors[0], colors[1], colors[2]));
	}
	if (textChunk.getFontSize() > 0) {
		font.setSize(textChunk.getFontSize());
	}
	font.setStyle(textChunk.getFontStyle());
	return font;
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:13,代码来源:AbstractPdfReportBuilder.java

示例5: getFont

import com.itextpdf.text.Font; //导入方法依赖的package包/类
private Font getFont(String color, boolean bold) throws Exception {
	Font font = FontFactory.getFont(BscConstants.PDF_ITEXT_FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
	int rgb[] = SimpleUtils.getColorRGB2(color);
	BaseColor baseColor = new BaseColor(rgb[0], rgb[1], rgb[2]);
	font.setSize(9);
	font.setColor(baseColor);
	return font;
}
 
开发者ID:billchen198318,项目名称:bamboobsc,代码行数:9,代码来源:PersonalReportPdfCommand.java

示例6: getFont

import com.itextpdf.text.Font; //导入方法依赖的package包/类
private Font getFont(String color, boolean bold) throws Exception {
	Font font = FontFactory.getFont(BscConstants.PDF_ITEXT_FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
	int rgb[] = SimpleUtils.getColorRGB2(color);
	BaseColor baseColor = new BaseColor(rgb[0], rgb[1], rgb[2]);
	font.setSize(9);
	if (bold) {
		font.setSize(14);
		font.setStyle(Font.BOLD);
	}		
	font.setColor(baseColor);
	return font;
}
 
开发者ID:billchen198318,项目名称:bamboobsc,代码行数:13,代码来源:KpiReportPdfCommand.java

示例7: buildPdfDocument

import com.itextpdf.text.Font; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected void buildPdfDocument(Map<String, Object> model, Document doc,
        PdfWriter writer, HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    // get data model which is passed by the Spring container
    List<HrmsLogin> users = (List<HrmsLogin>) model.get("allUsers");
     
    doc.add(new Paragraph("Master List of Users"));
     
    PdfPTable table = new PdfPTable(4);
    table.setWidthPercentage(100.0f);
    table.setWidths(new float[] {3.0f, 2.0f, 2.0f, 2.0f});
    table.setSpacingBefore(10);
     
    // define font for table header row
    Font font = FontFactory.getFont(FontFactory.HELVETICA);
    font.setColor(BaseColor.WHITE);
     
    // define table header cell
    PdfPCell cell = new PdfPCell();
    cell.setBackgroundColor(BaseColor.BLUE);
    cell.setPadding(5);
     
    // write table header
    cell.setPhrase(new Phrase("Employee ID", font));
    table.addCell(cell);
     
    cell.setPhrase(new Phrase("Username", font));
    table.addCell(cell);
	 
    cell.setPhrase(new Phrase("Password", font));
    table.addCell(cell);
     
    cell.setPhrase(new Phrase("Role", font));
    table.addCell(cell);
     
   
     
    // write table row data
    for (HrmsLogin user : users) {
        table.addCell(user.getHrmsEmployeeDetails().getEmpId()+"");
        table.addCell(user.getUsername());
        table.addCell(user.getPassword());
        table.addCell(user.getRole());
        
    }
     
    doc.add(table);
     
}
 
开发者ID:PacktPublishing,项目名称:Spring-MVC-Blueprints,代码行数:52,代码来源:HRPDFBuilderImpl.java

示例8: pdfWrite

import com.itextpdf.text.Font; //导入方法依赖的package包/类
@Test
public void pdfWrite() {
    try {
        //1.创建一个document
        Document document = new Document();


        //2.定义pdfWriter,指明文件输出流输出到一个文件
        PdfWriter.getInstance(document, new FileOutputStream(filePath));

        //3.打开文档
        document.open();


        //字体
        Font font = new Font();
        font.setFamily("STSongStd-Light");
        //颜色
        font.setColor(BaseColor.BLUE);
        //4.添加内容
        Paragraph content = new Paragraph("xxx!", font);


        document.add(content);


        //添加段落
        for (int i = 0; i < 100; i++) {
            document.add(new Paragraph("HelloWorld"
                    + ","
                    + "Hello iText"
                    + ","
                    + "HelloxDuan"));
        }

        //5.关闭
        document.close();
    } catch (Exception e) {

    }

}
 
开发者ID:ansafari,项目名称:melon,代码行数:43,代码来源:ItextPdfTest.java

示例9: buildPdfDocument

import com.itextpdf.text.Font; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
   protected void buildPdfDocument(Map<String, Object> model, Document doc,
           PdfWriter writer, HttpServletRequest request, HttpServletResponse response)
           throws Exception {
       // get data model which is passed by the Spring container
       List<Answer> listAnswers = (List<Answer>) model.get("listAnswers");
        
       doc.add(new Paragraph("Here's your Answers"));
        
       PdfPTable table = new PdfPTable(4);
       table.setWidthPercentage(100.0f);
       table.setWidths(new float[] {3.0f, 2.0f, 2.0f, 2.0f});
       table.setSpacingBefore(10);
        
       // define font for table header row
       Font font = FontFactory.getFont(FontFactory.HELVETICA);
       font.setColor(BaseColor.WHITE);
        
       // define table header cell
       PdfPCell cell = new PdfPCell();
       cell.setBackgroundColor(BaseColor.BLUE);
       cell.setPadding(5);
        
       // write table header
       cell.setPhrase(new Phrase("Answer 1", font));
       table.addCell(cell);
        
       cell.setPhrase(new Phrase("Answer 2", font));
       table.addCell(cell);

       cell.setPhrase(new Phrase("Answer 3", font));
       table.addCell(cell);
        
       cell.setPhrase(new Phrase("Published Date", font));
       table.addCell(cell);
        
       // write table row data
       for (Answer answer : listAnswers) {
           table.addCell(answer.getAnswer1());
           table.addCell(answer.getAnswer2());
           table.addCell(answer.getAnswer3());
           table.addCell(answer.getAnsweredDate());
           //table.addCell(String.valueOf(answer.getPrice()));
       }
        
       doc.add(table);
        
   }
 
开发者ID:TransformCore,项目名称:BIS-BDT-Citizen,代码行数:50,代码来源:PdfView.java

示例10: HeaderFooter

import com.itextpdf.text.Font; //导入方法依赖的package包/类
public HeaderFooter(int fontSize) {
	mFont = new Font();
	mFont.setColor(BaseColor.BLACK);
	mFont.setSize(fontSize);
}
 
开发者ID:RayTW,项目名称:RComicDownloader,代码行数:6,代码来源:PDF.java


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