The steps (for example to add “Times New Roman”) are:
1. Download the font and add it to the assets folder.
2. In com.radaee.pdf.Global.Init(), copy the font to the internal storage, as follows:
String fontPath = act.getFilesDir().getAbsolutePath() + "/times.ttf";
sub = new File(fontPath);
if (!sub.exists()) {
try {
InputStream src;
FileOutputStream dst = new FileOutputStream(sub);
src = assets.open("fonts/times.ttf");
while ((read = src.read(buf)) > 0) {
dst.write(buf, 0, read);
}
src.close();
src = null;
dst.close();
dst = null;
} catch (Exception e) {
}
}
3. Add your font to the font list between fontfileListStart() and fontfileListEnd() as follows:
fontfileListStart();
…
fontfileListAdd(fontPath);
…
fontfileListEnd();
4. Add font mapping (if-necessary).
fontfileMapping("Times”, “Times New Roman");
You can check font name list after fontfileListEnd() like:
String face_name = null;
int face_first = 0;
int face_count = getFaceCount();
while (face_first < face_count) {
face_name = getFaceName(face_first);
face_first++;
}
When you don't know which font to use in PDF file, you can invoke Document.SetFontDel() to set font delegate, to map a font name to a font path.