Save the file when PPT is transferred to PDF, but the problem that opening the PDF file is blank has not been solved.

// ppt 
if (
   req.files[0].mimetype === "application/vnd.openxmlformats-officedocument.presentationml.presentation" ||
   req.files[0].mimetype === "application/vnd.ms-powerpoint"
) {
     var form = formstream();
     form.buffer("file", des_file, req.files[0].originalname.substring(0, req.files[0].originalname.lastIndexOf(".")));
     var options = {
         method: "POST",
         host: "127.0.0.1",
         port: "5000",
         path: "/unoconv/pdf/",
         headers: form.headers()
     };
     const promise = new Promise(function (resolve, reject) {
           var reqs = http.request(options, function (res) {
               var _data = "";
               res.on("data", function (data) {
                   _data += data;
               }).on("end", function () {
                   resolve(_data);
               }).on("error", function (err) {
                   reject(err);
               });
           });
           form.pipe(reqs);
     })
     promise.then(function (buffer) {
         console.log(buffer, "success")    // buffet
         fs.writeFile("./test.pdf", buffer, function (err) {
            if (err) {        
               console.log(err);
            }
         })
         // pdf
     }, function (err) {
         console.log(err, "failure")
     })
     }

when you finish the conversion, save the pdf file again, but opening the file is blank. What"s the problem?

Mar.11,2021

if I guess correctly. What is returned in the pipe should be a Buffer object, or a binary data stream or something. There should be a problem if you take String directly. Try calling toString

before splicing.

or think of data as Buffer object, store all Buffer in an array, and then put all concat together at the end, and then write to the file.


what library are you using? Take a closer look at the document to see what listens for events at the end of the transformation, or what should be written. I can't tell from your code.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e419bd-43426.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e419bd-43426.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?