NickNaso / ghostscript4js

Ghostscript4JS binds the Ghostscript C API to the Node.JS world.
http://www.nacios.it
Apache License 2.0
68 stars 19 forks source link

where gs output converted file? #45

Closed crapthings closed 5 years ago

crapthings commented 5 years ago

i can't find it anywhere?

const cmd = '-sDEVICE=pngalpha -o /usr/pdf2image/convert/file-%03d.png -r144 ' + filepath

docker-compose.yml

- '/data/db/static/pdf2image/convert:/usr/pdf2image/convert'

but it looks nothing there.

image

the output looks fine

NickNaso commented 5 years ago

Hi @crapthings, your file should be in the folder /usr/pdf2image/convert/. Could you send your complete docker-compose.yml and Dockerfile, maybe I could help you in better way.

crapthings commented 5 years ago
const gs = require('ghostscript4js')
const multer  = require('multer')
const upload = multer({ dest: 'private/' })

module.exports = function ({ router }) {

  return router

    .post('/pdf2image', upload.array('files'), async function (req, res, next) {
      console.log(req.files)
      const filepath = req.files[0].path
      const cmd = '-sDEVICE=pngalpha -o /usr/pdf2image/convert/file-%03d.png -r144 ' + filepath
      gs.execute(cmd)
.then(() => {
  console.log("All is ok")
})
.catch((err) => {
  console.log(err)
 console.log("Ooops... something wrong happened")
})
      return res.sendStatus(200)
    })

}
# Official Node.js 8.x lts image based on Debian stretch (has ghostscript 9.20 in its archive)
FROM node:carbon-stretch

RUN apt-get update
RUN apt-get --yes install ghostscript
RUN apt-get --yes install libgs-dev

WORKDIR /usr/pdf2image

# Only copy the package.json for now
# If it didn't change this will improve build time because node_modules can be cached
# https://christianfei.com/posts/Cache-speed-up-docker-node-modules/
COPY package.json .

ENV GS4JS_HOME=/usr/lib/x86_64-linux-gnu
RUN npm install --registry=https://registry.npm.taobao.org --verbose

# Copy the rest of the source code over
COPY . .

CMD ["npm", "start"]
version: '3'
services:
  pdf2image:
    image: 'lvfang:pdf2image'
    restart: 'always'
    ports:
      - '4002:3000'
    volumes:
    - '/data/db/static/lvfang-pdf2image/private:/usr/pdf2image/private'
    - '/data/db/static/lvfang-pdf2image/convert:/usr/pdf2image/convert'

there're no errors, and execute tells me all is okay

i run into docker container to exec same cmd with

gs -sDEVICE=pngalpha -o /usr/pdf2image/convert/file-%03d.png -r144 filename

the files are there.

crapthings commented 5 years ago

@NickNaso

after this issue #44 i can now run script on osx, but its still same like inside docker

can't find output file, the convert progress seems super fast, it knows how many page are there.

but run same cmd with terminal with gs is okay.

crapthings commented 5 years ago

ah okay i think i've found the problem

work

-sDEVICE=pngalpha -o ./convert/test-%03d.png -sDEVICE=pngalpha -r144 ' + 'test.pdf'

no working with js, but works with terminal

-sDEVICE=pngalpha -o ./convert/test-%03d.png -r144 ' + 'test.pdf'
kamal0808 commented 4 years ago

@crapthings can you explain why putting in the -sDEVICE twice works but doesn't work when put once?