Class PDTrueTypeFont

    • Field Detail

      • UNKNOWN_FONT

        public static final java.lang.String UNKNOWN_FONT
        This is the key to a property in the PDFBox_External_Fonts.properties file to load a Font when a mapping does not exist for the current font.
        See Also:
        Constant Field Values
    • Constructor Detail

      • PDTrueTypeFont

        public PDTrueTypeFont()
        Constructor.
      • PDTrueTypeFont

        public PDTrueTypeFont​(COSDictionary fontDictionary)
                       throws java.io.IOException
        Constructor.
        Parameters:
        fontDictionary - The font dictionary according to the PDF specification.
        Throws:
        java.io.IOException - exception if something went wrong when loading the font.
    • Method Detail

      • loadTTF

        public static PDTrueTypeFont loadTTF​(PDDocument doc,
                                             java.lang.String file)
                                      throws java.io.IOException
        This will load a TTF font from a font file.
        Parameters:
        doc - The PDF document that will hold the embedded font.
        file - The file on the filesystem that holds the font file.
        Returns:
        A true type font.
        Throws:
        java.io.IOException - If there is an error loading the file data.
      • loadTTF

        public static PDTrueTypeFont loadTTF​(PDDocument doc,
                                             java.io.File file)
                                      throws java.io.IOException
        This will load a TTF to be embedded into a document.
        Parameters:
        doc - The PDF document that will hold the embedded font.
        file - a ttf file.
        Returns:
        a PDTrueTypeFont instance.
        Throws:
        java.io.IOException - If there is an error loading the data.
      • loadTTF

        public static PDTrueTypeFont loadTTF​(PDDocument doc,
                                             java.io.InputStream stream)
                                      throws java.io.IOException
        This will load a TTF to be embedded into a document.
        Parameters:
        doc - The PDF document that will hold the embedded font.
        stream - a ttf input stream.
        Returns:
        a PDTrueTypeFont instance.
        Throws:
        java.io.IOException - If there is an error loading the data.
      • loadTTF

        public static PDTrueTypeFont loadTTF​(PDDocument doc,
                                             java.io.InputStream stream,
                                             Encoding enc)
                                      throws java.io.IOException
        This will load a TTF to be embedded into a document.
        Parameters:
        doc - The PDF document that will hold the embedded font.
        stream - a ttf input stream.
        enc - The font encoding.
        Returns:
        a PDTrueTypeFont instance.
        Throws:
        java.io.IOException - If there is an error loading the data.
      • loadTTF

        public static PDTrueTypeFont loadTTF​(PDStream fontStream,
                                             Encoding enc)
                                      throws java.io.IOException
        This will load a TTF to be embedded into a document.
        Parameters:
        fontStream - a ttf input stream.
        enc - The font encoding.
        Returns:
        a PDTrueTypeFont instance.
        Throws:
        java.io.IOException - If there is an error loading the data.
      • getawtFont

        public java.awt.Font getawtFont()
                                 throws java.io.IOException
        Looks up, creates, returns the AWT Font.
        Overrides:
        getawtFont in class PDSimpleFont
        Returns:
        returns the awt font to bes used for rendering
        Throws:
        java.io.IOException - if something went wrong.
      • getTTFFont

        public org.apache.fontbox.ttf.TrueTypeFont getTTFFont()
                                                       throws java.io.IOException
        Return the TTF font as TrueTypeFont.
        Returns:
        the TTF font
        Throws:
        java.io.IOException - If there is an error loading the data
      • clear

        public void clear()
        Description copied from class: PDFont
        Calling this will release all cached information.
        Overrides:
        clear in class PDFont
      • getFontWidth

        public float getFontWidth​(int charCode)
        Description copied from class: PDFont
        Determines the width of the given character.
        Overrides:
        getFontWidth in class PDFont
        Parameters:
        charCode - the code of the given character
        Returns:
        the width of the character