Created
November 12, 2020 20:43
-
-
Save odevodyssey/ac07f490c43375c7cf0cde1db22f1e4a to your computer and use it in GitHub Desktop.
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
// usage: node pdf-parser-express | |
// the below packages are required to run this server, and can be installed with npm | |
const express = require('express') | |
const bodyParser = require('body-parser') | |
const pdf = require('pdf-parse') | |
const crawler = require('crawler-request') | |
const multer = require('multer') | |
//var upload = multer({ dest: 'uploads/' }) | |
var upload = multer() | |
const app = express() | |
const port = 3000 | |
app.use(bodyParser.json()) | |
app.use(bodyParser.raw()) | |
app.get('/', (req, res) => { | |
res.send('Hello PDF Parsing!') | |
}) | |
app.post('/pdf-base64-parse', function (req, res) { | |
console.log(`Request body: ${JSON.stringify(req.body)}`) | |
let buff = Buffer.from(req.body.base64, 'base64') | |
pdf(buff).then(function(data) { | |
// PDF text | |
console.log(data.text); | |
res.send({ pdfText: data.text }) | |
}) | |
}) | |
app.post('/multipart-parse', upload.single('file'), function (req, res) { | |
console.log(`Request File: ${JSON.stringify(req.file)}`) | |
let buff = req.file.buffer | |
pdf(buff).then(function(data) { | |
// PDF text | |
console.log(data.text); | |
res.send({ pdfText: data.text }) | |
}) | |
}) | |
app.post('/pdf-link-parse', function (req, res) { | |
console.log(`Request body: ${JSON.stringify(req.body)}`) | |
let pdfLink = req.body.link | |
crawler(pdfLink).then(function(response){ | |
// handle response | |
console.log(response.text); | |
res.send({ pdfText: response.text }) | |
}); | |
}) | |
app.listen(port, () => { | |
console.log(`Example app listening at http://localhost:${port}`) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment