logicaldoc
文档:http://docs.logicaldoc.com/
下载: http://sourceforge.net/projects/logicaldoc/
logicaldoc 里面转换SWF用到了三个命令:
command.convert=convert
command.gs=gs
command.pdf2swf=pdf2swf
http://forums.logicaldoc.com/viewtopic.php?f=6&t=416&p=1050&hilit=command.convert#p1050
Speacking about the latest release 6.2.3, you need some external command.
GhostScript
ImageMagik
SWFTools
package com.logicaldoc.web; import com.logicaldoc.core.document.Document; import com.logicaldoc.core.document.dao.DocumentDAO; import com.logicaldoc.core.document.thumbnail.ThumbnailManager; import com.logicaldoc.core.store.Storer; import com.logicaldoc.util.Context; import com.logicaldoc.util.MimeType; import com.logicaldoc.util.config.ContextProperties; import com.logicaldoc.web.util.SessionUtil; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class DocumentPreview extends HttpServlet { protected static final String SUFFIX = "suffix"; public static final String DOC_ID = "docId"; private static final String FILE_VERSION = "fileVersion"; private static final long serialVersionUID = -6956612970433309888L; protected static Log log = LogFactory.getLog(DocumentPreview.class); protected static String PDF2SWF = "command.pdf2swf"; protected static String IMG2PDF = "command.convert"; protected String SWF_DIRECT_CONVERSION_EXTS = "gif, png, pdf, jpeg, jpg, tiff, tif"; public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String id = request.getParameter("docId"); String fileVersion = request.getParameter("fileVersion"); String suffix = request.getParameter("suffix"); InputStream stream = null; try { Storer storer = (Storer)Context.getInstance().getBean(Storer.class); long docId = Long.parseLong(id); if (StringUtils.isEmpty(suffix)) suffix = "thumb.jpg"; DocumentDAO docDao = (DocumentDAO)Context.getInstance().getBean(DocumentDAO.class); Document doc = (Document)docDao.findById(docId); if (StringUtils.isEmpty(fileVersion)) fileVersion = doc.getFileVersion(); SessionUtil.validateSession(request.getParameter("sid")); String resource = storer.getResourceName(docId, fileVersion, suffix); if (!(storer.exists(docId, resource))) { log.debug("Need for preview creation"); createPreviewResource(doc, fileVersion, resource); } stream = storer.getStream(docId, resource); if (stream == null) { log.debug("thumbnail not available"); forwardPreviewNotAvailable(request, response); return; } downloadDocument(request, response, stream, storer.getResourceName(doc, fileVersion, suffix)); } catch (Throwable t) { log.error(t.getMessage(), t); new IOException(t.getMessage()); } finally { if (stream != null) stream.close(); } } protected void createPreviewResource(Document doc, String fileVersion, String resource) { Storer storer = (Storer)Context.getInstance().getBean(Storer.class); String thumbResource = storer.getResourceName(doc, fileVersion, "thumb.jpg"); if (!(storer.exists(doc.getId(), thumbResource))) { ThumbnailManager thumbManager = (ThumbnailManager)Context.getInstance().getBean(ThumbnailManager.class); try { thumbManager.createTumbnail(doc, fileVersion); log.debug("Created thumbnail " + resource); } catch (Throwable t) { log.error(t.getMessage(), t); } } if (resource.endsWith(".jpg")) { return; } if (!(storer.exists(doc.getId(), resource))) { InputStream is = null; File tmp = null; try { tmp = File.createTempFile("preview", ""); String docExtension = FilenameUtils.getExtension(doc.getFileName()); if (this.SWF_DIRECT_CONVERSION_EXTS.contains(docExtension)) { is = storer.getStream(doc.getId(), storer.getResourceName(doc, fileVersion, null)); document2swf(tmp, docExtension, is); } else { is = storer.getStream(doc.getId(), thumbResource); document2swf(tmp, "jpg", is); } storer.store(tmp, doc.getId(), resource); log.debug("Created preview " + resource); } catch (Throwable e) { log.error(e.getMessage(), e); } finally { if (tmp != null) FileUtils.deleteQuietly(tmp); if (is != null) try { is.close(); } catch (IOException e) { } } } } protected void forwardPreviewNotAvailable(HttpServletRequest request, HttpServletResponse response) { try { RequestDispatcher rd = request.getRequestDispatcher("/skin/images/preview_na.gif"); rd.forward(request, response); } catch (Exception e) { e.printStackTrace(); } } public static void downloadDocument(HttpServletRequest request, HttpServletResponse response, InputStream is, String filename) throws FileNotFoundException, IOException { String mimetype = MimeType.getByFilename(filename); response.setContentType(mimetype); OutputStream os = response.getOutputStream(); int letter = 0; try { while ((letter = is.read()) != -1) os.write(letter); } finally { os.flush(); os.close(); is.close(); } } protected void document2swf(File swfCache, String extension, InputStream docInput) throws IOException { File tmpPdf = null; try { tmpPdf = File.createTempFile("preview", ".pdf"); if ("pdf".equals(extension.toLowerCase())) { FileOutputStream fos = null; try { fos = new FileOutputStream(tmpPdf); IOUtils.copy(docInput, fos); fos.flush(); } catch (Throwable e) { } finally { IOUtils.closeQuietly(fos); } } else { img2pdf(docInput, extension, tmpPdf); } pdf2swf(tmpPdf, swfCache); } finally { if (tmpPdf != null) FileUtils.deleteQuietly(tmpPdf); } } protected void img2pdf(InputStream is, String extension, File output) throws IOException { File tmp = File.createTempFile("preview", extension); String inputFile = tmp.getPath() + "[0]"; FileOutputStream fos = null; try { fos = new FileOutputStream(tmp); IOUtils.copy(is, fos); fos.flush(); fos.close(); ContextProperties conf = (ContextProperties)Context.getInstance().getBean(ContextProperties.class); ProcessBuilder pb = new ProcessBuilder(new String[] { conf.getProperty(IMG2PDF), inputFile, " -compress None -quality 100 ", output.getPath() }); Process process = pb.start(); Thread wrapper = new Thread(process) { public void run() { try { this.val$process.waitFor(); } catch (InterruptedException e) { } } }; wrapper.start(); for (int i = 0; i < 10; ++i) if (wrapper.isAlive()) try { Thread.sleep(1000L); } catch (InterruptedException e) { } wrapper.interrupt(); process.destroy(); } catch (Throwable e) { } finally { IOUtils.closeQuietly(fos); tmp.delete(); } } protected void pdf2swf(File input, File output) throws IOException { ContextProperties conf = (ContextProperties)Context.getInstance().getBean(ContextProperties.class); String[] cmd = composeCmd(conf.getProperty(PDF2SWF), input, output); BufferedReader stdout = null; Process process = null; try { ProcessBuilder pb = new ProcessBuilder(cmd); process = pb.start(); stdout = new BufferedReader(new InputStreamReader(process.getInputStream())); while (stdout.readLine() != null); process.waitFor(); } catch (Throwable e) { output.delete(); log.error("Error in PDF to SWF conversion", e); } finally { if (process != null) process.destroy(); IOUtils.closeQuietly(stdout); } } protected String[] composeCmd(String command, File input, File output) { String[] standardCmd = { command, "-f", "-T 9", "-t", "-G", "-s storeallcharacters", input.getPath(), "-o", output.getPath() }; String[] imgCmd = { command, "-T 9 -q 30", input.getPath(), "-o", output.getPath() }; if (command.endsWith("convert")) return imgCmd; return standardCmd; } }
相关推荐
文档管理系统 是知识管理系统中很重要的组成,DMS管理各种文档,以便在需要时能进行检索、查询、组合和输出。
SAP_DMS-SAP文档管理系统(DMS)配置及操作手册-V1 使用dms的筒靴们可以看看。
智能和开源文档管理系统 LogicalDOC是文档管理和协作系统。该软件具有许多功能,可以为任何组织和个人安全,安全地组织,索引,检索,控制和分发重要的业务文档。 公司使用纸质流程(例如打印,邮寄和手动归档...
Papermerge是一个开源文档管理系统(DMS),主要用于归档和检索数字文档。 您无需在办公桌,办公室或抽屉上堆满纸质文件,而是可以快速对其进行扫描并将其配置为直接上传到Papermerge DMS。 Papermerge-文档管理系统...
我们的文档管理系统用电子程序替代了所有这些方法,从而使您的组织可以显着降低成本。 查看https://www.logicaldoc.com了解更多信息。 为了提供可靠的DMS平台,LogicalDOC的设计基于最佳的Java技术。 主界面是基于...
智能和开源文档管理系统 LogicalDOC是文档管理和协作系统。该软件具有许多功能,可以为任何组织和个人安全,安全地组织,索引,检索,控制和分发重要的业务文档。 公司使用纸质流程(例如打印,邮寄和手动归档...
开源文档管理软件LogicalDOC Community Edition是一个。 如果您正在寻找免费的费用,那么“社区”是您的最佳选择。 LogicalDOC使企业可以控制电子文档的生产,存储,管理和分发,从而产生更大的效力以及重用信息和...
DMS企业版-win64.zip,阿里云提供的数据库管理软件,Windows桌面版安装包,简单易用,推荐下载。
pso变体算法
case study - DMS - 常州市城区排水监控一体化管理系统项目pdf,case study - DMS - 常州市城区排水监控一体化管理系统项目
动态多群粒子群代码-基于J.J.Liang2005年得文章
SAP 文档管理系统(DMS) 配置文档
DMS的文档管理方式就是将电子化的文档和SAP ERP中的对象关联起来...最近项目中要使用DMS,通过搜索找到了《SAP 文档管理系统(DMS) 配置文档》英文版,看起来比较费劲,所以提供了一个对照的中文翻译版本,供大家参考。
dms-webapp:物流配送管理系统
3D-ca3dms-toh.zip,基于上下文感知的三维遮挡mean-shift算法在rgb-d视频中的鲁棒目标跟踪,3D建模使用专门的软件来创建物理对象的数字模型。它是3D计算机图形的一个方面,用于视频游戏,3D打印和VR,以及其他应用程序...
动态多群粒子群优化器的MATLAB源代码还包括次区域和谐搜索
python库。 资源全名:aws_cdk.aws_dms-1.20.0-py3-none-any.whl
资源分类:Python库 所属语言:Python 资源全名:ceafa-dms-core-2.0.7.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
python库。 资源全名:aws-cdk.aws-dms-1.23.0.tar.gz