How to preview any files inside a Java application?

与世无争的帅哥 提交于 2019-12-03 08:04:10

I've got the similar problem and the best I found after couple of days of googling is following.

Alfresco has the same problem and resolved it with :

  • An open office which runs in server mode (socket) and all the office documents are sent by alfresco to open office in order to convert them in PDF
  • Those PDF are converted to .swf viewer thanks to SWFTOOLS
  • This .swf is integrated in the HTML
  • For images, it uses ImageMagick to create small version of the file I suppose

Personnaly, I will try to implement it this way :

  • Converting office documents to PDF thanks to open office in socket mode
  • Transform the first page of the PDF into a PNG thanks to JPedal library (the LGPL version)
  • Diplay that PNG to the end user
  • For images I would perhaps use ImageMagick too ... but for now, I'm using Seam Image.scaleToFit API

I had the same problem too and stumbled over this thread. Starting with the solution from Anthony I am using Libre Office in socket mode to convert office documents directly to a PNG. Unfortunately this isn't posible from PDF's. Here is a good overview which ways are possible.

unoconv --connection 'socket,host=127.0.0.1,port=2220,tcpNoDelay=1;urp;StarOffice.ComponentContext' -f png -e PageRange=1 your_file_name.extension

Little reference to start Libre Office in socket mode: click me

Martijn Courteaux

I asked this a long time ago: solution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!