简体   繁体   English

如何预览Java应用程序中的任何文件?

[英]How to preview any files inside a Java application?

I'm using a JTree to browse the content of a folder and I want that when a user click on a file, the software shows a preview of it (a screenshot of its first page). 我正在使用JTree浏览文件夹的内容,我希望当用户单击文件时,该软件可以显示该文件的预览(其第一页的屏幕截图)。

The files are mostly Office documents and PDF. 这些文件主要是Office文档和PDF。

I manage to do it for PDF file using a module downloaded from Sun, but I'd like to know if there is a way to do it using any software (JARs preferably) or even the built-in Windows API. 我设法使用从Sun下载的模块来处理PDF文件,但是我想知道是否可以使用任何软件(最好是JAR)甚至内置Windows API来处理。

I was thinking of converting the file to PDF then do a preview of this PDF but this isn't optimal. 我当时想将文件转换为PDF,然后预览此PDF,但这并不是最佳选择。

Any ideas ? 有任何想法吗 ?

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 : Alfresco也有同样的问题,并使用以下方法解决了:

  • 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 在服务器模式(套接字)下运行的开放式办公室,所有办公文件都由露天发送到开放式办公室,以便将它们转换为PDF
  • Those PDF are converted to .swf viewer thanks to SWFTOOLS 借助SWFTOOLS,这些PDF被转换为.swf查看器
  • This .swf is integrated in the HTML 该.swf集成在HTML中
  • For images, it uses ImageMagick to create small version of the file I suppose 对于图像,它使用ImageMagick创建我认为的文件的小版本

Personnaly, I will try to implement it this way : 从个性上讲,我将尝试通过以下方式实现它:

  • Converting office documents to PDF thanks to open office in socket mode 通过以套接字模式打开办公室,可将Office文档转换为PDF
  • Transform the first page of the PDF into a PNG thanks to JPedal library (the LGPL version) 借助JPedal库(LGPL版本),将PDF的首页转换为PNG
  • Diplay that PNG to the end user 将PNG播放给最终用户
  • For images I would perhaps use ImageMagick too ... but for now, I'm using Seam Image.scaleToFit API 对于图像,我也许也会使用ImageMagick ...但是现在,我正在使用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. 从Anthony的解决方案开始,我正在以套接字模式使用Libre Office将Office文档直接转换为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 在套接字模式下启动Libre Office的小参考: 单击我

我很久以前问过这个: 解决方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM