There is always challenge to convert Microsoft office document to PDF document through open source. I had also some issue when I was working one of the projects and converting Microsoft word doc or Microsoft power point document to pdf document through open source. Here are some steps to convert Microsoft word document or Microsoft power point document to pdf document through Java application and open source.
Prerequisite Requirements for conversion
1.) JDK(1.5+)
2.) Open office version-2.02+(Download from “http://www.openoffice.org/”)
3.) jodconverter2.2.2 (Download from “http://sourceforge.net/projects/jodconverter/files/”)
Here are steps:-
1.) install JDK(1.5+) and Open office version-2.02 in your local machine.
2.) Go to <Open office install folder>/ program/ folder
3.) Run this command through MS dos window.
soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard
4.) Now write the given java code and run
- import java.io.File;
- import com.artofsolving.jodconverter.DocumentConverter;
- import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
- import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
- import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;
- public class MsDocToPdfUtil {
- public static void convertDocToPdf(){
- try {
- File in = new File("C:/test.doc");
- OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
- connection.connect();
- DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
- File outPutFile = new File("C:/test.pdf");
- converter.convert(in,outPutFile);
- connection.disconnect();
- }catch(Exception ex){
- ex.printStackTrace();
- }
- }
- public static void main(String[] args) {
- try {
- convertDocToPdf();
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- }
Rajnish Kumar is CTO of Vanrish Technology with Over 25 years experience in different industries and technology. He is very passionate about innovation and latest technology like APIs, IOT (Internet Of Things), Artificial Intelligence (AI) ecosystem and Cybersecurity. He present his idea in different platforms and help customer to their digital transformation journey.