Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Count PDF pages from stdin with Ghostscript (PostScript)

Well I found on stackoverflow how to count pages of PDF file using Ghostscript by executing the following command on a shell

gs -q -dNODISPLAY -c "($PATH_TO_PDF) (r) file runpdfbegin pdfpagecount = quit"')

I would like to get the pdf from stdin.

I'll played a little bit around, but with no success.

My approach was:

gs -q -dNODISPLAY - -c "(%stdin) (r) file runpdfbegin pdfpagecount = quit"')

I get no output.

Any hints or suggestions?

like image 681
Mathias Avatar asked May 28 '14 10:05

Mathias


2 Answers

You cannot work with PDF files from stdin, as the PDF format makes it more or less essential to be able to have random access to all parts of the file.

In the cases where Ghostscript reads a PDF file from stdin it first copies it to a local file then works on that, so it isn't working from stdin anyway.

In short, this can't be done.

like image 175
KenS Avatar answered Oct 05 '22 11:10

KenS


This works:

gs -q -dNODISPLAY -c "($PATH_TO_PDF) (r) file runpdfbegin pdfpagecount = quit";

I think the problem with your attempt to use

gs -q -dNODISPLAY -c "($PATH_TO_PDF) (r) file runpdfbegin pdfpagecount = quit"')

was the unmatched closing bracket after QUIT

like image 28
Chris Avatar answered Oct 05 '22 11:10

Chris