How to convert word streams read by gridfs-stream to pdf

problem description

word files accessed by mongodb need to be displayed in the browser, but the browser is not good at displaying office files, so the current solution is to read word, through gridfs-stream in the background and then convert it to pdf

.

the environmental background of the problems and what methods you have tried

node.js

related codes

const downloadFile = function (isPicture, req, res, next) {
    req.checkParams("id", "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));
};

what result do you expect? What is the error message actually seen?

Mar.28,2021

No database will help you convert word to PDF. Read it on your own, there are many third-party tools, such as: Office to PDF
is suitable for you to use, please verify for yourself.

Menu