-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e4ad203
Showing
4 changed files
with
1,841 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.