Closed lukassteiner closed 4 years ago
Hi @lukassteiner, try to execute this command
const gs = require('ghostscript4js');
const command = `-psconv -q -r300 -sPAPERSIZE=a4 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dUseTrimBox -sDEVICE=jpeg -dDownScaleFactor=3 -o out-%d.jpg -dJPEGQ=100 -f in.pdf`;
await gs.execute(command);
It should solve your problem. Send me a feedback if it works for you.
Hi @NickNaso Thanks a lot for the command! This works very well.
I just have a case with a specific pdf where I get this output even with your command:
Error: stream operator isn't terminated by valid EOL. Output may be incorrect. Error: stream operator isn't terminated by valid EOL. Output may be incorrect. Error: stream operator isn't terminated by valid EOL. Output may be incorrect. Error: stream operator isn't terminated by valid EOL. Output may be incorrect.
I am not able to publish the pdf publicly but I will send it to you per email. Maybe you know a way to suppress that output as well.
Hi @lukassteiner, I just received your pdf and in next couple of days I will investigate the reasons behind your error and I will answer here.
I'm having a similar issue where I have GS repair corrupted PDFs. It'd be great to find a way to suppress this:
**** Error: Encountered 'obj' while expecting 'endobj'.
Treating this as a missing 'endobj', output may be incorrect.
Hi @freewil, do you obtain this error only the addon? Could you try to execute the command directly with the ghostscript command line over the same file and report if you obtain the same error? Thank you.
@NickNaso I receive the error when running it with the addon via node and via the command-line directly from my shell. From my shell, I can confirm GS is outputting the error/warning to stdout. Since GS is processing a corrupted PDF, it's to be expected that it outputs the "error" or "warning" while processing. GS still successfully creates the output PDF, it's really just a warning, but it would be nice to somehow suppress its output via output redirection to another stream (like /dev/null) or file descriptor.
I tried to create a corrupted PDF without sensitive information that I'm working with for an example, but was unable to immediately do so.
This is the command I am running:
(async () => {
const cmd = ['-psconv', '-q', '-o', repairedFile, '-sDEVICE=pdfwrite', '-dPDFSETTINGS=/prepress', corruptedFile]
await gs.execute(cmd)
})()
$ gs -q -o repaired.pdf -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress corrupted.pdf
**** Error: Encountered 'obj' while expecting 'endobj'.
Treating this as a missing 'endobj', output may be incorrect.
Hi @freewil, thanks for your feedback now I'm sure that the problem is in the redirection of the stream. In the next days I need to investigate how to do that.
I have this issue with one PDF as well. Is there a solution?
Is this fixed in the newest release @NickNaso ?
I happen to have the same issue as @freewil. Did anyone able to find the root cause and how to resolve this issue?
I was able to work around to fix this issue. Hopefully, it will solve yours. Identify the pdf which throws the below error
**** Error: Encountered 'obj' while expecting 'endobj'. Treating this as a missing 'endobj', output may be incorrect.
Then fix the pdf separately using the below command:
gs -o gs-repaired---35.pdf -dPDFSETTINGS=/prepress -sDEVICE=pdfwrite 35.pdf
Is there a way to suppress the console output of ghostscript? When I convert a pdf to jpg like this:
I get this output in the console:
When I use the gs command directly, I usually just add the "-q" flag.