GithubHelp home page GithubHelp logo

office2pdf's Introduction

Office2PDF

本项目的功能是将office文件,主要是doc,docx,xls,xlsx,ppt,pptx,txt等文件轻松转成pdf文件,进而可以再前端做文件预览;

首先了解一下目前主流的文件预览方案:

基于openoffice + swftools + flexpaper

请访问原文博客

主要原理

  • 通过第三方工具openoffice,将word、excel、ppt、txt等文件转换为pdf文件
  • 通过swfTools将pdf文件转换成swf格式的文件
  • 通过FlexPaper文档组件在页面上进行展示

缺点:服务器需要安装openoffice,wsftools和flexpaper等插件,比较负重;前端需要安装flash插件

优点:实现的wsf预览方式对文件的失真较少,代码实现起来也不是特别复杂

这也是目前比较主流的方式,例如百度云盘大概就是按照这种方式

基于IText + POI + Jsoup

请访问原文博客

主要原理:

  • 使用 poi 将word转换成 html
  • 使用IText 将html转换成pdf(由于html中所有标签都必须要闭合,才能使用IText,所以这里用jsoup对html进行转换)

缺点: 会有失真问题,另外涉及到中文编码问题

基于Openoffice + jquery-media

这种也是我以上项目中所采用的方案:

主要原理:

  • 通过第三方软件openoffice,将word、excel、ppt、txt等文件转换为pdf文件
  • 前端使用media展示pdf文件

jQuery-Media,不仅可以无插件展示pdf文件,还可以html, 及其他媒体文件等,功能比较强大,社区提供了很多的demo,可以查看一下。

本项目代码将office转成pdf后,就可以通过jQuery-media展示pdf,具体做法就是:

<a class="media" href="123.pdf"></a>

js脚本执行如下:

$("a.media").media({width:800, height:600});

优点: 前后台代码都比较简单

缺点:依然需要安装OpenOffice软件

附件:

office2pdf's People

Contributors

vence avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

office2pdf's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.