How to convert .doc / .xls file into PDF using Java - java

I want to convert .doc/.xls file into PDF through my java application. Now, I know there have been some discussions on this topic. I also know that JODConverter is one option, but the problem with this is dependency on OpenOffice. Whoever wants to use my app will first need to install OpenOffice on his/her host. I want to avoid this. Do we have any new solution through which I can do this conversion in my app without having dependencies on any other applications.

You could use POI for reading XLS and DOC, and use iText for generating the PDF.
POI project:
http://jakarta.apache.org/poi/
iText project:
http://www.lowagie.com/iText

Related

Any Java api similar to open xml sdk 2.0?

Is there any java api which is similar to open xml sdk 2.0. Just I need to convert open office xml excel file to .xlsx file.
office xml excel file I'm creating by using xml and xslt. I tried apache poi to read xml excel file but getting invalid header format exception.
Thanks.
Well, I believe the best API out there to handle *.xlsx files is Apache POI (it has *.xlsx support since 3.7 or so).
Some alternatives:
There was a project called JExcel API, but there's not much activity there in the last 3 or so years (and I'm not sure if it handles *.xlsx format, only *.xls, but I might be wrong).
I'm not sure, but the OpenOffice UDK might also help you. Unfortunately it is only a binding, and requires an installed implementation (i.e., you have to install OpenOffice in order to use it), which is not always a valid requirement on the server side if you do not have any X servers there.
Another option is something like using it through Jacob via COM. The pro is that you are able to access all ow the data, the con is COM, you need an installed Excel on your machine (and of course, it is a Windows-specific solution).
I believe the best way to stick to Apache POI, it is usually perfectly enough if you just want to read/write cell data.

Open Microsoft Word docx file with Java

How can I open a Microsoft Word docx file in Java? furthermore, how can I open it if it is password protected?
For instance,
File f = new File("hello.docx");
Please try to avoid responding with things such as "you shouldn't do this." I have a good reason for this, so please stick to the question when you answer. thanks a lot!
There is Apache POI project for working with MS Office files. DOCX file is just a zip file with series of XML files inside, so you can unzip the file and work with XML. The XML spec (Open XML) is known.
I haven't personally used it, but it looks like Apache POI will work for you: http://poi.apache.org/
You can use docx4j too. http://www.docx4java.org/trac/docx4j
I have used both docx4j and Apache's POI libraries, if you are working with .docx I would recommend .docx4j. Automated alot of the process of creating a .docx.
There is a great exmaple here : http://java.dzone.com/articles/create-complex-word-docx
on how to create a .docx using the docx4j package.
If the docx is password protected, it won't be a zip file. It will be a compound file. See Overview of Protected Office Open XML Documents
To read a compound file in Java, use POIFS. POIFS is part of POI (docx4j uses it as well, so if you download the docx4j distribution, you'll be able to use the POIFS API)
Once you have decrypted the encrypted package, you can read it using docx4j or POI.
Edit: OK, now docx4j can handle password-protected docx automatically.
Have you tried to open it using the Open Office api? It can work with a lot of documents types.
I used it with MS Excel files .xls ( old version ) format.
Hope this can help you.

How to extract data from a pdf file using JPedal?

Actually I am attempting to extract the data from a PDF file but I didn't find any example in the internet and I am asking if there is any possibility that I can use the JPedal library to open to read the data from a PDF file.
You can use PDFBox from Apache.
I am not familiar with JPedal, but I write lots of code that generates and processes pdf files. I use IText and highly recommend it. If you have a specific question on how to process a pdf file, let me know.

Convert file .pptx to image using Java

Is there a way to convert pptx to an image? My aim is to finally generate an PDF file.
I try with Aspose but there are some issue. With Apache POI, it don't support PPTX. Any other idea?
There is a PPTX SVGExporter in DocX4j that may help you, in conjonction with Batik (from SVVG to PDF)
Note : I've not tested it
You may be able to write a small native library that Java calls to do the operation. I'm pretty sure you can use a .NET language or C++ to connect to powerpoint and have it "print" to either PDF or some other usable format. Here is a small sample application which does some automation.

Converting .xls to .pdf using Java(or not)

Is there a way to convert a xls file into a pdf?
I want to make a dynamical report directly to pdf file, but didn't find a way to make dynamic columns on iReport, so I've made a method on Java that exports to xls dynamically.
So I was wondering if is there a way to convert this file to pdf, but it need to be on a method from my code. Or if you have a better idea, it can be used too.
Maybe there's a way to make this pdf file from my code as I did with xls. Please help me out.
Thanks.
Try using iText http://itextpdf.com/ - I've used it to create PDFs with columnar structure.
In addition to using iText directly, there are a couple report engines that sit on top of it:
Eclipse BIRT (using 2.1.7, the last MPL/LGPL version)
Jasper Reports (which uses a Very Old version, 1.3.1 IIRC)
This is a commercial solution:
http://www.dancrintea.ro/xls-to-pdf/
If you want open source try jakarta POI.
Try using the Muhimbi PDF Converter Services. It comes with a Java compatible Web Services based interface and sample code. It does other things as well.
I worked on this application, so the usual disclaimer applies.

Categories

Resources