Git Product home page Git Product logo

anytopdf's Introduction

在linux环境下 从doc/docx, ppt/pptx, xls/xlsx转为pdf

unoconv (依赖于libreoffice)

0. 确认libreoffice相应组件已经安装完成

1. 安装unoconv

sudo apt-get install unoconv

2. 转换

unoconv -f pdf sample.doc

其中 -f 是-format,后面给定想要转换的格式(例如:pdf),sample.doc为要转换的文件名,最终会得到sample.pdf 这个文件。

还可以添加 参数:-o exemple.pdf代表输出文件名称

参数:-e PageRange=1-2 代表需要转换的页数

3. 后台服务调用unoconv

3.1 首先启动unoconv server(启动libreoffice 的 soffice)

  unoconv --listener

或者编写脚本文档:

# create the start script for unoconv - start in listener mode:
touch /etc/init.d/unoconvd
chmod 755 /etc/init.d/unoconvd

# File /etc/init.d/unoconvd: # script includes the tar file

#!/bin/sh
### BEGIN INIT INFO
# Provides: unoconvd
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 5
# Default-Stop:
# Description: unoconvd - Converting documents to PDF by unoconv
### END INIT INFO
case "$1" in
    start)
        /usr/bin/unoconv --listener &
        ;;
    stop)
        killall soffice.bin
        ;;
    restart)
        killall soffice.bin
        sleep 1
        /usr/bin/unoconv --listener &
        ;;
esac

3.2

连接到unoconv并完成转换:

    unoconv --connection 'socket,host=127.0.0.1,port=2002,tcpNoDelay=1;urp;StarOffice.ComponentContext' -f pdf 3.doc

其中3.doc为想要转化的文件,其中host地址以及port号都可以在开启服务时修改,如不修改则默认为127.0.0.1的本地ip以及2002的端口号

anytopdf's People

Contributors

shuleee avatar

Watchers

James Cloos 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.