server.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. const fs = require('fs')
  2. const express = require('express')
  3. const multer = require('multer')
  4. const childProcess = require('child_process')
  5. const PDF2HTMLEX_PATH = 'C:/Users/alan.colon/Downloads/pdf2htmlEX-win32-0.14.6-upx-with-poppler-data/pdf2htmlEX.exe'
  6. const upload = multer({
  7. dest: 'temp/'
  8. })
  9. const app = express()
  10. app.use(express.static('./public'))
  11. app.post('/edit', upload.single('document'), (req, res) => {
  12. childProcess.exec(`"${PDF2HTMLEX_PATH}" --no-drm 1 "${req.file.path}" "${req.file.path}.html"`, (err, stdout, stderr) => {
  13. if (err) {
  14. res.status(500).send(`<pre>${err}\n\n${stdout}\n\n${stderr}</pre>`)
  15. } else {
  16. fs.readFile(`${req.file.path}.html`, 'utf8', (err, data) => {
  17. if (err) {
  18. res.status(500).send(`<pre>${err}\n\n${stdout}\n\n${stderr}</pre>`)
  19. } else {
  20. res.status(200).send(data.replace('</head>', `
  21. <script src="edit.js" type="text/javascript"></script>
  22. <link rel="stylesheet" href="edit.css" />
  23. </head>`))
  24. }
  25. })
  26. }
  27. })
  28. })
  29. app.listen('3003')
  30. console.log('http://localhost:3003')