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

Empty output with when using pdfwrite #30

Closed letalumil closed 6 years ago

letalumil commented 6 years ago

Hello! Thanks for the great package, it looks promising, but something doesn't work well in my case.

I'm trying to convert a PostScript file to PDF via the following command: -sDEVICE=pdfwrite -o out.pdf -f in.ps. So, nothing fancy, all params are the default.

If I execute it in shell directly this way: gs -sDEVICE=pdfwrite -o out.pdf -f in.ps, then everything works well and the out.pdf is placed next to the in.ps.

But when I try to use the very same command with ghostscript4js, then I get no PDF file and no error. Here is the code I use:

const gs = require('ghostscript4js');
let cmd = '-sDEVICE=pdfwrite -o out.pdf -f in.ps';
try {
    gs.executeSync(cmd);
} catch (err) {
    console.log('Err');
}

And here is the console output:

ghost node index.js
GPL Ghostscript 9.21 (2017-03-16)
Copyright (C) 2017 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
%%BoundingBox: 89 39 523 683
%%HiResBoundingBox: 89.981997 39.095999 522.503984 682.073979
%%BoundingBox: 90 43 523 681
%%HiResBoundingBox: 90.215997 43.415999 522.503984 680.147979

I tried the sample code with the PNG file from the readme and it works well. It seems to be something specific with the pdfwrite. If you have any suggestions I'd much appreciate it! Thanks!

Here is some info about my environment:

OS: macOS 10.12.6 Node: v8.4.0 (I also tried with node v6) Ghostscript: 9.21 Sample PostScript file I used: link (I also tried a bunch of other ps files, but no luck)

GautierT commented 6 years ago

I have the same error. No output file. And no error.

NickNaso commented 6 years ago

Hi @GautierT and @letalumil, thanks for your feedback I will work on that on the weekend and hope to release new version that solve the problem. To test I will use the sample ps file posted by @letalumil.

NickNaso commented 6 years ago

Hi @letalumil and @GautierT , I replicated your problems and for now I found this solution:

const gs = require('ghostscript4js')
let cmd = '-psconv -q -dNOPAUSE -sDEVICE=pdfwrite -o out.pdf -f in.ps'
try {
    gs.executeSync(cmd)
} catch (err) {
    console.log('Error => ', err)
}

It worked for me, please try it and send me feedback.

letalumil commented 6 years ago

Hi @NickNaso, I just tried the modified command and it works well now.

Thank you for the quick help!

GautierT commented 6 years ago

Works for me too

let cmd = `-psconv -q -dNOPAUSE -sDEVICE=pdfwrite -o ${file_path_repair}  -dPDFSETTINGS=/prepress ${file_path}`
const result = await  gs.execute(cmd)
NickNaso commented 6 years ago

Hi @letalumil and @letalumil , good to hear. So next days I will provide to close the issue. Have a nice day.

blujedis commented 1 year ago

@NickNaso so it appears that switch -sOutputFile doesn't work with ghostscript4js. At least I don't see an output although stdout appears to iterate the pages. That said the above examples did output the file. Is my description accurate or is there something I'm missing. Also would would be the suggestion as to monitoring progress. Say percentage of completion. Maybe getting page count first then counting the ticks (each page) or something? Speaking to compression or any process which iterates each page.