How to modify an OpenOffice.org Draw diagram in Java? - java

I have an OpenOffice.org Draw diagram, which shows individual modules of my software.
I also have a file with information about problems in those modules (each module can be in one of 3 states: OK, ERROR, UNKNOWN).
I want to
a) color the figures in the diagram according to the information from the file (problematic modules - red, OK modules - green and all others - gray) and
b) export the diagram to an image file.
The original diagram is created manually (so that it is laid out nicely).
Question: How can I do this, preferably in Java?
Thanks in advance
Dmitri

OpenOffice has an official API. You should check if it can do what you need.
If not, a reasonable way to progress would be to export to SVG, and then use a SVG library to manipulate the SVG XML as needed.

#TRA has a good point. On the other hand, if you're feeling brave..
Open Office files are Zipped XML. Use a ZipInputStream to get access to the entries, then any of the plethora of J2SE based XML handling APIs (Sax, DOM etc.) to parse the XML.

Related

Create .vsdx files (Microsoft Visio) in Java

I'm looking for some info on how to create a .vsdx file in Java without any commercial libraries. According to other questions it seems to be pretty tough.
As a source we have a different, probably unknown file format called .epml that contains graphical information of EPCs which we should be able to convert to a .xml file. As far as I understand the .vsdx format so far, that's one of many files in the unzipped .vsdx required. I'd be glad if anyone could tell me about my options how to implement/create all the other files.
EDIT: The goal here is to be able to convert the graphic information of the .epml file so Visio is able to read & display it as in the source. Therefore, it doesn't have to be a .vsdx file if there are other possible options.
Thanks!
EPML is a not an unknown format, it is an interchange format for EPC tools. Just try to google it :)
I would suggest you convert your .epml files to .svg (there are free open source converters available, like epml2svg). Visio can read and show .svg files. Means - writing code does not seem to be required to achieve your goal (to convert .epml files to something Visio can show). AFAR there is online version of the tool as well - you upload EPML file, get back SVG, and just open it in Visio - that's it.
Side note - there are companies, like bpm-x for example, specializing in BPM tool-to-tool diagram conversion. Maybe they already have a solution for your original tool.
The .VSDX file is "office xml" format, that is also open and documented. But it's pretty tough to generate file from scratch, you are right. So in principle you could start with any code that is capable of handling open xml packages. Microsoft has OpenXML SDK, but that's .NET (MSDN HOWTO assumes you are using .NET, but explains basics of what the open xml package consists of)
AFAIK, for java, there are no open source visio libraries you could use. Java and Visio seem to live in parallel universes. The only viable commercial option I've heard of seem to be Aspose.
Interesting - whilst I cannot give a final answer, here are some thoughts:
Question 1: Why would you want to avoid commercial tools, when the final result file will require some - namely "Visio"?
1) Creating Visio files from XML:
Create template XMLs from a VSDX. Identify the files, that you need to edit. From what I've seen, these should be the masters and the pages files. Being able to make an XML from EPML, you should also know how to adapt it to a new structure.
This solution is probably by far the most tedious and less flexible.
2) Use Visio automation:
Presuming that the final document will need more than just graphics, namely shape data as well, an easier solution would consist of creating the graphics first
a) as SVG and import into Visio
b) even easier - automated drawing by Visio's automation capabilities (VBA, .Net, ...). The shapes to drop would already have been prepared as masters will all the relevant data and behaviour settings.
Then you would populate the data by means of one of the many data linking features (Wizard, Standard data linking, ODBC connections, etc.)

Convert multiple files into PDF

My questions is rather theoretical. I need to implement an application that takes different file extensions such as [asp,bmp,doc,docx,html,jpg,pdf,pdf,png,pptx,sql,txt,xls,xlsx] and converts them all into a consecutive PDF file for print.
I did my research in terms of coding and found multiple libraries that do the job
such as Apache POI, iText, aspose.pdf.jar and others I tested them out on individual portions of the idea. They work great but require a lot of women-hours to implement the desired application. My question is, is there anything more complete that will speed up the job. For example a library such as apache POI that does not require specifying every single padding and background color.
Any suggestions are appreciated.
As per my knowledge and experience not a single API is present there who provide all solution without this. Because of that we need to use Apache POI, iText, aspose.pdf.jar , FOP.
In java(using jquery as per my knowledge) you are able take snapshot of rendered page using stream which you will need to proceed at serverside and generate PDF which generate pdf file same like html page without any extra formatting but it having limitation that you can't use landscape. If page data is big then it shrinks pdf which causes small font(in very large page even you unable to read pdf).

library to bring a pdf to code

I have the need to create some pdf through java code, pdf templates are fixed and are very complex too. Each pdf represents a module and I have to fill it with informations I get from other sources in my application and finally create the complete pdf.
So, is there a library which, given a pdf, scans it and creats some java code which will eventually create it back? This way once I get the pdf template in java code I just have to edit it adding my informations and create it back.
You can check these 2 link it's have all information regarding PDF CRUD operation.
How to read PDF files using Java?
http://mrbool.com/how-to-create-write-and-read-pdf-files-using-pdfone-and-java/27058
I have used with success iText http://itextpdf.com/ for various tasks involving creating, parsing and modifying pdf files. Please not that this one is not free for commercial use and the pricing isn't cheap either.
However, your question is a possible duplicate of the folowing one, so be sure to check the answers there:
https://stackoverflow.com/questions/6118635/what-is-the-best-pdf-open-source-library-for-java
itext is one of best approach for your need..
itext API'S

Optimized graph drawing for the web

Having seen some suggestions for graphs, I wonder what's the optimum for my problem.
I want to render a directed graph to a servlet/picture that is displayed in the browser. There should be some kind of optimization of position. No dependency to Swing would be preferred. Algorithms are not important, since the structure of the graph is determined by business logic. It would be desired to be able add labels to edges as well.
it would be optimal if i can serve this as png/svg.
Which library/service would you recommend?
clarifications:
1) The question is all about Graphs - like Directed Acyclic Graph - NOT - Charts.
2) flot, Google Charts - cannot plot graphs, only charts, or have i missed something?
3) no i do not need interactivity
4) graphviz would be nice, but the grappa java library is quite outdated and is built upon swing/awt. while it may be theoretically possible to render swing to images, it would not be my favorite way to to so in a server-app.
5) it would be fine to use an online service where the images are not hosted locally.
edit: added links to Wikipedia to clarify graph/chart term
Take a look at graphviz
yFiles might be useful for this.
How about the dot component of Graphviz? It produces graphs (not charts), outputs to PNG and SVG, and supports labeling edges. You can shell out to dot to generate the image you need, and return an img tag that references that. Alternatively, you can return an img tag that references a URL that will generate the requisite graph (or retrieve a cached copy). Here's the dot info:
http://www.graphviz.org/pdf/dotguide.pdf
You might also take a look at WebDot, which is apparently designed for this purpose:
http://www.graphviz.org/webdot/
As well as waiting weeks to hear about the Magic Framework that's going to solve all your problems in one line of code, there is also the other option of just Writing Some Code yourself to do exactly what you want... (I'm not saying it's 10 minutes' work, but it's probably one or two days, and you posted your question over two weeks ago...)
Have you had a look, for example, at the Wikipedia entry on Force-based algorithms-- it has pseudocode and a few links that might be helpful.
I'm assuming it is the layout algorithm that's the issue, and not the matter of creating a BufferedImage, drawing to its graphics context, PNG-encoding it and sending it down the socket. You really don't need a framework for that bit, I don't think.
Try aiSee. It is used by all kinds of web-based applications for data mining, static program analysis, matrix visualization, network analysis, and whatnot. It is also used by some MediaWikis as their graph-layout backend.
They have a huge database of sample graphs over at aiSee.com. Check it out. It supports edge labels, export to mapped SVG and HTML, and is not dependent on Swing.
We create mxGraph for such requirements. We did actually release it in 2006, but took a while to notice this question...
For serverside, try JUNG, you can run it against Batik and produce beautiful SVG or PNG files. JUNG has a nice design and very powerful layout algorithms...
Also, since you mention that "it would be fine to use an online service", graphviz provide a service called webdot to render graphs.
There are others along this line as well... e.g. http://graph.gafol.net/ (seems to be down)
Client side:
Try http://arborjs.org/ for a minimal(ish) library it is dedicated to layout, use this is you like to prefer your own rendering routines (div, canvas, svg, paper.js, processing... etc).
I also like http://sigmajs.org/ for a more complete approach, build in touch support, plugins, file formats, etc.
Interestingly, the Eclipse project has an SWT/JFace component/framework capable of displaying and generating (import/export) Graphviz's 'DOT' format, in pure Java:
ZEST (home page & download links)
See http://wiki.eclipse.org/Graphviz_DOT_as_a_DSL_for_Zest for usage examples.
Although ZEST is touted as an Eclipse plugin, it does seem that the DOT-manipulation API's can be used standalone and external to an Eclipse installation.
Cheers
Rich
You may try sigma.js: http://sigmajs.org/
It is a lightweight, open source library in Javascript to display large graphs on the Web.
JPGD is a Graphviz parser in Java. It's a little abandoned, but the code is nice and clear, and if you find bugs I'm sure the author would accept contributed fixes.
Although advertised as a parser, it is also a generator. You can build Graphs as collections of Node and Edge objects, then get .dot using Graph.toString(). Getting this as a graphic would be a simple shell out to the Graphviz dot executable.
Alternatively, dot is very easy to generate yourself. In the simplest case, it's just a matter of writing a potted header
digraph myGraph {
... followed by one edge definition per edge
node1 -> node2 ;
... followed by a closing brace
}
so i took alook at all the given answers and links, it looks like Prefuse/Flare will by the optimal choice.
they have very appealing visialisations, plus they have built in support for graphs.
Maybe check out Google Charts?
You can use SVG in combination with Batik. I have used this several times for displaying graphics. Batik with Java 1.5 is very fast. With this solution you can program your graph in Java with no dependency on Swing. You can add labels where you want, host it as a Servlet and display it as png or svg.
You can create the graphs in SVG (this is an XML document).
You use Batik to transform the SVG-document to a PNG/JPG image.
You can use a Servlet to stream this image back to the browser.
In java you build an SVG(=XML) document. Samples for SVG graphs can be found here:
Directed graph and here: Simple directed graph
See this question, especially Stephan's answer about prefuse. I read that you do not need interactivity, but prefuse still may be useful.
I can whole-heartedly recommend flot - excellent!
See examples here.
JFreeChart might be the way you want to go, but you make a distinction between Charts and Graphs. Maybe you can explain what you mean by that. I've usually used these terms synonymously. :)
JFreeChart has good scatter, bar and line graphs as well as fun ones like Pie and Dial so maybe it will work for you.

How do I use Apache POI to read a .DOC file in Java to separate images from text?

I need to read a Word .doc file from Java that has text and images. I need to recognize the images & text and separate them into 2 files.
I've recently heard about "Apache POI." How I can use Apache POI to read Word .doc files?
The examples and sample code on apache's site are pretty good. I recommend you start there.
http://poi.apache.org/hwpf/quick-guide.html
To get specific bits of text, first create a org.apache.poi.hwpf.HWPFDocument. Fetch the range with getRange(), then get paragraphs from that. You can then get text and other properties.
Here for an example of extracting an image. Here for the latest revision as of this writing.
And of course, the Javadocs
Note that, according to the POI site,
HWPF is still in early development.
It's not free (or even cheap!) but Aspose.Words should be able to do this. Their evaluation download will let you play with small files.
Do the destination files also have to be Docs? You could open the docs in Office and save them out as HTML. Then the separation becomes trivial. RTF is also a viable option, but I can't recommend a good RTF parser off the top of my head.
Edit to say: I just remembered another possible solution: Jacob, but you'll need an instance of Office running on the same machine. It's short for Java COM Bridge and it lets you make calls to the COM libraries in Office to manipulate the documents. I'm sure it's not as scary as it might sound!

Categories