鍍金池/ 問答/數(shù)據(jù)庫  HTML  Office/ gridfs-stream讀取的word流怎么轉(zhuǎn)換為pdf

gridfs-stream讀取的word流怎么轉(zhuǎn)換為pdf

問題描述

mongodb存取的word文件,需要在瀏覽器中顯示,但瀏覽器不好顯示office文件,所以目前的解決的方案是,在后臺通過gridfs-stream讀取word,然后轉(zhuǎn)換為pdf

問題出現(xiàn)的環(huán)境背景及自己嘗試過哪些方法

node.js

相關(guān)代碼

const downloadFile = function (isPicture, req, res, next) {
    req.checkParams('id', "路徑參數(shù)id格式有誤").isMongoId();
    let id = req.params.id;
    let errors = req.validationErrors();
    if (errors) {
        return res.error(errors[0].msg);
    }
    Services.Gridfs.getOne(id).then(function (file) {
        if (file) {
            res.header("Content-Type", file.contentType);
            if (!isPicture) {
                setContentDispositionHeader(req, res, file.filename);
            }
            let gfs = utils.Gridfs.getGridfs();
            var readstream = gfs.createReadStream({
                _id: id
            });
            readstream.on('error', function (error) {
                next(error);
            });
            readstream.pipe(res);
        } else {
            return res.error("無此文件", 404);
        }
    }).catch(err=>next(err));
};

你期待的結(jié)果是什么?實際看到的錯誤信息又是什么?

回答
編輯回答
半心人

沒有哪個數(shù)據(jù)庫會幫你把word轉(zhuǎn)換成PDF。讀出來自己轉(zhuǎn),第三方工具很多,比如:Office to PDF
是不是適合你使用請自己驗證。

2017年10月8日 23:39