Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
aayush-kapoor authored Dec 11, 2021
0 parents commit e4ad203
Show file tree
Hide file tree
Showing 4 changed files with 1,841 additions and 0 deletions.
56 changes: 56 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const express = require('express');
const app = express(); //initialising express
const fs = require('fs'); //read and create files
const multer = require('multer'); //upload files to server
const { ppid } = require('process');
const {createWorker} = require('tesseract.js')
const worker = createWorker(); //to analyse the images

const storage = multer.diskStorage({
destination: (req,file,cb) => {
cb(null, "./uploads"); // called when image is to be stored
},
filename: (req,file,cb) => {
cb(null, file.originalname);
}
}); // to store file name, where we want it
const upload = multer({ storage : storage}).single('Monke');

app.set("view engine", "ejs");


app.get('/', (req,res) => {
res.render('index');
});


/*app.get('/upload', (req,res) => {
console.log('heyy')
})*/

app.post('/upload', (req,res) => {
upload(req,res, err => {
fs.readFile(`./uploads/${req.file.originalname}`, (err, data)=>{
if(err) return console.log('This is youe error: ', err);

worker
.recognize(data, "eng", {tessjs_create_pdf: '1'})
.progress(progress =>{
console.log(progress);
})
.then(result =>{
res.redirect('/download');
})
.finally( () => worker.terminate());
});
})
});


app.get('/dowmload', (req,res) => {
const file = `${__dirname}/ocr-result.pdf`;
res.download(file);
})

const PORT = 5000 || process.env.PORT;
app.listen(PORT, () => console.log(`heyy im running on port ${PORT}`));
16 changes: 16 additions & 0 deletions index.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name = "viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie-edge" />
<title>Img to PDF</title>
</head>
<body>
<h1>Image to PDF</h1>
<form action="/upload" method="POST" enctype="multipart/form-data">
<input type="file" name="Monke" id="" />
<button type="submit">Convert to PDF</button>
</form>
</body>
</html>
Loading

0 comments on commit e4ad203

Please sign in to comment.