Count PDF pages from stdin with Ghostscript (PostScript)

Well, I have found on https://stackoverflow.com/a/1961949/ ... a way to count the pages of a PDF file using Ghostscript by running the following command in the shell

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

I would like to get a pdf file from stdin.

I will play a little, but to no avail.

My approach:

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

I have no conclusion.

Any hints or suggestions?

+6
source share
3 answers

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

In cases where Ghostscript reads the PDF file from stdin, it first copies it to the local file and then works on it, so it still doesn't work from stdin.

In short, this is not possible.

+5
source

It works:

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

I think the problem is with your attempt to use

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

was an unsurpassed closing bracket after QUIT

+2
source

It can be done.

 String ars = "-q -dNODISPLAY -dNOPAUSE -sDEVICE=tiffg3 -r150.4 -o" + outputImagesPath + "%d.tiff -sPAPERSIZE=a4 " + inputPDFFile + " -c quit"; Process proc = new Process(); proc.StartInfo.FileName = ghostScriptPath; proc.StartInfo.Arguments = ars; proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.CreateNoWindow = true; proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; proc.Start(); proc.WaitForExit(); //Raise Your Complete Job Event Here And User Directory.GetFiles("..").Count 
-3
source

Source: https://habr.com/ru/post/969950/


All Articles