本文整理汇总了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);
}
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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();
}
示例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;
}
}
示例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;
}
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
}
示例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();
}