Skip to content

Instantly share code, notes, and snippets.

@sgringwe
Created September 27, 2015 23:07
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sgringwe/bf1cbcdfa0e2e2700cc2 to your computer and use it in GitHub Desktop.
Save sgringwe/bf1cbcdfa0e2e2700cc2 to your computer and use it in GitHub Desktop.
Check pdf validity using ghostscript
gs -dNOPAUSE -dBATCH -sDEVICE=nullpage valid.pdf
GPL Ghostscript 9.16 (2015-03-30)
Copyright (C) 2015 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
(return code 0)
: gs -dNOPAUSE -dBATCH -sDEVICE=nullpage invalid.pdf
GPL Ghostscript 9.16 (2015-03-30)
Copyright (C) 2015 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
**** This file uses an unknown security handler.
**** The file was produced by:
��+dr��� <<<<��.]��{[1$3�*M=��]H&T��v�U@�r�,t�
Error: /undefined in pdf_process_Encrypt
Operand stack:
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1951 1 3 %oparray_pop 1950 1 3 %oparray_pop 1934 1 3 %oparray_pop --nostringval-- --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push --nostringval--
Dictionary stack:
--dict:1182/1684(ro)(G)-- --dict:1/20(G)-- --dict:83/200(L)-- --dict:83/200(L)-- --dict:117/127(ro)(G)-- --dict:280/300(ro)(G)-- --dict:22/32(L)--
Current allocation mode is local
Last OS error: Invalid argument
GPL Ghostscript 9.16: Unrecoverable error, exit code 1
:
(return code 1)
@mijorus
Copy link

mijorus commented Dec 29, 2021

I know you were here for this.... 👀

exec("gs -dNOPAUSE -dBATCH -sDEVICE=nullpage {$pdf_filename}", $output, $return_var);
  if($return_var) {
    // error handling
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment