Anil Kumar
Anil Kumar

Reputation: 2741

Apache PDFBox: Can I set font other than those present in PDType1Font

I can see only 4 fonts with variants in PDType1Font. Is there any way I can use other / custom fonts?

PDFType1Font fonts

  public static final PDType1Font TIMES_ROMAN = new PDType1Font("Times-Roman");
    public static final PDType1Font TIMES_BOLD = new PDType1Font("Times-Bold");
    public static final PDType1Font TIMES_ITALIC = new PDType1Font("Times-Italic");
    public static final PDType1Font TIMES_BOLD_ITALIC = new PDType1Font("Times-BoldItalic");
    public static final PDType1Font HELVETICA = new PDType1Font("Helvetica");
    public static final PDType1Font HELVETICA_BOLD = new PDType1Font("Helvetica-Bold");
    public static final PDType1Font HELVETICA_OBLIQUE = new PDType1Font("Helvetica-Oblique");
    public static final PDType1Font HELVETICA_BOLD_OBLIQUE = new PDType1Font("Helvetica-BoldOblique");
    public static final PDType1Font COURIER = new PDType1Font("Courier");
    public static final PDType1Font COURIER_BOLD = new PDType1Font("Courier-Bold");
    public static final PDType1Font COURIER_OBLIQUE = new PDType1Font("Courier-Oblique");
    public static final PDType1Font COURIER_BOLD_OBLIQUE = new PDType1Font("Courier-BoldOblique");
    public static final PDType1Font SYMBOL = new PDType1Font("Symbol");
    public static final PDType1Font ZAPF_DINGBATS = new PDType1Font("ZapfDingbats");

Upvotes: 2

Views: 15175

Answers (1)

Tilman Hausherr
Tilman Hausherr

Reputation: 18851

You can load truetype fonts like this in Apache PDFBox 2.0.*:

PDType0Font font = PDType0Font.load(document, new File("c:/windows/fonts/simhei.ttf"));

See also the API documentation and the EmbeddedFonts.java example.

Upvotes: 6

Related Questions