本文整理汇总了Java中com.itextpdf.text.Font类的典型用法代码示例。如果您正苦于以下问题:Java Font类的具体用法?Java Font怎么用?Java Font使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Font类属于com.itextpdf.text包,在下文中一共展示了Font类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: cellRodape
import com.itextpdf.text.Font; //导入依赖的package包/类
private PdfPTable cellRodape(String value, boolean l,boolean r,int align)
{
Font fontCorpoTableO= FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED ,7.5f);
PdfPTable pTable = new PdfPTable(1);
pTable.setWidthPercentage(100f);
PdfPCell cellValue = new PdfPCell(new Phrase(value,fontCorpoTableO));
if(l){cellValue.setBorderWidthLeft(0);}
if(r){cellValue.setBorderWidthRight(0);}
switch (align)
{
case Element.ALIGN_RIGHT:cellValue.setHorizontalAlignment(Element.ALIGN_RIGHT);break;
case Element.ALIGN_LEFT:cellValue.setHorizontalAlignment(Element.ALIGN_LEFT);break;
case Element.ALIGN_CENTER:cellValue.setHorizontalAlignment(Element.ALIGN_CENTER);break;
default:break;
}
pTable.addCell(cellValue);
return pTable;
}
示例2: 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;
}
示例3: funcaoTitulo
import com.itextpdf.text.Font; //导入依赖的package包/类
private Phrase funcaoTitulo(int i) {
String txt;
Font fontcabecatable = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED ,10f );
switch (i)
{
case 0:txt="Nr. Factura";break;
case 1:txt="Nome do Segurado"; break;
case 2:txt="Prémio";break;
case 3:txt="Imposto 6%";break;
case 4:txt="Imposto 5%";break;
case 5:txt="FGA 2.6%";break;
default:txt="TOTAL";break;
}
a=com.itextpdf.text.Element.ALIGN_CENTER;
Phrase rt = new Phrase(txt,fontcabecatable);
return rt;
}
示例4: testShowTextAlignedVsSimpleColumnTopAlignment
import com.itextpdf.text.Font; //导入依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/32162759/columntext-showtextaligned-vs-columntext-setsimplecolumn-top-alignment">
* ColumnText.ShowTextAligned vs ColumnText.SetSimpleColumn Top Alignment
* </a>
* <p>
* Indeed, the coordinates do not line up. The y coordinate of
* {@link ColumnText#showTextAligned(PdfContentByte, int, Phrase, float, float, float)}
* denotes the baseline while {@link ColumnText#setSimpleColumn(Rectangle)} surrounds
* the text to come.
* </p>
*/
@Test
public void testShowTextAlignedVsSimpleColumnTopAlignment() throws DocumentException, IOException
{
Document document = new Document(PageSize.A4);
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(new File(RESULT_FOLDER, "ColumnTextTopAligned.pdf")));
document.open();
Font fontQouteItems = new Font(BaseFont.createFont(), 12);
PdfContentByte canvas = writer.getDirectContent();
// Item Number
ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("36222-0", fontQouteItems), 60, 450, 0);
// Estimated Qty
ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("47", fontQouteItems), 143, 450, 0);
// Item Description
ColumnText ct = new ColumnText(canvas); // Uses a simple column box to provide proper text wrapping
ct.setSimpleColumn(new Rectangle(193, 070, 390, 450));
ct.setText(new Phrase("In-Situ : Poly Cable - 100'\nPoly vented rugged black gable 100ft\nThis is an additional description. It can wrap an extra line if it needs to so this text is long.", fontQouteItems));
ct.go();
document.close();
}
示例5: calculateStyle
import com.itextpdf.text.Font; //导入依赖的package包/类
private int calculateStyle(Style style) {
int s = Font.NORMAL;
if (style.isBold()) {
s |= Font.BOLD;
}
if (style.isItalic()) {
s |= Font.ITALIC;
}
if (style.isStrikethrough()) {
s |= Font.STRIKETHRU;
}
if (style.isUnderline()) {
s |= Font.UNDERLINE;
}
return s;
}
示例6: addBalancedReportTitle
import com.itextpdf.text.Font; //导入依赖的package包/类
/**
* Adds the report title for balanced report.
*
* @param document
* the report document.
* @param reportName
* the report name.
* @param fiscalYear
* the fiscal year.
* @param quarter
* the quarter.
* @param startDate
* the start date.
* @param endDate
* the end date.
* @throws com.itextpdf.text.DocumentException
* if any error occurs.
*/
static void addBalancedReportTitle(com.itextpdf.text.Document document, String reportName, Integer fiscalYear,
Integer quarter, Date startDate, Date endDate)
throws com.itextpdf.text.DocumentException {
com.itextpdf.text.Paragraph title = new com.itextpdf.text.Paragraph(reportName,
new Font(FontFamily.HELVETICA, 16, Font.BOLD));
title.setAlignment(PDF_ALIGN_CENTER);
document.add(title);
if (fiscalYear != null && quarter != null) {
com.itextpdf.text.Paragraph subTitle1 = new com.itextpdf.text.Paragraph("Fiscal Year " + fiscalYear +
" - Quarter" + quarter, new Font(FontFamily.HELVETICA, 14, Font.BOLD));
subTitle1.setAlignment(PDF_ALIGN_CENTER);
document.add(subTitle1);
}
if (startDate != null && endDate != null) {
com.itextpdf.text.Paragraph subTitle2 = new com.itextpdf.text.Paragraph("Processed between " +
"" + REPORT_DATE_FORMAT.format(startDate) + " and " +
"" + REPORT_DATE_FORMAT.format(endDate),
new Font(FontFamily.HELVETICA, 12, Font.BOLD));
subTitle2.setAlignment(PDF_ALIGN_CENTER);
document.add(subTitle2);
}
}
开发者ID:NASA-Tournament-Lab,项目名称:CoECI-OPM-Service-Credit-Redeposit-Deposit-Application,代码行数:41,代码来源:ReportServiceHelper.java
示例7: getFont
import com.itextpdf.text.Font; //导入依赖的package包/类
public Font getFont(int _style, final float size) {
final int style;
if(!allowUnderline) {
style = _style & (~(Font.UNDERLINE));
} else {
style = _style;
}
String key = style + "," + size;
return getFont(key, new FontBuilder() {
@Override
public Font createFont() {
int baseStyle = style & Font.BOLDITALIC;
BaseFont bf = baseFontMap.get(baseStyle);
return new Font(bf, size, style);
}
});
}
示例8: refresh
import com.itextpdf.text.Font; //导入依赖的package包/类
@Override
public void refresh() {
ExploreConfig config = extractConfig();
String commandLine = config.toCommandLine();
if (commandLine.isEmpty()) {
setForeground(Color.GRAY);
setFont(getFont().deriveFont(Font.ITALIC));
setText("No parameters");
setEnabled(false);
} else {
setForeground(Color.BLACK);
setFont(getFont().deriveFont(Font.NORMAL));
setText(commandLine);
setEnabled(true);
}
}
示例9: funcaoTitulo
import com.itextpdf.text.Font; //导入依赖的package包/类
private Phrase funcaoTitulo(int i) {
String txt;
Font fontcabecatable = new Font(Font.FontFamily.COURIER, 8, Font.BOLD);
switch (i)
{
case 0:txt="S/N";break;
case 1:txt="DATA";break;
case 2:txt="APOLICE";break;
case 3:txt="DATA INICIO";break;
case 4:txt="DATA FIM";break;
case 5:txt="NO. DIAS";break;
case 6:txt="NOME";break;
case 7:txt="RECEIPT NO.";break;
case 8:txt="EA PREM";break;
case 9:txt="NICON COMISSÃO";break;
case 10:txt="5% IMPOSTO";break;
case 11:txt="0.60% SELO";break;
// case 12:txt="NET OUT OF TAX";break;
default:txt="TOTAL"/*"NET OUT OF TAX"*/;break;
}
Phrase rt = new Phrase(txt,fontcabecatable);
return rt;
}
示例10: writeSimplePdf
import com.itextpdf.text.Font; //导入依赖的package包/类
public static void writeSimplePdf() throws Exception{
//1.新建document对象
//第一个参数是页面大小。接下来的参数分别是左、右、上和下页边距。
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
//2.建立一个书写器(Writer)与document对象关联,通过书写器(Writer)可以将文档写入到磁盘中。
//创建 PdfWriter 对象 第一个参数是对文档对象的引用,第二个参数是文件的实际名称,在该名称中还会给出其输出路径。
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("D:\\Documents\\ITextTest.pdf"));
//3.打开文档
document.open();
//4.向文档中添加内容
//通过 com.lowagie.text.Paragraph 来添加文本。可以用文本及其默认的字体、颜色、大小等等设置来创建一个默认段落
BaseFont bfChinese = BaseFont.createFont("STSong-Light","UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
Font fontChinese = new Font(bfChinese, 22, Font.BOLD, BaseColor.BLACK);
document.add(new Paragraph("sdfsdfsd全是中文显示了没.fsdfsfs",fontChinese));
document.add(new Paragraph("Some more text on the first page with different color and font type.",
FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD, new BaseColor(255, 150, 200))));
Paragraph pragraph=new Paragraph("你这里有中亠好", fontChinese);
document.add(pragraph);
//图像支持格式 GIF, Jpeg, PNG, wmf
Image gif = Image.getInstance("F:/keyworkspace/survey/WebRoot/images/logo/snlogo.png");
gif.setBorder(5);
gif.scaleAbsolute(30,30);
gif.setAlignment(Image.RIGHT|Image.TEXTWRAP);
document.add(gif);
Paragraph pragraph11=new Paragraph("你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好你这里有中亠好", fontChinese);
document.add(pragraph11);
Image gif15 = Image.getInstance("F:/keyworkspace/survey/WebRoot/images/logo/snlogo.png");
// gif15.setBorder(50);
gif15.setBorder(Image.BOX);
gif15.setBorderColor(BaseColor.RED);
// gif15.setBorderColorBottom(borderColorBottom)
gif15.setBorderWidth(1);
gif15.scalePercent(50);
document.add(gif15);
//5.关闭文档
document.close();
}
示例11: 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);
}
}
示例12: addOfferInstances
import com.itextpdf.text.Font; //导入依赖的package包/类
private void addOfferInstances(List<OfferInstance> offerInstances, Document document, BaseFont bf)
throws DocumentException {
if(offerInstances.isEmpty()) {
return;
}
document.add(new Paragraph("Wybrane oferty: ", new Font(bf, 12)));
PdfPTable offerInstancesTable = new PdfPTable(3);
offerInstancesTable.setWidthPercentage(100);
offerInstancesTable.setSpacingBefore(18f);
offerInstancesTable.setSpacingAfter(18f);
createofferInstancesTableHeaders(offerInstancesTable);
createofferInstancesTableContent(offerInstances, offerInstancesTable);
document.add(offerInstancesTable);
}
示例13: onStartPage
import com.itextpdf.text.Font; //导入依赖的package包/类
/**
* Increase the page number.
* @see com.itextpdf.text.pdf.PdfPageEventHelper#onStartPage(
* com.itextpdf.text.pdf.PdfWriter, com.itextpdf.text.Document)
*/
@Override
public void onStartPage(PdfWriter writer, Document document) {
pagenumber++;
System.out.println("ON Start Page PDF");
Rectangle rect = writer.getBoxSize("art");
/* header
ColumnText.showTextAligned(writer.getDirectContent(),
com.itextpdf.text.Element.ALIGN_RIGHT, header[0],
rect.getRight(), rect.getTop(), 0);
*/
Font font = new Font();
font.setSize(8);
if (G.licensePDF) {
ColumnText.showTextAligned(writer.getDirectContent(),
com.itextpdf.text.Element.ALIGN_CENTER, new Phrase(String.format(TLanguage.getString("EXPORT_PDF_LICENCIA")),font),
(rect.getLeft() + rect.getRight()) / 2, rect.getBottom() - 18, 0);
ColumnText.showTextAligned(writer.getDirectContent(),
com.itextpdf.text.Element.ALIGN_CENTER, new Phrase(String.format(TLanguage.getString("EXPORT_PDF_LICENCIA2")),font),
(rect.getLeft() + rect.getRight()) / 2, rect.getBottom() - 9, 0);
}
}
示例14: findFont
import com.itextpdf.text.Font; //导入依赖的package包/类
private Font findFont(org.apache.poi.ss.usermodel.Cell cell) {
if(cell == null) return new Font(Font.FontFamily.HELVETICA, 10);
if(xSSFWorkbook == null)
throw new NullPointerException("workbook was null!");
final org.apache.poi.ss.usermodel.Font f = xSSFWorkbook.getFontAt(cell.getCellStyle().getFontIndex());
final Font.FontFamily family;
final String fontName = f.getFontName().toLowerCase();
if(fontName.contains("times")) family = Font.FontFamily.TIMES_ROMAN;
else if(fontName.contains("courier")) family = Font.FontFamily.COURIER;
else if(fontName.contains("symbol")) family = Font.FontFamily.SYMBOL;
else family = Font.FontFamily.HELVETICA;
//final Font result = new Font(family, size);
// the font height value is 20 * the font size in points
final Font result = new Font(family, (float) f.getFontHeight() / 20);
if(f.getBold()) result.setStyle(Font.BOLD);
if(f.getItalic()) result.setStyle(Font.ITALIC);
return result;
}
示例15: makePDF
import com.itextpdf.text.Font; //导入依赖的package包/类
private static void makePDF(Bitmap bmp, File file) {
Document document = new Document();
try {
PdfWriter.getInstance(document, new FileOutputStream(file));
document.addAuthor(FullscreenActivity.mAuthor.toString());
document.addTitle(FullscreenActivity.mTitle.toString());
document.addCreator("OpenSongApp");
if (bmp!=null && bmp.getWidth()>bmp.getHeight()) {
document.setPageSize(PageSize.A4.rotate());
} else {
document.setPageSize(PageSize.A4);
}
document.addTitle(FullscreenActivity.mTitle.toString());
document.open();//document.add(new Header("Song title",FullscreenActivity.mTitle.toString()));
BaseFont urName = BaseFont.createFont("assets/fonts/Lato-Reg.ttf", "UTF-8",BaseFont.EMBEDDED);
Font TitleFontName = new Font(urName, 14);
Font AuthorFontName = new Font(urName, 10);
document.add(new Paragraph(FullscreenActivity.mTitle.toString(),TitleFontName));
document.add(new Paragraph(FullscreenActivity.mAuthor.toString(),AuthorFontName));
addImage(document,bmp);
document.close();
} catch (Exception e) {
e.printStackTrace();
}
}