Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty output with when using pdfwrite #30

Closed
letalumil opened this issue Feb 20, 2018 · 7 comments
Closed

Empty output with when using pdfwrite #30

letalumil opened this issue Feb 20, 2018 · 7 comments
Assignees
Labels

Comments

@letalumil
Copy link

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
Copy link

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

@NickNaso
Copy link
Owner

NickNaso commented Feb 21, 2018

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 NickNaso self-assigned this Feb 21, 2018
NickNaso added a commit that referenced this issue Feb 21, 2018
@NickNaso
Copy link
Owner

NickNaso commented Feb 21, 2018

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
Copy link
Author

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

Thank you for the quick help!

@GautierT
Copy link

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
Copy link
Owner

NickNaso commented Feb 22, 2018

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

@blujedis
Copy link

blujedis commented Dec 2, 2022

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants