Can We Draw Piechart In Pdf Using Itext Android?
I want to add Pie chart in my PDF using itext in Android. But all the example related to piechart seems to use the following 2D classes: Graphics2D graphics2d = template.createGr
Solution 1:
So i have found a solution. I was using MPAndroidChart for making the PieChart. This library has a method for getting the bitmap from the drawn Piechart.
pieChart.getChartBitmap();
So, once you get the bitmap, iText will let you add the bitmap into your pdf. The final code may looks like this:
ByteArrayOutputStreamstream=newByteArrayOutputStream();
Bitmapbitmap= pieChart.getChartBitmap();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
ImagemyImg= Image.getInstance(stream.toByteArray());
myImg.setAlignment(Image.MIDDLE);
document.add(myImg);
Cheers!
Solution 2:
For Android you need to use itextg
instead of itextpdf
.
Examples that use classes that are not available on Android, should not be used. When you find a solution, it would be nice if you submitted your documentation.
Post a Comment for "Can We Draw Piechart In Pdf Using Itext Android?"