Can't use ghostscript gswin64c to convert a pdf file into image using PHP

34
July 11, 2019, at 9:20 PM

I am trying to convert a pdf into an image using PHP. Platform is windows. Here is the directory structure:

gs9.27
    bin
        gsdll64.dll
        gsdll64.lib
        gswin64.exe
        gswin64c.exe
        test.pdf

Here is my PHP code:

chdir('gs9.27\bin');
echo getcwd() . "\n";
$command = "gswin64c -dBATCH -dNOPAUSE -r150 -sDEVICE=jpeg -sOutputFile=test.jpg test.pdf 2>&1";
exec($command,$output);
echo '<pre>';
print_r($output);
echo '</pre>';

When I execute the command, I got the error message saying:

Array
(
[0] => GPL Ghostscript 9.27 (2019-04-04)
[1] => Copyright (C) 2018 Artifex Software, Inc.  All rights reserved.
[2] => This software is supplied under the GNU AGPLv3 and comes with NO WARRANTY:
[3] => see the file COPYING for details.
[4] => Processing pages 1 through 1.
[5] => Page 1
[6] => GPL Ghostscript 9.27: **** Could not open the file 'test.jpg'.
[7] => Error: /invalidfileaccess in --showpage--
[8] => Operand stack:
[9] =>    1   true
[10] => Execution stack:
[11] =>    %interp_exit   .runexec2   --nostringval--   showpage   --nostringval--   2   %stopped_push   --nostringval--   showpage   showpage   false   1   %stopped_push   1992   1   3   %oparray_pop   1991   1   3   %oparray_pop   1979   1   3   %oparray_pop   1980   1   3   %oparray_pop   showpage   showpage   2   1   1   showpage   %for_pos_int_continue   1983   1   7   %oparray_pop   showpage   showpage   1840   0   9   %oparray_pop   showpage   showpage
[12] => Dictionary stack:
[13] =>    --dict:735/1123(ro)(G)--   --dict:1/20(G)--   --dict:80/200(L)--   --dict:80/200(L)--   --dict:133/256(ro)(G)--   --dict:315/325(ro)(G)--   --dict:33/64(L)--   --dict:6/9(L)--   --dict:7/20(L)--
[14] => Current allocation mode is local
[15] => Last OS error: Permission denied
[16] => GPL Ghostscript 9.27: Unrecoverable error, exit code 1
)

test.jpg is the output file, not input, so why I got the could not open file error message? how to fix this issue?

READ ALSO
How to restrict unsuitable requests using validation rules in Laravel 5.8?

How to restrict unsuitable requests using validation rules in Laravel 5.8?

I have only one validation rule in my Laravel project:

48
Sort result with empty strings last

Sort result with empty strings last

I have this locations table:

46
&ldquo;No module named specutils&rdquo; although specutils installation went through

“No module named specutils” although specutils installation went through

I am trying to install the Specutils packageI followed these instructions and typed the following command in my Anaconda Prompt terminal:

21