zoukankan      html  css  js  c++  java
  • 在线预览office文件:libreoffice基本使用

    使用的核心是这段命令:
    soffice --headless --convert-to pdf --outdir ' + 输出路径 + ' ' + 源文件路径

    在node中的使用的话,需要使用子进程来运行命令行,如下所示,这里是封装成了promise的形式:

    const process = require('child_process')const outputPath = 'upload/pdf/'
    
    // office translate
    module.exports = function(enterPath) {
        return new Promise((resolve, reject) => {
            process.exec('soffice --headless --convert-to pdf --outdir ' + outputPath + ' ' + enterPath, (err, stdout, stderr) => {
                if (err || stderr) return reject(err || stderr)
                resolve(stdout)
            })
        })
    }

    也可以像这样写:

    const util = require('util')
    const process = require('child_process')
    var exec = util.promisify(process.exec)
    
    // office translate
    async function officeToPdf(enterPath, outputPath) {
        const { stdout, stderr } = await exec(
            'soffice --headless --convert-to pdf --outdir ' + outputPath + ' ' + enterPath
        )
        console.log('stdout:', stdout)
        console.log('stderr:', stderr)
    }

    在node中使用案例:https://github.com/yejunm3/office_transform

    libreoffice下载地址:https://www.libreoffice.org/download/download/

  • 相关阅读:
    嵌入式工程师为何不用学习C++语言?
    汽车电子基础知识
    为什么寄存器比存储器快?
    数字信号和模拟信号
    JLink和JTag的区别
    C++中static关键字作用总结
    所谓高情商,就是会说话
    汽车电子缩略语及术语
    卷积
    算法整理
  • 原文地址:https://www.cnblogs.com/yejunm3/p/14316592.html
Copyright © 2011-2022 走看看