2

I have an XML input file and XSLT code (XSL file) that I use to perform a transformation.

I want to generate PDF from them on Android (after a button click).

I was able to generate PDF on my computer with Apache FOP Java library.

I tried the same approach on Android, but fop.jar has a lot of dependencies. I copied all of them to the Android's libs, but I'm getting a lot of warnings from dx described in this question and finally it's not working. These are the JARs:

avalon-framework-4.2.0.jar  
serializer-2.7.0.jar  
xml-apis-ext-1.3.04.jar
batik-all-1.7.jar           
xalan-2.7.0.jar       
xmlgraphics-commons-1.5.jar
commons-io-1.3.1.jar        
xercesImpl-2.7.1.jar
commons-logging-1.0.4.jar   
xml-apis-1.3.04.jar

So, what can I do to generate that PDF?

I see these options:

  1. Make an empty Android project. Add the source code of that 10 JARs (they're all Open Source). Add stuff which they're importing, but it's not present in Android's Java libraries. Compile it to stand-alone JAR working on Android. Do you think it's possible to do? Seems like daunting task, maybe there's an easier way?

  2. Do it in Cordova's JavaScript, instead of calling Java (with custom plugin). However, I couldn't find any suitable library.

Please suggest me the least time-consuming approach to generate that PDF or propose a different way.

Community
  • 1
  • 1
Adam Stelmaszczyk
  • 19,665
  • 4
  • 70
  • 110
  • 1
    I have edited your question. In my opinion, it's not necessary to show a large picture of the general procedure of an XSLT transformation, because that's really straightforward and has nothing to do with the question. – Mathias Müller Jan 28 '15 at 23:45
  • @MathiasMüller You're absolutely right, thank you Mathias. It's much better now. I can see from your profile that you are much more experienced in XSLT than me, if you could give me an advice how to generate that PDF, that would be much appreciated. – Adam Stelmaszczyk Jan 28 '15 at 23:46
  • 1
    I've never tried to run FOP on Android, and never heard of anyone who did. If you decide for option 1, how can you be sure you're not going to be held back by the fact that the JVM on Android is slightly different? Other thoughts: Do the transformation and rendering need to be done on the device? Why not write a web application? Also, do you really need PDF as the output format? Generating HTML from XML should be easier. Interesting question nevertheless. – Mathias Müller Jan 28 '15 at 23:59
  • [Here, FOP is listed as "inappropriate"](http://stefan.fenz.at/creating-pdfs-on-android-an-evaluation/) - whatever that means. – Mathias Müller Jan 29 '15 at 00:04
  • @MathiasMüller I'm hoping that the difference between JVMs will be not significant. All in all, they're both implementing Java Language Specification, so they should produce the same results, don't they? Generation of PDF is already done on the server side. Web application exists. Now, our team is writing a mobile app (with the same functionality as web app). Our idea was to generate PDFs offline, in the client, so yes, transformation and rendering need to be done on the device. – Adam Stelmaszczyk Jan 29 '15 at 00:15
  • 1
    I'm not an Android dev, but I think porting FOP to Android is going to be painful. But you should be aware that FOP is only the XSL-FO _rendering agent_, the XSLT transformation is not done by FOP. XSLT itself is not a problem on Android. So, you should be able to transform your input XML to any XML document. And then you should perhaps look for another way to generate PDF? For instance, the ["XML Worker" of iText](http://itextpdf.com/product/xml_worker) seems to be promising. – Mathias Müller Jan 29 '15 at 00:27
  • @MathiasMüller FOP is quite memory-hungry, especially when the input has long page sequences; this could be a reason for its "inappropriateness". – lfurini Jan 29 '15 at 17:11
  • 1
    @lfurini I'm not sure "inappropriate" is the right term for a memory-intensive application. If I had to guess, I'd say there are compatibility issues beyond limited amounts of RAM that prevent FOP from running on Android. – Mathias Müller Jan 29 '15 at 17:29
  • I have created an issue on fop project regarding this https://issues.apache.org/jira/browse/FOP-2915 – Binoy Babu Mar 05 '20 at 07:50

0 Answers0