GithubHelp home page GithubHelp logo

somax / doc-convertor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from liubin/doc-convertor

0.0 1.0 0.0 184 KB

with libre office installed on CentOS

License: MIT License

Dockerfile 12.92% JavaScript 87.08%

doc-convertor's Introduction

doc-convertor

English Version Document.

本镜像预安装了CentOS 7 和LibreOffice,以及Node.js,能将Office文档转换为PDF文件以及png图片,并上传到七牛云存储。

使用方法

Build Image

sudo docker build -t doc-convertor .

将Offcie文档转换为Pdf文件

由于镜像内已经安装了LibreOffice,可以直接使用libreoffice命令进行文档转换。

sudo docker run  -v /YOUR_HOST_PATH/:/tmp doc-convertor libreoffice  \
--headless --convert-to pdf /tmp/SOME_OFFICE_FILE --outdir /tmp

其中YOUR_HOST_PATH是宿主机的文件夹路径,而SOME_OFFICE_FILE则是要转换的文件名(已经被映射到了容器的/tmp下)。

将Pdf文件转换为图像

$ sudo docker run -v /YOUR_HOST_PATH:/tmp doc-convertor convert /tmp/SOME.PDF /tmp/test-%02d.png

该命令的详细说明请参看这里的文档

一站式解决方案

$ sudo docker run -v /YOUR_HOST_PATH:/THIS_PATH_WILL_BE_QINIU_KEY \
  -e QINIU_BUCKET_NAME=xxx \
  -e QINIU_SECRET_KEY=yyy \
  -e QINIU_ACCESS_KEY=zzz \
  -e DOC_PATH=/THIS_PATH_WILL_BE_QINIU_KEY/SOMETHING-LIKE-UUID-TO-BE-A-KEY \
  doc-convertor node uploader.js

该方法会将宿主机/YOUR_HOST_PATH下的文档转换为Pdf及图像后,并上传到七牛云存储。如果QINIU_开头的环境变量没有设置,则会略过上传步骤。上传到七牛时的key(即对象标识符)为容器内该文件的full path/THIS_PATH_WILL_BE_QINIU_KEY

输出类似下面这样:

page_count: 8
/app2/temp/d-000.png: FvoI-yedq3BGxmCJOh1ne0P5bVLH
/app2/temp/d-006.png: Fu_0KFOH1eTy3kYsrvz6RkaLgEiA
/app2/temp/d-007.png: FpgptqUl72NiEwVttCE7_BcS0SK7
/app2/temp/d-001.png: FoCh4_FFGjy2PqXkikne171kjr_l
/app2/temp/d-005.png: FvrqA_Elrd5oXqpSkVjHpljrRZBz
/app2/temp/d-003.png: FjsUZFLb3sGzyksfqoKLx6qNGb-g
/app2/temp/d.docx: FnOCwMDsU8dDjv0WyCV0v7kchtPO
/app2/temp/d-004.png: FkFLGKaZXdjV3UFU4V43kNc2e8OK
/app2/temp/d-002.png: FkWirLGmINxYX0_5XuHTErss_Clu
/app2/temp/d.pdf: FrROdUt5aXhE9rXTnMzoCHg8xqTe

文件名映射规则为:

  • 假设原文件名d.docx;
  • 则pdf文件名为d.pdf,扩展名会替换为pdf;
  • png文件默认采d-%03d.png这种形式,即加上了000,001这样的后缀;
  • page_count是总页数,这是通过计算png文件数量实现的;
  • 如果文件被上传到了七牛,则会输出key: hash

doc-convertor's People

Contributors

liubin avatar

Watchers

马晓军 avatar

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.