I know there are tons of library for converting between documents format for PHP, Java etc.
But I wanted to know if there is any pure javascript libary for converting between document formats.
I want the conversion to take place at client side itself without sending it to the server.
Is it possible or is it farfetched?
It is possible. For example you can use jsPDF to generate PDF documents. But it is generally not advisable to do document conversion on the client side due to all the unknown variables (i.e. doc versions, client computer capacity, etc....) A server library meant for document conversion will have much more robust handling of all the various conditions that may arise when trying to process documents. Hope that helps!
Related
I was wondering if somebody succeeded in transforming from MathML expressions into images in GAE.
GAE imposes many limitations on the classes allowed (bye bye FOP/ JEUclid) and I cannot do the logic in the front-end (mathjax) since the target is to print a pdf.
So far I contemplate either changing PaaS or switching to managed vm in GAE but it seems rather overkill.
Thanks
I have such experience, with processing math formulas and generating a PDF. It took a time, but I managed to do that on Appengine. I tried most of know libraries, including FOP, none of them works on gae, of course.
What I'm using:
mathtex.cgi for math render. It can generate an image through HTTP call, just pass formula in request, and get a PNG. I've installed on separate server (I already had this server, very basic one, for wordpress and stuff, so that was not a problem). Also you could find few public servers with mathtex.cgi, including official one, that you can use w/o having own server
appengine-itext for PDF. It have some minor issues, but mostly works. To put formulas into PDF I've following hack: a simple regex replaces math code with a <img> tag that points to a dummy protocol math://, then I have a custom ImageProvider that renders formula by using MathTex for such urls
for browser clients MathJax works fine
Little bit hacky, and requires a cheap external server, but that works
I have a client-server system implemented in C#, and the client and server exchange .Net objects via serialization / deserialization and communicating via TCP/IP. This runs on a local network, it is not web-based or Internet-based.
Now I want to include Android clients connected by wifi. Again, this is local network only, not via the Internet and not web-based. The Android programming will be in Java. (I am aware of Mono for Android, but prefer not to get into that now.)
Is there some fairly simple way to implement object to object interchange between Java and .Net objects, provided, of course, that they are compatible?
I've looked a bit at JSON (Jackson on the Java end and Json.Net on the .Net end), and I'm guessing it can probably be done, but only with major efforts on remapping things at each end as soon as the objects become fairly complicated.
Any other suggestions? JSON-based or otherwise?
PS. My question is somewhat related to this one Mapping tool for converting Java's JSON to/from C#, but it never got a suitable answer, perhaps due to insufficient info in the question. Also, I don't care whether I end up using a JSON-based transport or XML or something else.
I would suggest either JSON or XML (which is based on a .xsd file) because these are independent of their respective implementations (instead of something like an ObjectOutputStream in java).
The problem of having this format between the two components (client and server) is that they need to be at the same version. My best practice is to have one underlying definition of the format (i use xml with an xsd file which specifies how the xml has to look like), then use jaxb to generated java classes. That way you can (un)marshal from/to xml in the java part.
I am very sure a similar thing exists in the world of .NET.
JSON is smaller than xml in size, i find xml to be more readable.
SO user "default locale" should get the honor for this, but he/she has only answered via a comment. So just to make it very clear what my choice was I'll answer my own question.
I've decided to go with Google Protocol Buffers, which in my opinion has much better support for moving objects back and forth between Java and .Net than JSON. Because I have a lot of experience with C#, and a lot of existing C#-defined classes, I've selected Marc Gravell's protobuf-net program for the .Net end, and Google's own support for the Android end (no - see edit). This implies that I'm defining the objects in C#, not in .proto files - protobuf-net generates the .proto files from which I then generate the Java code.
Incidentally, as the transport mechanism I'm using a little-known program called naga on the Android end. http://code.google.com/p/naga/ Naga seems to work fine, and is well-documented and has sample programs, and should be better known in my opinion.
EDIT:
OK, I've got it working now to my satisfaction. Here's what I'm using:
Google Protocol buffers as the interchange format: https://developers.google.com/protocol-buffers/
Marc Gravell's protobuf-net at the C# end: http://code.google.com/p/protobuf-net/
A program called called protostuff at the Java end: http://code.google.com/p/protostuff/
(I prefer protostuff to the official Google Java implementation of protocol buffers due to Google's implementation being based on the Java objects being immutable.)
Actually, I'm not using pure protocol buffers as the interchange format - I prefix the data with the name of the (outermost) class being transmitted. This makes the data self-identifying for deserializing at the other end.
You can also try wox (https://github.com/codelion/wox), it is a cross platform serialization library for Java and C# based on XML.
I'm developing a Java application that handles and analyses different types of data and what I want is to display this data in an user friendly way by using plots and tables in a HTML webpage using jQuery, Highcharts and few other JavaScript libraries.
What's the best way to do this? Is Google Web Toolkit my best bet?
My current solution is to do the analysis and the display of the data completely separated. I run all the analysis in Java an then export the results in Json files and build the plots with JavaScript scripts. Although, this way I'm having issues in handling the increasingly growing JavaScript files. Moreover, a more integrated interface where I could handle everything together would be the perfect solution.
Thanks.
Is your only problem the size of the resulting javascript file? If so, there are a couple of options.
1) Use websockets.
Websockets allow you to have a live connection between the server and the browser. This would allow you to stream the data instead of sending it between the backend and the browser as a server.
2) Serialize your data in a more compressed manner.
JSON is great. It's biggest strengths being it being human readable and playing exceptionally well with Javascript. However, it will add some extra bytes to your data. Not many mind you, but some. However, if size is truly being a problem, then consider creating a more serialized way to pass data, where you have an understanding of how the data should look, then on the browser, you can deserialize it into json, and continue as normal.
3) Compress and decompress
This one is a bit more convoluted, but will probably save you more bytes for the price of slower performance. You can zip the data up before passing it to the client, and unzipping on the browser. See this other question for more details on compression and decompression with javascript.
4) Leave it as is.
I guess I don't have enough context, but I think what you are currently doing should be fine enough. There is always ways to improve, but not sure exactly what you want to improve.
Cheers.
I'm planning on developing an app for android that requires a back-end server to sync data with other users of the app. I'm planning on writing this server in standard java running on a unix server.
I once did this directly between two android devices, in that case I just serialized all the data needed to be sent on both ends.
However I suspect that the format that Dalvik serializes to and Java SE's format are not compatible. Is this the case? And if it is, what are my alternatives? One thing that popped into my mind was sending raw xml over a socket, but if there are better alternatives I'll be glad to hear them.
Thanks.
If you are doing a server then you should rely on something more standard like XML or JSON. I personally favor JSON. You shouldn't expect all your client to be Java friendly. Almost every mobile device support JSON. Look at Jackson library to generate your json. Then you can use Jackson again to deserialize your object.
The beauty of this solution is also stupid simple. You can look at the content by just just putting the request in your browser. Not so easy with binary data.
I have used data serialization successfully between Android devices and servers.
I did have to convert TimeZone class to String and back because the TimeZone class in particular is not fully compatible (it tried transferring something in the sun. package which got ClassNotFoundException on Android).
Other than that I have been able to transfer objects from java.util collections and maps and from java.sql data types and of course the java.lang types String, Integer, etc..
You can try protobuf for serialization. It is said to be more efficient, and you won't be concerned about compatibility.
You can also use some form of XML serialization (JAXB, XStream, XMLEncoder, etc)
The resolution of this question hints that it is compatible.
If your object graph is pretty simple and if you are comfortable with JSON at all, Android has JSON support included and it would be easy to get support in Java SE. I tend to think of JSON as a good alternative for when XML or Java serialization seems to "heavy".
Have a look at this benchmark. Kryo is the one I'm using. It supports creation of the custom binary serialization, which can be done in a way suitable for both Dalvik and JSE.
You may want to look at a related question, which provides additional discussion and links.
Protocol buffers would be a good format over the wire to consider.
I can't speak to the serialization of Dalvik.
I'm learning the Android api from a book, and it seems like there isn't any mention of a stream-lined api for dealing with raw xml (reading and writing). His suggestion for parsing is the XmlPullParser, and his examples look horrendous considering the kind of api's I'm spoiled by in other platforms (LINQ to XML especially).
Is this the best available technique on the Android platform?
Obviously I can write a wrapper to avoid the repetitive stuff, but I'd be surprised if no such thing already exists.
Also, he doesn't even make mention of creating xml structures in code. What are my options for both?
On a side note, do any Java devs that are familiar with LINQ to XML in .Net know of anything equivalent in Java?
Since you probably don't want to load any substantial size DOMs into Android's memory - pull and SAX parsers are preferred way dealing with XML in Android. I think it pays to invest into understanding how SAX works and write a custom handler than rely on some generic libraries that may be incompatible or overbloated. I parse XML in my apps using SAX all the time and I'm very pleased with the speed (most of the time)
Well I'm pretty new to Java, but here's what I've gleaned so far about xml parsing on Android:
The XmlPullParser approach is recommended for Android due to resource constraints. There is a DOM parser available in Android, which would let you use XPath to navigate an xml document. Using the DOM means that you have to load the entire document into memory at once, however. The XmlPullParser method is much more efficient in terms of memory used.
The XmlPullParser method takes a little getting used to after being comfortable with LINQ to XML or XPath, but it's really not too bad IMHO (at least with the documents I was parsing). If you're working with small xml documents you could certainly use the DOM with XPath.
There's a decent article about the different methods for reading and writing XML with Android here:
http://www.ibm.com/developerworks/opensource/library/x-android/index.html
I had the same issues with parsing xml or xhtml and ended up writing a webservice doing it for me.
Android Device ->(Request URL) -> Webservice Get and Parse -
-> (Data) -> Android Device
You can transmit the data in JSON to work with it on the device.
The advantage of this is you can minimize the traffic on the slow mobile network and change the parsing without releasing a new android app.
Maybe this is will work for you too.
regards