diff --git a/foomaticrip.h b/foomaticrip.h
index 2777672..fea8e47 100644
--- a/foomaticrip.h
+++ b/foomaticrip.h
@@ -94,6 +94,7 @@ extern int spooler;
#define PATH_MAX 65536
+#define CMDLINE_MAX 65536
typedef struct {
char printer[256];
diff --git a/pdf.c b/pdf.c
index ebd6ab5..ee4eb51 100644
--- a/pdf.c
+++ b/pdf.c
@@ -41,14 +41,13 @@ static int wait_for_renderer();
static int pdf_count_pages(const char *filename)
{
- char gscommand[4095];
+ char gscommand[CMDLINE_MAX];
char output[31] = "";
int pagecount;
- snprintf(gscommand, 4095, "%s -dNODISPLAY -q -c "
- "'/pdffile (%s) (r) file def pdfdict begin pdffile pdfopen begin "
- "(PageCount: ) print pdfpagecount == flush currentdict pdfclose "
- "end end quit'",
+ snprintf(gscommand, CMDLINE_MAX, "%s -dNODISPLAY -q -c "
+ "'/pdffile (%s) (r) file runpdfbegin (PageCount: ) print "
+ "pdfpagecount = quit'",
gspath, filename);
FILE *pd = popen(gscommand, "r");