Can we draw PieChart in PDF using itext Android? - 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.createGraphics(width, height,
new DefaultFontMapper());
Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, width,
height);
that are actually awt classes and not available in android version of itext-5.
Any alternate to using 2D classses ?
Edited: I am using itextg version for android. Its missing 2D classes mentioned above.

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:
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Bitmap bitmap = pieChart.getChartBitmap();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
Image myImg = Image.getInstance(stream.toByteArray());
myImg.setAlignment(Image.MIDDLE);
document.add(myImg);
Cheers!

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.

Related

Gaussian blur with opencv in ios

I am trying to make a gaussian blur with opencv in ios. I have already included opencv into my app, but I don't know how to call it so that it makes a gaussian blur.
In Android I call it like this:
Mat source = Highgui.imread(filepath, Highgui.CV_LOAD_IMAGE_COLOR);
Mat destination = new Mat(source.rows(),source.cols(),source.type());
Imgproc.GaussianBlur(source, destination, new Size(45, 45), 0);
Highgui.imwrite(getDir().getPath() + File.separator +"Gaussian45.jpg", destination);
Is there something similar in iOS too?
Thanks for your answers.
By the looks of things, You have to convert it to a cv::Mat, then you can use the normal guassian blur c++ method and then convert it back to ULLImage
The above link demonstrates how to convert from and to the two image types. Once you have converted it to cv::Mat you simply use this method:
void GaussianBlur(InputArray src, OutputArray dst, Size ksize, double sigmaX, double sigmaY=0, int

Thumbs from pdf android

I want to displaythe thumb images of pdf in my app. I am using this answer. But I don't know how to use it in android as Rectangle2D can't be userd in java. I tried using RectFand modified the code as:
File file = new File(arrayOfResults.get(arg0).filePath);
RandomAccessFile raf = new RandomAccessFile(file, "r");
FileChannel channel = raf.getChannel();
ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY,
0, channel.size());
PDFFile pdffile = new PDFFile(buf);
// draw the first page to an image
PDFPage page = pdffile.getPage(0);
// get the width and height for the doc at the default zoom
RectF rect = new RectF(0, 0, (int) page.getWidth(),
(int) page.getHeight());
But the app crashed with the following error:
java.lang.NoClassDefFoundError: java.awt.geom.Rectangle2D$Double
at com.sun.pdfview.PDFFile.parseNormalisedRectangle(PDFFile.java:1874)
Please help.
Android added a PdfRenderer class that can do that in API 21.
If you need to go below that, you need to ship with your own PDF render engine. We've looked at the marketplaces and found that the options are all lacking in one way or another, and created PSPDFKit for Android. It's a commercial PDF framework and (full disclaimer) I'm part of the team that builds it.
In PSPDFKit for Android, you can use renderPageToBitmap to render the PDF into a bitmap.
If your project is personal or you are an indie, try http://plugpdf.com/
They offer their Android PDF SDK free for you. You can also check out their blog article about rendering a PDF page to bitmap image on Android. http://plugpdf.com/how-to-render-a-pdf-document-to-bitmap-image-on-android/
Disclaimer: I am the Founder & CEO at ePapyrus Inc. which runs plugpdf.com.

Creating Image instance from drawable images in android

i am creating digital signature app using iTextG jar, to add water mark on the signature field, iText's
appearance.setImage(Image.getInstance(signedImagePath));
Requires a path of the watermark image, i want to use image from drawable folder of android, kindly suggest me i am not getting how to create Image instance from drawable, suggest if any other option is there?
You use ImageInstance something like this.
Bitmap bitmap = BitmapFactory.decodeResource(getBaseContext().getResources(),R.drawable.yourimage);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100 , stream);
Image myImg = Image.getInstance(stream.toByteArray());
Hope this helped.
http://developer.android.com/reference/android/graphics/BitmapFactory.html#decodeResource(android.content.res.Resources, int, android.graphics.BitmapFactory.Options)

How to save Bitmap to .tiff in Android?

I know it is possible to save bitmap to png or jpg
now i want to save bitmap to .tiff,anybody can help?
Android does not have native support for saving TIFF files.
You best bet would be to get the raw byte array, and then using either a Java or NDK library (like libtiff) to save it as a TIFF.
I believe this is is a repost from here:
Convert a bitmap image to an uncompressed tif image in Java
To answer the question, the above answer suggested the following using the Java Advanced Imaging (JAI) library:
TIFFImageWriterSpi spi = new TIFFImageWriterSpi();
ImageWriter writer = spi.createWriterInstance();
ImageWriteParam param = writer.getDefaultWriteParam();
param.setCompressionMode(ImageWriteParam.MODE_DISABLED);
ImageOutputStream ios = ImageIO.createImageOutputStream(new File("output.tif"));
writer.setOutput(ios);
writer.write(null, new IIOImage(bmp, null, null), param);
You always can save the Bitmap as .png and convert it to .tiff
Android hasn't support for tiff images. You should use some library for working with tiff. For example my: https://github.com/Beyka/Android-TiffBitmapFactory

How can i use poi to read ppt?

i find it supports well in Java,i can convert it to jpg;
but when i use it in Android,bufferimage,graphics,imageio are not support
becuase android drop the java.awt
so if i want to use poi in android,how can i do
tell me something useful, thks.
swamy gave you rather useful link.
as of bufferedImage, you can adopt it and write your own adapter, as I did:
BufferedImage image = ImageIO.read(url);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write( image, "jpeg", baos );
baos.flush();
byte[] imageInByte = baos.toByteArray();
baos.close();
int idx = ppt.addPicture(imageInByte, XSLFPictureData.PICTURE_TYPE_JPEG);
XSLFPictureShape pic = xslfSlide.createPicture(idx);
I got docx4j (which can handle pptx) running on Android; see jaxb-can-be-made-to-run-on-android
The reason I mention this, is I had to overcome java.awt issues, which might help you. I repackaged as https://github.com/plutext/ae-awt
If you want to use that with POI, you'd have to alter the references in POI.
If you are just using pptx, you might find it easier to use docx4j (since with POI, you'll probably also need to get XML Beans working on Android).

Categories

Resources