本文整理汇总了Java中com.lowagie.text.Font类的典型用法代码示例。如果您正苦于以下问题:Java Font类的具体用法?Java Font怎么用?Java Font使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Font类属于com.lowagie.text包,在下文中一共展示了Font类的40个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
示例16: writeColumns
import com.lowagie.text.Font; //导入依赖的package包/类
private void writeColumns(PDFDocument document, PdfPTable tb)
{
PdfPTable tabla = new PdfPTable(anchoColumnas);
tabla.setWidthPercentage(100);
// this.tabla.setSplitRows(true);
Font font = document.getContext().getDefaultFont();
PdfPCell cell;
cell = createCell("",Rectangle.LEFT | Rectangle.RIGHT);
tabla.addCell(cell);
for(int i=0; i<columnas.size(); i++)
{
cell = createCell((String)columnas.get(i),document.getContext().getColor(204,204,204),
Rectangle.ALIGN_CENTER,font);
tabla.addCell(cell);
}
cell = createCell("",Rectangle.LEFT | Rectangle.RIGHT);
tabla.addCell(cell);
addTabla(tb,tabla);
}
示例17: writeCampos
import com.lowagie.text.Font; //导入依赖的package包/类
private void writeCampos(PDFDocument document, PdfPTable tb)
{
PdfPTable tabla = new PdfPTable(anchoColumnas);
PdfPCell cell;
tabla.setWidthPercentage(100);
Font font = document.getContext().getDefaultFont();
for(int i=0; i<campos.size();i++)
{
cell = createCell("",Rectangle.LEFT | Rectangle.RIGHT);
tabla.addCell(cell);
Vector cp = (Vector)campos.get(i);
for(int j=0; j<cp.size(); j++)
{
cell = createCell((String)cp.get(j),font);
tabla.addCell(cell);
}
cell = createCell("",Rectangle.LEFT | Rectangle.RIGHT);
tabla.addCell(cell);
}
addTabla(tb,tabla);
}
示例18: createNeedHeader
import com.lowagie.text.Font; //导入依赖的package包/类
private PdfPTable createNeedHeader(String name) throws DocumentException {
Font whiteFont = new Font(Font.HELVETICA,14,Font.BOLD,Color.WHITE);
PdfPTable table = new PdfPTable(3);
table.setWidthPercentage(100);
table.setWidths(new float[]{0.10f,0.20f,0.70f});
PdfPCell emptyCell = new PdfPCell();
emptyCell.setBorder(0);
table.addCell(emptyCell);
PdfPCell headerCell = new PdfPCell();
headerCell.setColspan(2);
headerCell.setPhrase(new Phrase(name,whiteFont));
headerCell.setHorizontalAlignment(Element.ALIGN_CENTER);
headerCell.setBackgroundColor(Color.LIGHT_GRAY);
table.addCell(headerCell);
return table;
}
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:18,代码来源:SummaryOfActionsAndCommentsReportGenerator.java
示例19: OscarChartPrinter
import com.lowagie.text.Font; //导入依赖的package包/类
public OscarChartPrinter(HttpServletRequest request, OutputStream os) throws DocumentException,IOException {
this.request = request;
this.os = os;
document = new Document();
// writer = PdfWriterFactory.newInstance(document, os, FontSettings.HELVETICA_10PT);
writer = PdfWriter.getInstance(document,os);
writer.setPageEvent(new EndPage());
document.setPageSize(PageSize.LETTER);
document.open();
//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);
}
示例20: installTabbedContainerSettings
import com.lowagie.text.Font; //导入依赖的package包/类
@Override
public void installTabbedContainerSettings() {
super.installTabbedContainerSettings();
UIManager.put("TabbedPane.textIconGap", 30);
UIManager.put("JTabbedPaneSmartIcon.font", new UIDefaults.ProxyLazyValue("javax.swing.plaf.FontUIResource", null,
new Object[] { "Dialog", Font.NORMAL, 13 }));
}
示例21: getWidth
import com.lowagie.text.Font; //导入依赖的package包/类
public static float getWidth(String text, boolean bold, boolean italic) {
Font font = PdfFont.getFont(bold, italic);
float width = 0;
if (text.indexOf('\n')>=0) {
for (StringTokenizer s = new StringTokenizer(text,"\n"); s.hasMoreTokens();)
width = Math.max(width,font.getBaseFont().getWidthPoint(s.nextToken(), font.getSize()));
} else
width = Math.max(width,font.getBaseFont().getWidthPoint(text, font.getSize()));
return width;
}
示例22: getWidthOfLastLine
import com.lowagie.text.Font; //导入依赖的package包/类
public static float getWidthOfLastLine(String text, boolean bold, boolean italic) {
Font font = PdfFont.getFont(bold, italic);
float width = 0;
if (text.indexOf('\n')>=0) {
for (StringTokenizer s = new StringTokenizer(text,"\n"); s.hasMoreTokens();)
width = font.getBaseFont().getWidthPoint(s.nextToken(), font.getSize());
} else
width = Math.max(width,font.getBaseFont().getWidthPoint(text, font.getSize()));
return width;
}
示例23: PdfEventHandler
import com.lowagie.text.Font; //导入依赖的package包/类
/**
* Constructor for PdfEventHandler
*
*/
public PdfEventHandler() throws DocumentException, IOException {
super();
Font font = PdfFont.getSmallFont();
setBaseFont(font.getBaseFont());
setFontSize(font.getSize());
return;
}
示例24: getFont
import com.lowagie.text.Font; //导入依赖的package包/类
private static Font getFont(float size, boolean fixed, boolean bold, boolean italic) {
if (ApplicationProperty.PdfFontCache.isTrue()) {
Font font = sFontCache.get(size + (fixed ? "F": "") + (bold ? "B": "") + (italic ? "I" : ""));
if (font == null) {
font = createFont(size, fixed, bold, italic);
sFontCache.put(size + (fixed ? "F": "") + (bold ? "B": "") + (italic ? "I" : ""), font);
}
return font;
} else {
return createFont(size, fixed, bold, italic);
}
}
示例25: getWidth
import com.lowagie.text.Font; //导入依赖的package包/类
public float getWidth(Font font) {
if (hasText()) {
if (getText().indexOf('\n')>=0) {
float width = 0f;
for (StringTokenizer s = new StringTokenizer(getText(),"\n"); s.hasMoreTokens();)
width = Math.max(width, width(s.nextToken(), font));
return width;
} else {
return width(getText(), font);
}
} else {
return 0f;
}
}
示例26: get
import com.lowagie.text.Font; //导入依赖的package包/类
/**
* Gets a chunk with a symbol character.
* @param e a symbol value (see Entities class: alfa is greek alfa,...)
* @param font the font if the symbol isn't found (otherwise Font.SYMBOL)
* @return a Chunk
*/
public static Chunk get(String e, Font font) {
char s = getCorrespondingSymbol(e);
if (s == (char)0) {
try {
return new Chunk(String.valueOf((char)Integer.parseInt(e)), font);
}
catch(Exception exception) {
return new Chunk(e, font);
}
}
Font symbol = new Font(Font.SYMBOL, font.getSize(), font.getStyle(), font.getColor());
return new Chunk(String.valueOf(s), symbol);
}
示例27: addFont
import com.lowagie.text.Font; //导入依赖的package包/类
/**
* Adds a <CODE>Font</CODE> to be searched for valid characters.
* @param font the <CODE>Font</CODE>
*/
public void addFont(Font font) {
if (font.getBaseFont() != null) {
fonts.add(font);
return;
}
BaseFont bf = font.getCalculatedBaseFont(true);
Font f2 = new Font(bf, font.getSize(), font.getCalculatedStyle(), font.getColor());
fonts.add(f2);
}
示例28: RtfListLevel
import com.lowagie.text.Font; //导入依赖的package包/类
public RtfListLevel(RtfDocument doc)
{
super(doc);
templateID = document.getRandomInt();
setFontNumber( new RtfFont(document, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL, new Color(0, 0, 0))));
setBulletFont(new Font(Font.SYMBOL, 10, Font.NORMAL, new Color(0, 0, 0)));
}
示例29: setAppointmentInfo
import com.lowagie.text.Font; //导入依赖的package包/类
private void setAppointmentInfo(EctConsultationFormRequestUtil reqForm) throws DocumentException{
printClinicData(reqForm);
Font font = new Font(bf, FONTSIZE, Font.NORMAL);
// Set consultant info
cb.beginText();
cb.setFontAndSize(bf, FONTSIZE);
cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.referalDate, 190, height - 112, 0);
cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.urgency.equals("1") ? "Urgent" : (reqForm.urgency.equals("2") ? "Non-Urgent" : "Return"), 190, height - 125, 0);
cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.getServiceName(reqForm.service), 190, height - 139, 0);
cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.getSpecailistsName(reqForm.specialist), 190, height - 153, 0);
cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.specPhone, 190, height - 166, 0);
cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.specFax, 190, height - 181, 0);
cb.endText();
ct.setSimpleColumn(new Float(190), height - 223, new Float(290), height - 181, LINEHEIGHT, Element.ALIGN_LEFT);
ct.addText(new Phrase(reqForm.specAddr.replaceAll("<br>", "\n"), font));
ct.go();
// Set patient info
cb.beginText();
cb.setFontAndSize(bf, FONTSIZE);
cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.patientName, 385, height - 112, 0);
cb.endText();
ct.setSimpleColumn(new Float(385), height - 153, new Float(585), height - 112, LINEHEIGHT, Element.ALIGN_LEFT);
ct.addText(new Phrase(reqForm.patientAddress.replaceAll("<br>", " "), font));
ct.go();
cb.beginText();
cb.setFontAndSize(bf, FONTSIZE);
cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.patientPhone, 385, height - 166, 0);
cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.patientDOB, 385, height - 181, 0);
cb.showTextAligned(PdfContentByte.ALIGN_LEFT, (reqForm.patientHealthCardType+" "+reqForm.patientHealthNum+" "+reqForm.patientHealthCardVersionCode).trim(), 440, height - 195, 0);
cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.appointmentHour+":"+reqForm.appointmentMinute+" "+reqForm.appointmentPm+" " + reqForm.appointmentDate, 440, height - 208, 0);
cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.patientChartNo, 385, height - 222, 0);
cb.endText();
}
示例30: RtfFont
import com.lowagie.text.Font; //导入依赖的package包/类
/**
* Constructs a RtfFont from a com.lowagie.text.Font
* @param doc The RtfDocument this font appears in
* @param font The Font to use as a base
*/
public RtfFont(RtfDocument doc, Font font) {
this.document = doc;
if(font != null) {
if(font instanceof RtfFont) {
this.fontName = ((RtfFont) font).getFontName();
this.charset = ((RtfFont) font).getCharset();
} else {
setToDefaultFamily(font.getFamilyname());
}
if(font.getBaseFont() != null) {
String[][] fontNames = font.getBaseFont().getFullFontName();
for(int i = 0; i < fontNames.length; i++) {
if(fontNames[i][2].equals("0")) {
this.fontName = fontNames[i][3];
break;
} else if(fontNames[i][2].equals("1033") || fontNames[i][2].equals("")) {
this.fontName = fontNames[i][3];
}
}
}
if(this.fontName.equalsIgnoreCase("unknown")) {
this.fontName = DEFAULT_FONT;
}
setSize(font.getSize());
setStyle(font.getStyle());
setColor(font.getColor());
if(document != null) {
this.fontNumber = document.getDocumentHeader().getFontNumber(this);
}
}
if(document != null) {
setRtfDocument(document);
}
}
示例31: printRtf
import com.lowagie.text.Font; //导入依赖的package包/类
public void printRtf()throws IOException, DocumentException{
//create an input stream from the rtf string bytes
byte[] rtfBytes = handler.getOBXResult(0, 0).getBytes();
ByteArrayInputStream rtfStream = new ByteArrayInputStream(rtfBytes);
//create & open the document we are going to write to and its writer
document = new Document();
RtfWriter2 writer = RtfWriter2.getInstance(document,os);
document.setPageSize(PageSize.LETTER);
document.addTitle("Title of the Document");
document.addCreator("OSCAR");
document.open();
//Create the fonts that we are going to use
bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
font = new Font(bf, 11, Font.NORMAL);
boldFont = new Font(bf, 12, Font.BOLD);
// redFont = new Font(bf, 11, Font.NORMAL, Color.RED);
//add the patient information
addRtfPatientInfo();
//add the results
writer.importRtfDocument(rtfStream, null);
document.close();
os.flush();
}
示例32: difference
import com.lowagie.text.Font; //导入依赖的package包/类
/**
* Replaces the attributes that are equal to <VAR>null</VAR> with
* the attributes of a given font.
*
* @param font The surrounding font
* @return A RtfFont
*/
public Font difference(Font font) {
String dFamilyname = font.getFamilyname();
if(dFamilyname == null || dFamilyname.trim().equals("") || dFamilyname.trim().equalsIgnoreCase("unknown")) {
dFamilyname = this.fontName;
}
float dSize = font.getSize();
if(dSize == Font.UNDEFINED) {
dSize = this.getSize();
}
int dStyle = Font.UNDEFINED;
if(this.getStyle() != Font.UNDEFINED && font.getStyle() != Font.UNDEFINED) {
dStyle = this.getStyle() | font.getStyle();
} else if(this.getStyle() != Font.UNDEFINED) {
dStyle = this.getStyle();
} else if(font.getStyle() != Font.UNDEFINED) {
dStyle = font.getStyle();
}
Color dColor = font.getColor();
if(dColor == null) {
dColor = this.getColor();
}
int dCharset = this.charset;
if(font instanceof RtfFont) {
dCharset = ((RtfFont) font).getCharset();
}
return new RtfFont(dFamilyname, dSize, dStyle, dColor, dCharset);
}
示例33: getFont
import com.lowagie.text.Font; //导入依赖的package包/类
public Font getFont(ChainedProperties props) {
String face = props.getProperty(ElementTags.FACE);
if (face != null) {
StringTokenizer tok = new StringTokenizer(face, ",");
while (tok.hasMoreTokens()) {
face = tok.nextToken().trim();
if (face.startsWith("\""))
face = face.substring(1);
if (face.endsWith("\""))
face = face.substring(0, face.length() - 1);
if (fontImp.isRegistered(face))
break;
}
}
int style = 0;
if (props.hasProperty(HtmlTags.I))
style |= Font.ITALIC;
if (props.hasProperty(HtmlTags.B))
style |= Font.BOLD;
if (props.hasProperty(HtmlTags.U))
style |= Font.UNDERLINE;
if (props.hasProperty(HtmlTags.S))
style |= Font.STRIKETHRU;
String value = props.getProperty(ElementTags.SIZE);
float size = 12;
if (value != null)
size = Float.parseFloat(value);
Color color = Markup.decodeColor(props.getProperty("color"));
String encoding = props.getProperty("encoding");
if (encoding == null)
encoding = BaseFont.WINANSI;
return fontImp.getFont(face, encoding, true, size, style, color);
}
示例34: isOtherFont
import com.lowagie.text.Font; //导入依赖的package包/类
/**
* Checks if a given font is the same as the font that was last used.
*
* @param font the font of an object
* @return true if the font differs
*/
public boolean isOtherFont(Font font) {
try {
Font cFont = (Font) currentfont.peek();
if (cFont.compareTo(font) == 0) return false;
return true;
}
catch(EmptyStackException ese) {
if (standardfont.compareTo(font) == 0) return false;
return true;
}
}
示例35: main
import com.lowagie.text.Font; //导入依赖的package包/类
/**
* Demonstrates the use of layers.
*
* @param args
* no arguments needed
*/
@Test
public void main() throws Exception {
// step 1: creation of a document-object
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
// step 2: creation of the writer
PdfWriter writer = PdfWriter.getInstance(document,
PdfTestBase.getOutputStream("optionalcontent.pdf"));
writer.setPdfVersion(PdfWriter.VERSION_1_5);
writer.setViewerPreferences(PdfWriter.PageModeUseOC);
// step 3: opening the document
document.open();
// step 4: content
PdfContentByte cb = writer.getDirectContent();
Phrase explanation = new Phrase(
"Automatic layers, form fields, images, templates and actions",
new Font(Font.HELVETICA, 18, Font.BOLD, Color.red));
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50,
650, 0);
PdfLayer l1 = new PdfLayer("Layer 1", writer);
PdfLayer l2 = new PdfLayer("Layer 2", writer);
PdfLayer l3 = new PdfLayer("Layer 3", writer);
PdfLayer l4 = new PdfLayer("Form and XObject Layer", writer);
PdfLayerMembership m1 = new PdfLayerMembership(writer);
m1.addMember(l2);
m1.addMember(l3);
Phrase p1 = new Phrase("Text in layer 1");
Phrase p2 = new Phrase("Text in layer 2 or layer 3");
Phrase p3 = new Phrase("Text in layer 3");
cb.beginLayer(l1);
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0f);
cb.endLayer();
cb.beginLayer(m1);
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0);
cb.endLayer();
cb.beginLayer(l3);
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0);
cb.endLayer();
TextField ff = new TextField(writer, new Rectangle(200, 600, 300, 620),
"field1");
ff.setBorderColor(Color.blue);
ff.setBorderStyle(PdfBorderDictionary.STYLE_SOLID);
ff.setBorderWidth(TextField.BORDER_WIDTH_THIN);
ff.setText("I'm a form field");
PdfFormField form = ff.getTextField();
form.setLayer(l4);
writer.addAnnotation(form);
Image img = Image.getInstance(PdfTestBase.RESOURCES_DIR
+ "pngnow.png");
img.setLayer(l4);
img.setAbsolutePosition(200, 550);
cb.addImage(img);
PdfTemplate tp = cb.createTemplate(100, 20);
Phrase pt = new Phrase("I'm a template", new Font(Font.HELVETICA, 12,
Font.NORMAL, Color.magenta));
ColumnText.showTextAligned(tp, Element.ALIGN_LEFT, pt, 0, 0, 0);
tp.setLayer(l4);
tp.setBoundingBox(new Rectangle(0, -10, 100, 20));
cb.addTemplate(tp, 200, 500);
ArrayList<Object> state = new ArrayList<Object>();
state.add("toggle");
state.add(l1);
state.add(l2);
state.add(l3);
state.add(l4);
PdfAction action = PdfAction.setOCGstate(state, true);
Chunk ck = new Chunk("Click here to toggle the layers", new Font(
Font.HELVETICA, 18, Font.NORMAL, Color.yellow)).setBackground(
Color.blue).setAction(action);
ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, new Phrase(ck),
250, 400, 0);
cb.sanityCheck();
// step 5: closing the document
document.close();
}
示例36: main
import com.lowagie.text.Font; //导入依赖的package包/类
/**
* Layer radio group and zoom.
*/
@Test
public void main() throws Exception {
// step 1
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
// step 2
PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream( "layers.pdf"));
writer.setPdfVersion(PdfWriter.VERSION_1_5);
writer.setViewerPreferences(PdfWriter.PageModeUseOC);
// step 3
document.open();
// step 4
PdfContentByte cb = writer.getDirectContent();
Phrase explanation = new Phrase("Layer radio group and zoom", new Font(Font.HELVETICA, 20, Font.BOLD, Color.red));
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50, 650, 0);
PdfLayer title = PdfLayer.createTitle("Layer radio group", writer);
PdfLayer l1 = new PdfLayer("Layer 1", writer);
PdfLayer l2 = new PdfLayer("Layer 2", writer);
PdfLayer l3 = new PdfLayer("Layer 3", writer);
PdfLayer l4 = new PdfLayer("Layer 4", writer);
title.addChild(l1);
title.addChild(l2);
title.addChild(l3);
l4.setZoom(2, -1);
l4.setOnPanel(false);
l4.setPrint("Print", true);
l2.setOn(false);
l3.setOn(false);
ArrayList<PdfLayer> radio = new ArrayList<PdfLayer>();
radio.add(l1);
radio.add(l2);
radio.add(l3);
writer.addOCGRadioGroup(radio);
Phrase p1 = new Phrase("Text in layer 1");
Phrase p2 = new Phrase("Text in layer 2");
Phrase p3 = new Phrase("Text in layer 3");
Phrase p4 = new Phrase("Text in layer 4");
cb.beginLayer(l1);
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0);
cb.endLayer();
cb.beginLayer(l2);
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0);
cb.endLayer();
cb.beginLayer(l3);
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0);
cb.endLayer();
cb.beginLayer(l4);
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p4, 50, 450, 0);
cb.endLayer();
ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase("<< Zoom here!", new Font(Font.COURIER, 12, Font.NORMAL, Color.blue)), 150, 450, 0);
// step 5
document.close();
}
示例37: awtToPdf
import com.lowagie.text.Font; //导入依赖的package包/类
@Override
public BaseFont awtToPdf(java.awt.Font font)
{
// not setting underline and strikethrough as we only need the base font.
// underline and strikethrough will not work here because PdfGraphics2D
// doesn't check the font attributes.
Map<Attribute,Object> atts = new HashMap<Attribute,Object>();
atts.putAll(font.getAttributes());
return getFont(atts, null, false).getBaseFont();
}
示例38: main
import com.lowagie.text.Font; //导入依赖的package包/类
/**
* Embedding True Type Fonts.
* @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-object
PdfWriter.getInstance(document, PdfTestBase.getOutputStream("unicode.pdf"));
// step 3: we open the document
document.open();
File fontPath = new File(PdfTestBase.RESOURCES_DIR + "liberation-fonts-ttf/LiberationMono-Regular.ttf");
// step 4: we add content to the document
BaseFont bfComic = BaseFont.createFont(fontPath.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font font = new Font(bfComic, 12);
String text1 = "This is the quite popular True Type font 'Liberation Mono'.";
String text2 = "Some greek characters: \u0393\u0394\u03b6";
String text3 = "Some cyrillic characters: \u0418\u044f";
document.add(new Paragraph(text1, font));
document.add(new Paragraph(text2, font));
document.add(new Paragraph(text3, font));
// step 5: we close the document
document.close();
}
示例39: main
import com.lowagie.text.Font; //导入依赖的package包/类
/**
* Embedding True Type Fonts.
*/
@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();
// step 4: we add content to the document
BaseFont bfComic = BaseFont.createFont(PdfTestBase.RESOURCES_DIR + "/liberation-fonts-ttf/LiberationSans-Regular.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font font = new Font(bfComic, 12);
String text1 = "This is the quite popular True Type font 'LiberationSans'.";
String text2 = "Some greek characters: \u0393\u0394\u03b6";
String text3 = "Some cyrillic characters: \u0418\u044f";
document.add(new Paragraph(text1, font));
document.add(new Paragraph(text2, font));
document.add(new Paragraph(text3, font));
// step 5: we close the document
document.close();
}
示例40: main
import com.lowagie.text.Font; //导入依赖的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();
}
注:本文中的com.lowagie.text.Font类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。