I have a requirement to convert any input files (txt,doc,docx,jpg,html,xls etc) to PDF.
I am using the below code to convert the input file to PDF , it is working for txt file but not doc, xls etc as I am getting some special characters in the output file. Can anyone help me with code to accomplish the same.. Your help will be appreciated.. Thanks
private void createPdf(String inputFile, String outputFile, boolean isPictureFile)
Document pdfDocument = new Document();
String pdfFilePath = outputFile;
FileOutputStream fileOutputStream = new FileOutputStream(pdfFilePath);
PdfWriter writer = null;
writer = PdfWriter.getInstance(pdfDocument, fileOutputStream);
* Proceed if the file given is a picture file
* Proceed if the file given is (.txt,.html,.doc etc)
File file = new File(inputFile);
catch (Exception exception)
System.out.println("Document Exception!" + exception);
There is no easy way to convert structured document formats like HTML, XLS, DOCX etc. to PDF. A library like JODConverter (which runs OpenOffice in server mode, so you need that as well) can probably accomplish most of the conversions.
Madhu Sudhan B T
Joined: Nov 18, 2009
Thanks Ulf Dittmer for the response.. can you please share some relevant sample java code/examples showing the usage of JODConverter api's? Thanks in advance
Joined: Mar 22, 2005
I seem to recall that its web site and attendant documentation had sample code.