Kolorwanie:
Status:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
const express = require("express");
const upload = require("express-fileupload");
const PDF2Pic = require("pdf2pic");
const pdfparse = require("pdf-parse");
const fs = require("fs");



const app = express();

app.set("view engine", 'hbs')
// app.set("view engine", 'hbs')
//gdy uzytkownik wchodzi na stronę


app.use(upload())

app.get("/", (req, res) => {
    res.sendFile(__dirname + '/index.html')
});

app.post("/", (req, res) => {
    if (req.files) {
        console.log(req.files)
        var file = req.files.file;
        var filename = file.name;
        console.log(filename)

        /////////////////

        //////////////
        file.mv('./uploads/' + filename, function (err) {
            if (err) {
                res.send(err);
            }
            else {
                //dodanie daty do nazwy (aby się nic nie zduplikowało)
                var date = new Date();
                var dateFull = new Date().toLocaleDateString();
                var filenameWitoutExtension = filename.match(/[^.]*/i)[0]

                // właściwości do zamiany pdf na obrazek
                const pdf2pic = new PDF2Pic({
                    density: 100,           // output pixels per inch
                    savename: filenameWitoutExtension + "_" + date.getHours() + date.getMinutes() + date.getMilliseconds(),   // output file name
                    savedir: "./images",    // output file location
                    format: "png",          // output file format
                    size: "600x600"         // output size in pixels
                });
                pdf2pic.convertBulk("./uploads/" + filename, -1).then((resolve) => {
                    console.log("image converter successfully!");
                    return resolve;
                }).catch(err => console.log(err))

                ///////////////
                // sprawdzenie ile stron ma pdf
                const pdffile = fs.readFileSync("./uploads/" + filename);
                pdfparse(pdffile).then(function (data) {
                    // var pagesNumber = data.numpages;
                    console.log("Liczba stron: " + data.numpages);

                    const sample = () => {
                        for (let i = 0; i < data.numpages; i++) {
                            return i
                        }
                    }
                    res.render("index2", {
                        pageNumber: sample()
                    })


                })

            }
        })
    }
})

app.listen(5000);

Copyrights 2014-2020 © Wklejaj.pl Wszelkie prawa zastrzeżone.