0

I need to generate Hindi PDFs and I am using iTextg for this purpose. To "type" in Hindi, I am using Android's static Layout to convert text to Bitmap. However I am getting really poor text quality.

My Code is as follows

public Bitmap textAsBitmap(String text, float textSize, float stroke, int color, int align) {
//All these flags were added after desperate attempts
    TextPaint paint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.HINTING_ON | Paint.LINEAR_TEXT_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    paint.setTextSize(textSize);
    paint.setColor(color);
    paint.setStrokeJoin(Paint.Join.ROUND);
    paint.setStrokeWidth(stroke);
    paint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL));
    float baseline = (int) (-paint.ascent() + 3f); // ascent() is negative
    Layout.Alignment mAlignment;
    if (align == Element.ALIGN_CENTER)
        mAlignment = Layout.Alignment.ALIGN_CENTER;
    else if (align == Element.ALIGN_RIGHT)
        mAlignment = Layout.Alignment.ALIGN_OPPOSITE;
    else mAlignment = android.text.Layout.Alignment.ALIGN_NORMAL;

    StaticLayout staticLayout = new StaticLayout(text, 0, text.length(),
            paint, 435, mAlignment, 1.0f, 1.0f, false);

    Bitmap image = Bitmap.createBitmap(staticLayout.getWidth(),
            staticLayout.getHeight() + 2, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(image);
    canvas.drawColor(Color.WHITE);

    canvas.drawBitmap(image, 5, 5, paint);

    staticLayout.draw(canvas);
    return image;
}

The Result Result

Help me out as these PDFs are later required to be printed.

user3425867
  • 644
  • 6
  • 14
  • 1
    If you do not convert text to images but keep text as text then the quality will be good. However then the ligatures may be incomplete. For full support of Indic languages you would need the pdfCalligraph add-on of iText 7. But that is not (yet) available for Android. I think you're stuck here, unless you find a way to tell `createBitmap` to increase quality. – Amedee Van Gasse Apr 18 '17 at 05:28
  • I think we need to think in terms of bitmaps now. Could we create a large size bitmap and downscale it. Do you think that would help quality? – user3425867 Apr 18 '17 at 12:02
  • I think you should definitely try it. – Amedee Van Gasse Apr 18 '17 at 12:26

0 Answers0