开发者

Android pdf and chart generation

I am new in Android development. I want to create an Android app which will take input from user, gen开发者_运维问答erate a pie chart and then export the report in pdf format. I am using iText(URL) and afreechart (URL) to generate pdf and chart respectively, but I don't know how to convert the generated chart into image, so that I can insert that image into the pdf. Please help.


Why would you convert a perfectly good PDF page into an image before inserting it into another PDF?

PdfReader reader = new PdfReader(path);
//PdfImportedPage inherits from PdfTemplate
PdfImportedPage page = writer.getImportedPage( reader, 1 );

Image wrappedImage = new ImageTemplate(page);
// now do whatever you would normally do to position the image where you want it.

This does not rasterize the imported page. It's still line art, text, and so forth... whatever it was to begin with. But now it's wrapped in an Image so you can conveniently position it with iText layout classes.


Okay. I just read the docs on AFreeChart. Apparently you can only draw to a Canvas.

So draw to a Canvas, then call setBitmap to write it to a BitMap, and call Bitmap's compress method to save it as a JPEG or PNG, your call.

iText can handle either of those image formats just fine. You could probably copy all the pixel information over In The Raw, but this was is considerably less code work on your part.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜