Mathias
Mathias

Reputation: 6839

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?

Upvotes: 6

Views: 7170

Answers (3)

Chris
Chris

Reputation: 69

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

Upvotes: 6

user5470004
user5470004

Reputation: 1

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

Upvotes: -4

KenS
KenS

Reputation: 31199

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.

Upvotes: 5

Related Questions