Knowledge Base - Wrong fonts' rendering and adding your own fonts (Android)

When you notice that the pdf is rendered with a wrong font, it probably means that the pdf uses a font that is not embedded in the pdf.

In this case the SDK uses a default font to show the content, which may seems different.

If you cannot modify the pdf to embed the font, you can use the SDK to add the font, the steps are:

You should include YOUR_FONT font as raw resources in your own project (name it ViewLib\res\raw\YOUR_FONT).

After that you should add this code in Init method of Global.java

File file = new File("/system/fonts/YOUR_FONT.ttf");
if(file.exists())
fontfileListAdd("/system/fonts/YOUR_FONT.ttf");
else
load_truetype_font(res, R.raw.YOUR_FONT, new File(files, "YOUR_FONT.ttf")); 

 

 

For old versions of the library you should need this :

1.     Download the font and add it to the assets folder (in this example we add “Times New Roman”).

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.

Applies To

RadaeePDF SDK for Android

Related Articles

Add your own fonts (iOS)

Wrong fonts' rendering (iOS)

Details

Created : 2015-01-16 18:13:59, Last Modified : 2018-02-07 09:27:06