Java : Convert from doc to pdf and ppt to pdf failing -
for our java project looking converting office files pdf, , subsequently images. currently, have success pptx
, docx
, xls
, xlsx
, pdf
image. if requires working code above mentioned, lemme know.
unfortunately, doc
pdf
, ppt
pdf
not working. have tried multiple solutions, none of them seem work. latest have tried jodconvertor, failed. jodconvertor library unable connect libreoffice, running @ given port.
can give me reliable way convert doc
&& ppt
pdf
, free of cost?
code :
private string createdoctopdfandthentoimage(string path) { try { file inputfile = new file(path); file outputfile = file.createtempfile("/home/akshay/jodtest", ".pdf"); openofficeconnection connection = new socketopenofficeconnection("127.0.0.1", 8100); connection.connect(); documentconverter converter = new openofficedocumentconverter(connection); converter.convert(inputfile, outputfile); connection.disconnect(); } catch (exception e) { e.printstacktrace(); } return ""; }
error log :
java.net.connectexception: connection failed: socket,host=127.0.0.1,port=8100,tcpnodelay=1: java.net.connectexception: connection refused @ com.artofsolving.jodconverter.openoffice.connection.abstractopenofficeconnection.connect(abstractopenofficeconnection.java:79) @ com.journaldev.spring.service.groupattachmentsserviceimpl.createdoctopdfandthentoimage(groupattachmentsserviceimpl.java:406) @ com.journaldev.spring.service.groupattachmentsserviceimpl.addattachment(groupattachmentsserviceimpl.java:338) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:498)
a headless instance started command :
/usr/bin/libreoffice --headless --accept=socket,host=localhost,port=8100;
if there no way fix this, other conversion mechanism work. kindly let me know. thank you.
i working on similar. use unoconv, requires libreoffice. works reliably on ppt/pptx. works on doc/docx, stuck , needed intervention.
here script loops through folder process new ppt/pptx files.it used in production. can add doc/docx well. have java application listening new file creation event on folder can handle converted pdf file after conversion done.
all these status flag files human intervention , status check other scripts. need add code old file clean up.
by way, interested in way of converting files pdf images. maybe can give me hints find better solution project. thanks.
#!/bin/bash #endless conversion echo "convert files pdf..." while [ 1 ] file in `ls -tr | grep '.*\.\(ppt\|pptx\)$'` if [ -e $file.failed ] || [ -e $file.succeeded ] # converted : else echo $file > $file.started echo $file > convert.busy # create busy converting flag file output=`./unoconv -f pdf $file` result=$? echo $result if [ $result -ne 0 ] echo "conversion pdf failed" echo $file > $file.failed else echo "conversion pdf succeeded" echo $file > $file.succeeded fi rm convert.busy # remove busy converting flag file fi done sleep 0.2 done
Comments
Post a Comment