问题描述
我正在使用 JTree 浏览文件夹的内容,我希望当用户单击文件时,软件会显示它的预览(其第一页的屏幕截图).
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).
文件主要是Office文档和PDF.
The files are mostly Office documents and PDF.
我设法使用从 Sun 下载的模块为 PDF 文件执行此操作,但我想知道是否有办法使用任何软件(最好是 JAR)甚至内置的 Windows API 执行此操作.
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.
我想将文件转换为 PDF,然后预览此 PDF,但这不是最佳选择.
I was thinking of converting the file to PDF then do a preview of this PDF but this isn't optimal.
有什么想法吗?
推荐答案
我遇到了类似的问题,经过几天的谷歌搜索后我发现最好的方法如下.
I've got the similar problem and the best I found after couple of days of googling is following.
Alfresco 有同样的问题,并通过以下方式解决:
Alfresco has the same problem and resolved it with :
- 以服务器模式(socket)运行的开放式办公室,所有的办公室文件都由露天发送到开放式办公室,以便将它们转换为PDF
- 由于 SWFTOOLS ,这些 PDF 已转换为 .swf 查看器
- 此 .swf 已集成在 HTML 中
- 对于图像,它使用 ImageMagick 来创建我认为的小版本文件
- 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 :
- 借助套接字模式下的开放式办公,将办公文档转换为 PDF
- 借助 JPedal 库(LGPL 版本)将 PDF 的第一页转换为 PNG)
- 将该 PNG 显示给最终用户
- 对于图像,我也可能会使用 ImageMagick ......但现在,我正在使用 Seam Image.scaleToFit API
- 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
这篇关于如何预览 Java 应用程序中的任何文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!