- java.lang.Object
-
- com.itextpdf.text.pdf.PdfEncodings
-
public class PdfEncodings extends java.lang.ObjectSupports fast encodings for winansi and PDFDocEncoding. Supports conversions from CJK encodings to CID. Supports custom encodings.- Author:
- Paulo Soares (psoares@consiste.pt)
-
-
Field Summary
Fields Modifier and Type Field Description protected static intCIDCHARprotected static intCIDNONEprotected static intCIDRANGEstatic byte[][]CRLF_CID_NEWLINEAssumes that '\\n' and '\\r\\n' are the newline sequences.
-
Constructor Summary
Constructors Constructor Description PdfEncodings()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddExtraEncoding(java.lang.String name, ExtraEncoding enc)Adds an extra encoding.static voidclearCmap(java.lang.String name)Clears the CJK cmaps from the cache.static java.lang.StringconvertCmap(java.lang.String name, byte[] seq)Converts abytearray encoded asnameto a CID string.static java.lang.StringconvertCmap(java.lang.String name, byte[] seq, int start, int length)Converts abytearray encoded asnameto a CID string.static byte[]convertToBytes(char char1, java.lang.String encoding)Converts aStringto a byte array according to the font's encoding.static byte[]convertToBytes(java.lang.String text, java.lang.String encoding)Converts aStringto a byte array according to the font's encoding.static java.lang.StringconvertToString(byte[] bytes, java.lang.String encoding)Converts a byte array to aStringaccording to the some encoding.static booleanisPdfDocEncoding(java.lang.String text)Checks istextonly has PdfDocEncoding characters.static voidloadCmap(java.lang.String name, byte[][] newline)Loads a CJK cmap to the cache with the option of associating sequences to the newline.
-
-
-
Field Detail
-
CIDNONE
protected static final int CIDNONE
- See Also:
- Constant Field Values
-
CIDRANGE
protected static final int CIDRANGE
- See Also:
- Constant Field Values
-
CIDCHAR
protected static final int CIDCHAR
- See Also:
- Constant Field Values
-
CRLF_CID_NEWLINE
public static final byte[][] CRLF_CID_NEWLINE
Assumes that '\\n' and '\\r\\n' are the newline sequences. It may not work for all CJK encodings. To be used with loadCmap().
-
-
Method Detail
-
convertToBytes
public static final byte[] convertToBytes(java.lang.String text, java.lang.String encoding)Converts aStringto a byte array according to the font's encoding.- Parameters:
encoding- the encodingtext- theStringto be converted- Returns:
- an array of
byterepresenting the conversion according to the font's encoding
-
convertToBytes
public static final byte[] convertToBytes(char char1, java.lang.String encoding)Converts aStringto a byte array according to the font's encoding.- Parameters:
encoding- the encodingchar1- thecharto be converted- Returns:
- an array of
byterepresenting the conversion according to the font's encoding
-
convertToString
public static final java.lang.String convertToString(byte[] bytes, java.lang.String encoding)Converts a byte array to aStringaccording to the some encoding.- Parameters:
bytes- the bytes to convertencoding- the encoding- Returns:
- the converted
String
-
isPdfDocEncoding
public static boolean isPdfDocEncoding(java.lang.String text)
Checks istextonly has PdfDocEncoding characters.- Parameters:
text- theStringto test- Returns:
trueif only PdfDocEncoding characters are present
-
clearCmap
public static void clearCmap(java.lang.String name)
Clears the CJK cmaps from the cache. Ifnameis the empty string then all the cache is cleared. Calling this method has no consequences other than the need to reload the cmap if needed.- Parameters:
name- the name of the cmap to clear or all the cmaps if the empty string
-
loadCmap
public static void loadCmap(java.lang.String name, byte[][] newline)Loads a CJK cmap to the cache with the option of associating sequences to the newline.- Parameters:
name- the CJK cmap namenewline- the sequences to be replaced by a newline in the resulting CID. SeeCRLF_CID_NEWLINE
-
convertCmap
public static java.lang.String convertCmap(java.lang.String name, byte[] seq)Converts abytearray encoded asnameto a CID string. This is needed to reach some CJK characters that don't exist in 16 bit Unicode. The font to use this result must use the encoding "Identity-H" or "Identity-V". See ftp://ftp.oreilly.com/pub/examples/nutshell/cjkv/adobe/.- Parameters:
name- the CJK encoding nameseq- thebytearray to be decoded- Returns:
- the CID string
-
convertCmap
public static java.lang.String convertCmap(java.lang.String name, byte[] seq, int start, int length)Converts abytearray encoded asnameto a CID string. This is needed to reach some CJK characters that don't exist in 16 bit Unicode. The font to use this result must use the encoding "Identity-H" or "Identity-V". See ftp://ftp.oreilly.com/pub/examples/nutshell/cjkv/adobe/.- Parameters:
name- the CJK encoding namestart- the start offset in the datalength- the number of bytes to convertseq- thebytearray to be decoded- Returns:
- the CID string
-
addExtraEncoding
public static void addExtraEncoding(java.lang.String name, ExtraEncoding enc)Adds an extra encoding.- Parameters:
name- the name of the encoding. The encoding recognition is case insensitiveenc- the conversion class
-
-