Java 类com.lowagie.text.Font 实例源码

项目:DWSurvey    文件:DocExportUtil.java   
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);
}
项目:unitimes    文件:PdfWebTable.java   
private float addText(PdfPCell cell, String text, boolean bold, boolean italic, boolean underline, Color color, Color bgColor) {
    Font font = PdfFont.getFont(bold, italic, underline, color);
    Chunk chunk = new Chunk(text, font);
    if (bgColor!=null) chunk.setBackground(bgColor);
    if (cell.getPhrase()==null) {
        cell.setPhrase(new Paragraph(chunk));
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    } else {
        cell.getPhrase().add(chunk);
    }
    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;
}
项目:unitimes    文件:ExportTimetablePDF.java   
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;
}
项目:itext2    文件:PdfOutline.java   
/**
 * 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);
}
项目:itext2    文件:RtfDestinationFontTable.java   
/**
 * 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;
}
项目:OSCAR-ConCert    文件:PdfRecordPrinter.java   
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();
}
项目:itext2    文件:RtfFont.java   
/**
 * 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;
    }
}
项目:itext2    文件:RtfFont.java   
/**
 * 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;
    }
}
项目:itext2    文件:TrueTypeTest.java   
/**
 * 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();
}
项目:itext2    文件:FixedFontWidthTest.java   
/**
 * Changing the width of font glyphs.
 * 
 * @param args
 *            no arguments needed
 */
@Test
public void main() throws Exception {
    // step 1
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    // step 2
    PdfWriter.getInstance(document, PdfTestBase.getOutputStream("fixedfontwidth.pdf"));
    // step 3
    document.open();
    // step 4
    BaseFont bf = BaseFont.createFont("Helvetica", "winansi", false, false, null, null);
    int widths[] = bf.getWidths();
    for (int k = 0; k < widths.length; ++k) {
        if (widths[k] != 0)
            widths[k] = 1000;
    }
    bf.setForceWidthsOutput(true);
    document.add(new Paragraph("A big text to show Helvetica with fixed width.", new Font(bf)));
    // step 5
    document.close();
}
项目:itext2    文件:FontEncodingTest.java   
/**
    * 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();
   }
项目:itext2    文件:OpenTypeFontTest.java   
/**
 * Using oth
 */
@Test
public void main() throws Exception {
    // step 1
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    // step 2
    PdfWriter.getInstance(document,
            PdfTestBase.getOutputStream("opentypefont.pdf"));
    // step 3
    document.open();
    // step 4
    BaseFont bf = BaseFont.createFont(PdfTestBase.RESOURCES_DIR
            + "liz.otf", BaseFont.CP1252, true);
    String text = "Some text with the otf font LIZ.";
    document.add(new Paragraph(text, new Font(bf, 14)));
    // step 5
    document.close();
}
项目:BJAF3.x    文件:GenPdfController.java   
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);
    }
}
项目:itext2    文件:DifferentFontsTest.java   
/**
 * Using FontSelector.
 */
@Test
public void main() throws Exception {
    // step 1
    Document document = new Document();
    // step 2
    PdfWriter.getInstance(document, PdfTestBase.getOutputStream("differentfonts.pdf"));
    // step 3
    document.open();
    // step 4
    Paragraph p = new Paragraph();
    p.add(new Chunk("This text is in Times Roman. This is ZapfDingbats: ", new Font(Font.TIMES_ROMAN, 12)));
    p.add(new Chunk("abcdefghijklmnopqrstuvwxyz", new Font(Font.ZAPFDINGBATS, 12)));
    p.add(new Chunk(". This is font Symbol: ", new Font(Font.TIMES_ROMAN, 12)));
    p.add(new Chunk("abcdefghijklmnopqrstuvwxyz", new Font(Font.SYMBOL, 12)));
    document.add(new Paragraph(p));
    // step 5
    document.close();

}
项目:itext2    文件:FontSelectionTest.java   
/**
 * 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();

}
项目:jasperreports    文件:JRPdfExporter.java   
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();
}
项目:itext2    文件:TableBordersTest.java   
private static PdfPCell makeCell(String text, int vAlignment, int hAlignment, Font font, float leading,
        float padding, Rectangle borders, boolean ascender, boolean descender) {
    Paragraph p = new Paragraph(text, font);
    p.setLeading(leading);

    PdfPCell cell = new PdfPCell(p);
    cell.setLeading(leading, 0);
    cell.setVerticalAlignment(vAlignment);
    cell.setHorizontalAlignment(hAlignment);
    cell.cloneNonPositionParameters(borders);
    cell.setUseAscender(ascender);
    cell.setUseDescender(descender);
    cell.setUseBorderPadding(true);
    cell.setPadding(padding);
    return cell;
}
项目:itext2    文件:ExtendedFontTest.java   
/**
 * 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();
}
项目:itext2    文件:UnicodePdfTest.java   
@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();
    }
}
项目:OSCAR-ConCert    文件:PdfRecordPrinter.java   
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();
}
项目:sistra    文件:Tabla.java   
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);
    }
项目:sistra    文件:Tabla.java   
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);
}
项目:OSCAR-ConCert    文件:SummaryOfActionsAndCommentsReportGenerator.java   
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;
}
项目:OSCAR-ConCert    文件:OscarChartPrinter.java   
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);
}
项目:rapidminer    文件:RapidDockingUISettings.java   
@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 }));
}
项目:unitimes    文件:PdfTimetableGridTable.java   
public void addTextVertical(PdfPCell cell, String text, boolean bold) throws Exception  {
    if (text==null) return;
       if (text.indexOf("<span")>=0)
           text = text.replaceAll("</span>","").replaceAll("<span .*>", "");
       Font font = PdfFont.getFont(bold);
    BaseFont bf = font.getBaseFont();
    float width = bf.getWidthPoint(text, font.getSize());
    PdfTemplate template = iWriter.getDirectContent().createTemplate(2 * font.getSize() + 4, width);
    template.beginText();
    template.setColorFill(Color.BLACK);
    template.setFontAndSize(bf, font.getSize());
    template.setTextMatrix(0, 2);
    template.showText(text);
    template.endText();
    template.setWidth(width);
    template.setHeight(font.getSize() + 2);
    //make an Image object from the template
    Image img = Image.getInstance(template);
    img.setRotationDegrees(270);
    //embed the image in a Chunk
    Chunk ck = new Chunk(img, 0, 0);

    if (cell.getPhrase()==null) {
        cell.setPhrase(new Paragraph(ck));
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    } else {
        cell.getPhrase().add(ck);
    }
}
项目:unitimes    文件:PdfWebTable.java   
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;
}
项目:unitimes    文件:PdfWebTable.java   
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;
}
项目:unitimes    文件:PdfEventHandler.java   
/**
   * Constructor for PdfEventHandler
   * 
   */
  public PdfEventHandler() throws DocumentException, IOException {

    super();

    Font font = PdfFont.getSmallFont();
setBaseFont(font.getBaseFont());
setFontSize(font.getSize());

      return;
   }
项目:unitimes    文件:PdfFont.java   
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);
    }
}
项目:unitimes    文件:PDFPrinter.java   
@Override
public void printHeader(String... fields) {
    iTable = new PdfPTable(fields.length - iHiddenColumns.size());
    iMaxWidth = new float[fields.length];
    iTable.setHeaderRows(1);
    iTable.setWidthPercentage(100);

    for (int idx = 0; idx < fields.length; idx++) {
        if (iHiddenColumns.contains(idx)) continue;
        String f = fields[idx];

        PdfPCell cell = new PdfPCell();
        cell.setBorder(Rectangle.BOTTOM);
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);

        Font font = PdfFont.getFont(true);
        Paragraph ch = new Paragraph(f, font);
        ch.setLeading(0f, 1f);
        cell.addElement(ch);        
        iTable.addCell(cell);

        float width = 0; 
        if (f.indexOf('\n')>=0) {
            for (StringTokenizer s = new StringTokenizer(f,"\n"); s.hasMoreTokens();)
                width = Math.max(width,font.getBaseFont().getWidthPoint(s.nextToken(), font.getSize()));
        } else 
            width = Math.max(width,font.getBaseFont().getWidthPoint(f, font.getSize()));
        iMaxWidth[idx] = width;
    }
}
项目:unitimes    文件:PDFPrinter.java   
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;
    }
}
项目:DWSurvey    文件:DocStyleUtils.java   
/** 
 * 功能说明:设置段落的样式,设置前半截内容和后半截内容格式不一样的段落样式</BR> 
 * 修改日:2011-04-27 
 * @author myclover 
 * @param content  前半截内容 
 * @param font     字体的样式 
 * @param firstLineIndent 首行缩进多少字符,16f约等于一个字符 
 * @param appendStr 后半截内容 
 * @return 
 */  
public static Paragraph setParagraphStyle(String content , Font font , float firstLineIndent , String appendStr){  
    Paragraph par = setParagraphStyle(content, font, 0f, 12f);  
    Phrase phrase = new Phrase();  
    phrase.add(par);  
    phrase.add(appendStr);  
    Paragraph paragraph = new Paragraph(phrase);  
    paragraph.setFirstLineIndent(firstLineIndent);  
    //设置对齐方式为两端对齐  
    paragraph.setAlignment(Paragraph.ALIGN_JUSTIFIED_ALL);  
    return paragraph;  
}
项目:itext2    文件:EntitiesToSymbol.java   
/**
 * 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);
}
项目:itext2    文件:FontSelector.java   
/**
 * 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);
}
项目:itext2    文件:RtfListLevel.java   
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)));
}
项目:OSCAR-ConCert    文件:EctConsultationFormRequestPrintPdf.java   
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();
    }
项目:itext2    文件:RtfFont.java   
/**
 * 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);
    }
}
项目:OSCAR-ConCert    文件:LabPDFCreator.java   
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();
}
项目:itext2    文件:RtfFont.java   
/**
 * 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);
}