I would like to render/open PDF file (stored in SDCard) in Android without using in-build application or viewer.
1) We have tried MuPDF open source library but rendering using this library is very slow.
2) Can we use iText library for rendering PDF files in Android (i.e. iText as a PDF Viewer).
Is there any other PDF library(open source) that can be used in Android Or suggest basic guideline for developing PDF viewer for Android.
1) MuPDF is good to render textbook pdf in android while it may be slow to render pdf with big images. A lot of customizations and improvements especially memory usage control need to do if you want the MuPDF to run fast and stable on android platform. You can check out two open source projects VuDroid and apv which are based on MuPDF.
2) It's up to your requirements. The iText may be enough to render simple text pdf, but I don't think it has better performance than MuPDF or other libraries that developed by using C/C++.
Another choice is to use Poppler. A successful story is the popular android app ezPDF Reader is based on Poppler, although it's violating GPL license. The out of box Poppler needs more work than MuPDF to do to run on android smoothly. You can refer to the open source project apdfviewer.
I've done some research in this field recently, I've tried more than 14 libraries on Android, I've done simple benchmarking on some high resolution print-ready PDF magazines and I'm currently considering to use MuPDF or Radaee in work as they went out as the best.
I've tried VuDroid and apv as well and they are very unstable, they are crashing very often on complex PDF documents and very slow in comparsion to MuPDF or Radaee.
Since MuPDF and Radaee (and some other libraries) are written in pure C and are used on Android through NDK, they are giving the best possible performance (and they both are paid for a commercial use).
Take a look at my PDF reader for Android here at anddev.
As I remember it uses modified PDFBox (without things related to editing), and features my own font converter (to feed fonts to Android and render them faster).
I don't develop PDF reader anymore and I can make all my changes opensource (though it will require some work, and time). You can try it out to find out how well it performs for you. Note: reader doesn't support encryption and copy-protection.
Related
Recently I am working on commercial project which requires to generate a PDF based on some dynamic HTML content, now I have implemented that with a java library called WKHTMLTOPDF (http://wkhtmltopdf.org/).
This library is a command line tool which user browser webkit as rendering engine, since I am new to java development, I am not sure whether there is any security or performance issue when using this library.
If this is not a good solution, is javascript plugin an alternative?
Sorry for my english!:)
I've worked on the same sort of thing recently. I used iText and found it immensely useful. I haven't used WKHTMLTOPDF but I'm answering since you seem to explore more on other options which could be better, safer. iText has been here for a long while now, and it's pretty simple to use.
Follow these links for more info on iText,
How to convert HTML to PDF using iText
And,
Converting HTML files to PDF
A small/sleek tutorial http://hmkcode.com/itext-html-to-pdf-using-java/
If you are concerned about any sort of licensing issues follow,
Is iText 5.4.2 open source?
I found iText quite handy and is supported by a most of the browsers too. (Chrome, IE, Firefox, I haven't tested on res of them) Hope this helps.
I would suggest you to use PD4ML library available purely in JAVA .It is easy to use and generates PDF from HTML (dom) quickly.
http://www.pd4ml.com/
I've got a Spring MVC webapp written in Java which you can upload images too. These images need to be manipulated (resized, cropped, etc) and I'm using the Scalr library for this, which requires the images to be read from a BufferedImage.
In Java you can convert from an InputStream (which is how images come in) to a BufferedImage very easily:
final BufferedImage img = ImageIO.read(in);
However, ImageIO is really pernickety about image formats and throws all sorts of exceptions if something isn't right about the image. Users could be uploading almost any quality of image to the web app, so this isn't acceptable.
So I'm looking for an alternative. I've done some googling and one suggestion was Java Advanced Imaging from Oracle. The only problem is that it appears to rely on the Oracle Java implementation and I'm not using that.
Is there another library I can use?
I'd say, don't change your code just yet!
The good thing about the ImageIO library is that it is completely plugin-based. If it doesn't read the formats you need right out of the box, you can add support very easily.
I've written a couple of plugins for the TwelveMonkeys ImageIO project (in particular, it includes a JPEGImageReader that supports CMYK color space).
Werner Randelshofer's CMYKJPEGImageReader linked by #MadProgrammer is another plugin you could try out.
JAI, as you have mentioned, also has plugins that allows you to read CMYK JPEGs (I think), however many of the plugins requires native libraries and extra installation that might be a hassle in a web app context. The project also hasn't been updated for years.
I'm sure there are commercial plugins available too, but I haven't researched these.
If you really want to change library, have a look at Apache Commons Imaging. It has a very nice API, and supports many formats. Images are read into BufferedImages. Their JPEG support, however, isn't very mature at the moment, so it most likely will not read your image.
JMagick and im4java both use ImageMagick which has very good support for many formats. Requires native IM installation. The APIs are file based however, which means you often have to write your streams to a temp file before processing. Also doesn't directly support BufferedImages, but you can convert if you like, and in many cases you can use IMs built in image manipulation instead of Java.
Again, there might be complete commercial library alternatives, either in Java or based on native code.
I was looking at different ways to create PDF reports for our clients report tool. I found this link where they can perform action and forms on a PDF document. Is it possible to generate those PDF's programmatically? Like is there any API that can create such a PDF?
I have used apache POI and iText but it don't have these capabilities. Have any one have come across any open source or commercial tools for this purpose?
My main target users will be iPad users. So having this API in objective c will also help.
This PDF was generated with Adobe InDesign CS5.5 (v7.5.3) and bases on PDF version 1.7. Adobe put a lot effort into generating interactive PDFs. As far as I know you can embed HTML 5 content to achieve fancy-looking animations.
There is also a Adobe InDesign Server (approx. USD 14'000+) that helps you to automate your publishing process.
I am a little bit out of touch with them, but it could be that pdflib is able to add active elements.
On the other hand, there are big differences in the capability to handle smart PDF between the various PDF viewers on iDevices, and you might have to do extensive testing. Therefore, the suggestion by Ben may be the better path for iDevices as primary target.
Well if you use a Mac you can use iBooksAuthor. It´s a mixture of WYSIWYG and code. Basically it´s WYSIWYG, but you can easily add more than the in iBooksAuthor included interactivity by using HTML (and JS + CSS) iFrames. I don´t know if it produces PDF but it definitely outputs some iPad capable file cause it´s a programm by app that targets interactive textbook production for ipads and macs. This i a very easy to use (and free) solution if you are targeting mainly ipads and some macs and iphones.
I am currently working on a small project, which shall load an image from an URL, resize and change it's colour depth to only 16 colours using a specified colour palette. The main problem for me is, that I want a program, which I can use on an Android device and on a desktop computer.
Do you know a good image processing library which works on both systems?
Thanks in advance.
There are several tools:
ImageJ, http://rsbweb.nih.gov/ij/
Fiji, http://fiji.sc/wiki/index.php/Fiji
IMMI, http://www.burgsys.com/image-processing-software-free.php
BoofCV: http://boofcv.org
The answers on this page are quite dated as of February 2014. I was searching to find a free Android image processing library and I came across the Stanford lecture notes here: http://www.stanford.edu/class/ee368/Android/index.html
Investigating a bit further, I found out that they are using OpenCV in their course material. It has a Java interface (along with many other languages), but the library is written natively in C++. They state that:
Along with well-established companies like Google, Yahoo, Microsoft,
Intel, IBM, Sony, Honda, Toyota that employ the library, there are
many startups such as Applied Minds, VideoSurf, and Zeitera, that make
extensive use of OpenCV.
I am excited(!) to have found this, looking forward to going home and giving it a go.
The Android NDK allows you to use an existing C/C++ library that does not require java.awt or any of the Android classes. For example, you could easily compile libpng as a shared library for Android and then write a JNI interface to pass images from the Java layer to the png library. Similarly, you will also be able to compile libpng as a shared library for your desktop computer and use it from there.
I recently wrote a tutorial on how to compile open-source libraries for Android. If you browse the Android source, you will find some classes that use the skia graphics library via jni. I have not used skia before, but since Android has skia in its base framework, it should not be too difficult to get it to work in your app/desktop program.
Writing cross-platform programs has been an area of active interest amongst the mobile developers community, and some engines such as libgdx have gotten really good at it. So what you are attempting is definitely possible.
Octoate,
I don't think there is a library that exists that does what you want, the reason for that is on non-mobile platform every graphical operation you are going to use in Java is going to use the Java2D rendering pipeline to some degree. On Android, this doesn't exist.
Android provides its own graphical pipeline for image manipulation and actually simplifies a lot of things that are more complicated in standard Java.
All that being said, it looks like you found a library (JJIL) that acts as an abstraction layer on top of these differences, in that case I would be a bit worried about performance and do some testing in your own code to see how it performs compared to the platform methods. For example, I saw this quote from JJIL:
allows images to be converted from Android bitmaps into JJIL RgbImages
When I look at the source for RgbImages, it looks like the image data gets converted and stored in an internal array; all of those layers of abstraction are going to cost you CPU time and memory, especially as images on mobile devices get bigger due to higher resolution cameras and high-bandwidth connections.
This may not be that big of an issue, but again, you'll probably want to do some profiling/testing/performance comparisons.
Any pure Java library should work on both platforms. A Google search of "Java image processing library" produced several results. Try to find the lightest weight lib that serves your purposes since memory and CPU are limited on mobile devices.
Barry
I am trying to write a Java application that will generate SVG image based on XML file. The application should also be able to show SVG file. My application should run on Android platform and desktop PCs. I read about Swing + Batik but afaik it will not work on Android. What is the best library to achieve this ?
This article in Code Project deals with the subject. Two approaches are presented:
android-libsvg library.
Anti Grain Geometry engine.
Both solutions have dependencies on native code library, so you would need JNI.
There is also svg4mobile project, which only uses Java.
per this thread: libsvg ported
libsvg has been ported to android..see thread for details. You need a crystax form of NDK, ie exceptions enabled..build/install doc here at:build-install-doc
Also try this open-source library, Apache 2.0 license:
SVG-Android
Performance is good as the actual drawing is handled natively by an android.graphics.Picture object.