Package com.lowagie.text.pdf

Examples of com.lowagie.text.pdf.BaseFont


    if (fontRec != null)
    {
      return fontRec;
    }

    BaseFont f;
    try
    {
      try
      {
        f = BaseFont.createFont(filename, encoding, embedded, false, null, null);
View Full Code Here


    @Override
    public void addFont(String path, String encoding, boolean embedded, String pathToPFB) throws DocumentException, IOException {
        try {
            String lower = path.toLowerCase();
            if (lower.endsWith(".otf") || lower.endsWith(".ttf") || lower.indexOf(".ttc,") != -1) {
                BaseFont font = BaseFont.createFont(path, encoding, embedded);

                String fontFamilyName = TrueTypeUtil.getFamilyName(font);
                FontFamily fontFamily = getCustomFontFamily(fontFamilyName);

                FontDescription descr = new FontDescription(font);
                try {
                    TrueTypeUtil.populateDescription(path, font, descr);
                } catch (Exception e) {
                    throw new XRRuntimeException(e.getMessage(), e);
                }

                fontFamily.addFontDescription(descr);
            } else if (lower.endsWith(".ttc")) {
                String[] names = BaseFont.enumerateTTCNames(path);
                for (int i = 0; i < names.length; i++) {
                    addFont(path + "," + i, encoding, embedded);
                }
            } else if (lower.endsWith(".afm") || lower.endsWith(".pfm")) {
                if (embedded && pathToPFB == null) {
                    throw new IOException("When embedding a font, path to PFB/PFA file must be specified");
                }

                BaseFont font = BaseFont.createFont(
                        path, encoding, embedded, false, null, readFile(pathToPFB));

                String fontFamilyName = font.getFamilyFontName()[0][3];
                FontFamily fontFamily = getCustomFontFamily(fontFamilyName);

                FontDescription descr = new FontDescription(font);
                // XXX Need to set weight, underline position, etc.  This information
                // is contained in the AFM file (and even parsed by Type1Font), but
                // unfortunately it isn't exposed to the caller.
                fontFamily.addFontDescription(descr);           
            } else {
                BaseFont font = BaseFont.createFont(path, encoding, embedded);
           
                String fontFamilyName = font.getFamilyFontName()[0][3];
                FontFamily fontFamily = getCustomFontFamily(fontFamilyName);

                FontDescription descr = new FontDescription(font);
                fontFamily.addFontDescription(descr);   
            }
View Full Code Here

    protected void addFontFaceFont(
            String uri, String encoding, boolean embedded, byte[] afmttf, byte[] pfb)
            throws DocumentException, IOException {
        String lower = uri.toLowerCase();
        if (lower.endsWith(".otf") || lower.endsWith(".ttf") || lower.indexOf(".ttc,") != -1) {
            BaseFont font = BaseFont.createFont(uri, encoding, embedded, false, afmttf, pfb);
           
            String fontFamilyName = TrueTypeUtil.getFamilyName(font);
            FontFamily fontFamily = getCustomFontFamily(fontFamilyName);
           
            FontDescription descr = new FontDescription(font);
            try {
                TrueTypeUtil.populateDescription(uri, afmttf, font, descr);
            } catch (Exception e) {
                throw new XRRuntimeException(e.getMessage(), e);
            }
           
            descr.setFromFontFace(true);
           
            fontFamily.addFontDescription(descr);
        } else if (lower.endsWith(".afm") || lower.endsWith(".pfm") || lower.endsWith(".pfb") || lower.endsWith(".pfa")) {
            if (embedded && pfb == null) {
                throw new IOException("When embedding a font, path to PFB/PFA file must be specified");
            }
           
            String name = uri.substring(0, uri.length()-4) + ".afm";
            BaseFont font = BaseFont.createFont(
                    name, encoding, embedded, false, afmttf, pfb);
           
            String fontFamilyName = font.getFamilyFontName()[0][3];
            FontFamily fontFamily = getCustomFontFamily(fontFamilyName);
           
            FontDescription descr = new FontDescription(font);
            descr.setFromFontFace(true);
            // XXX Need to set weight, underline position, etc.  This information
View Full Code Here

    }
   
    protected static void addUnicodeFont(HashMap result) throws DocumentException, IOException {
        FontFamily stsong = new FontFamily();
        stsong.setName("STSong-Light");
        BaseFont stsongFont = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        stsong.addFontDescription(new FontDescription(stsongFont, IdentValue.NORMAL, 400));
        result.put("STSong-Light", stsong);
       
        FontFamily msung = new FontFamily();
        msung.setName("MSung-Light");
        BaseFont msungFont = BaseFont.createFont("MSung-Light", "UniCNS-UCS2-H", BaseFont.NOT_EMBEDDED);
        msung.addFontDescription(new FontDescription(msungFont, IdentValue.NORMAL, 400));
        result.put("MSung-Light", msung);
       
        FontFamily heiseimin = new FontFamily();
        heiseimin.setName("HeiseiMin-W3");
        BaseFont heiseiminFont = BaseFont.createFont("HeiseiMin-W3", "UniJIS-UCS2-H", BaseFont.NOT_EMBEDDED);
        heiseimin.addFontDescription(new FontDescription(heiseiminFont, IdentValue.NORMAL, 400));
        result.put("HeiseiMin-W3", heiseimin);
       
        FontFamily hygothic = new FontFamily();
        hygothic.setName("HYGoThic-Medium");
        BaseFont hygothicFont = BaseFont.createFont("HYGoThic-Medium", "UniKS-UCS2-H", BaseFont.NOT_EMBEDDED);
        hygothic.addFontDescription(new FontDescription(hygothicFont, IdentValue.NORMAL, 400));
        result.put("HYGoThic-Medium", hygothic);
       
        FontFamily droidsan = new FontFamily();
        String path = "fonts/Droid-Sans/DroidSans.ttf";
        BaseFont font = BaseFont.createFont(path, BaseFont.IDENTITY_H, true);
        String fontFamilyName = TrueTypeUtil.getFamilyName(font);
        droidsan.setName(fontFamilyName);
        FontDescription descr = new FontDescription(font);
        try {
            TrueTypeUtil.populateDescription(path, font, descr);
View Full Code Here

   
    public void addFont(String path, String encoding, boolean embedded, String pathToPFB)
            throws DocumentException, IOException {
        String lower = path.toLowerCase();
        if (lower.endsWith(".otf") || lower.endsWith(".ttf") || lower.indexOf(".ttc,") != -1) {
            BaseFont font = BaseFont.createFont(path, encoding, embedded);
           
            String fontFamilyName = TrueTypeUtil.getFamilyName(font);
            FontFamily fontFamily = getFontFamily(fontFamilyName);
           
            FontDescription descr = new FontDescription(font);
            try {
                TrueTypeUtil.populateDescription(path, font, descr);
            } catch (Exception e) {
                throw new XRRuntimeException(e.getMessage(), e);
            }
           
            fontFamily.addFontDescription(descr);
        } else if (lower.endsWith(".ttc")) {
            String[] names = BaseFont.enumerateTTCNames(path);
            for (int i = 0; i < names.length; i++) {
                addFont(path + "," + i, encoding, embedded);
            }
        } else if (lower.endsWith(".afm") || lower.endsWith(".pfm")) {
            if (embedded && pathToPFB == null) {
                throw new IOException("When embedding a font, path to PFB/PFA file must be specified");
            }
           
            BaseFont font = BaseFont.createFont(
                    path, encoding, embedded, false, null, readFile(pathToPFB));
           
            String fontFamilyName = font.getFamilyFontName()[0][3];
            FontFamily fontFamily = getFontFamily(fontFamilyName);
           
            FontDescription descr = new FontDescription(font);
            // XXX Need to set weight, underline position, etc.  This information
            // is contained in the AFM file (and even parsed by Type1Font), but
View Full Code Here

    private void addFontFaceFont(
            String uri, String encoding, boolean embedded, byte[] afmttf, byte[] pfb)
            throws DocumentException, IOException {
        String lower = uri.toLowerCase();
        if (lower.endsWith(".otf") || lower.endsWith(".ttf") || lower.indexOf(".ttc,") != -1) {
            BaseFont font = BaseFont.createFont(uri, encoding, embedded, false, afmttf, pfb);
           
            String fontFamilyName = TrueTypeUtil.getFamilyName(font);
            FontFamily fontFamily = getFontFamily(fontFamilyName);
           
            FontDescription descr = new FontDescription(font);
            try {
                TrueTypeUtil.populateDescription(uri, afmttf, font, descr);
            } catch (Exception e) {
                throw new XRRuntimeException(e.getMessage(), e);
            }
           
            descr.setFromFontFace(true);
           
            fontFamily.addFontDescription(descr);
        } else if (lower.endsWith(".afm") || lower.endsWith(".pfm") || lower.endsWith(".pfb") || lower.endsWith(".pfa")) {
            if (embedded && pfb == null) {
                throw new IOException("When embedding a font, path to PFB/PFA file must be specified");
            }
           
            String name = uri.substring(0, uri.length()-4) + ".afm";
            BaseFont font = BaseFont.createFont(
                    name, encoding, embedded, false, afmttf, pfb);
           
            String fontFamilyName = font.getFamilyFontName()[0][3];
            FontFamily fontFamily = getFontFamily(fontFamilyName);
           
            FontDescription descr = new FontDescription(font);
            descr.setFromFontFace(true);
            // XXX Need to set weight, underline position, etc.  This information
View Full Code Here

            cb.moveTo(50, 600);
            cb.lineTo(400, 600);
            cb.stroke();
           
            // we construct a font
            BaseFont bf = BaseFont.createFont("c:\\windows\\fonts\\arialuni.ttf", BaseFont.IDENTITY_H, true);
            Font ft = new Font(bf, 12);
            // This is the text:
            String text = "\u0623\u0648\u0631\u0648\u0628\u0627, \u0628\u0631\u0645\u062c\u064a\u0627\u062a \u0627\u0644\u062d\u0627\u0633\u0648\u0628 + \u0627\u0646\u062a\u0631\u0646\u064a\u062a :";
            Phrase center = new Phrase(text + " Center", ft);
            ColumnText.showTextAligned(cb, PdfContentByte.ALIGN_CENTER, center, 250, 700, 0, PdfWriter.RUN_DIRECTION_RTL, 0);
View Full Code Here

           
            // step 3: we open the document
            document.open();
           
            // step 4: we add content to the document
            BaseFont bfComic = BaseFont.createFont("c:\\windows\\fonts\\comic.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED);
            Font font = new Font(bfComic, 12);
            String text1 = "quick brown fox jumps";
            String text2 = " over ";
            String text3 = "the lazy dog";
            document.add(new Paragraph(text1, font));
            document.add(new Paragraph("width: " + bfComic.getWidthPoint(text1, 12)));
            document.add(new Paragraph("ascent: " + bfComic.getAscentPoint(text1, 12)));
            document.add(new Paragraph("descent: " + bfComic.getDescentPoint(text1, 12)));
            document.add(new Paragraph("height: " + (bfComic.getAscentPoint(text1, 12) - bfComic.getDescentPoint(text1, 12))));
            document.add(new Paragraph(text2, font));
            document.add(new Paragraph("width: " + bfComic.getWidthPoint(text2, 12)));
            document.add(new Paragraph("ascent: " + bfComic.getAscentPoint(text2, 12)));
            document.add(new Paragraph("descent: " + bfComic.getDescentPoint(text2, 12)));
            document.add(new Paragraph("height: " + (bfComic.getAscentPoint(text2, 12) - bfComic.getDescentPoint(text2, 12))));
            document.add(new Paragraph(text3, font));
            document.add(new Paragraph("width: " + bfComic.getWidthPoint(text3, 12)));
            document.add(new Paragraph("ascent: " + bfComic.getAscentPoint(text3, 12)));
            document.add(new Paragraph("descent: " + bfComic.getDescentPoint(text3, 12)));
            document.add(new Paragraph("height: " + (bfComic.getAscentPoint(text3, 12) - bfComic.getDescentPoint(text3, 12))));
            document.add(new Paragraph(text1 + text2 + text3, font));
            document.add(new Paragraph("width: " + bfComic.getWidthPoint(text1 + text2 + text3, 12)));
            document.add(new Paragraph("ascent: " + bfComic.getAscentPoint(text1 + text2 + text3, 12)));
            document.add(new Paragraph("descent: " + bfComic.getDescentPoint(text1 + text2 + text3, 12)));
            document.add(new Paragraph("height: " + (bfComic.getAscentPoint(text1 + text2 + text3, 12) - bfComic.getDescentPoint(text1 + text2 + text3, 12))));
        }
        catch(DocumentException de) {
            System.err.println(de.getMessage());
        }
        catch(IOException ioe) {
View Full Code Here

          // step 2
            PdfWriter.getInstance(document, new FileOutputStream("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)));
        }
        catch (Exception de) {
            de.printStackTrace();
        }
View Full Code Here

      p.add(new Chunk("red", red));
      document.add(p);
      p = new Paragraph("Violets are ");
      p.add(new Chunk("blue", blue));
      document.add(p);
      BaseFont bf = FontFactory.getFont(FontFactory.COURIER).getCalculatedBaseFont(false);
      PdfContentByte cb = writer.getDirectContent();
      cb.beginText();
      cb.setColorFill(new Color(0x00, 0xFF, 0x00));
      cb.setFontAndSize(bf, 12);
      cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "Grass is green", 250, 700, 0);
View Full Code Here

TOP

Related Classes of com.lowagie.text.pdf.BaseFont

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.