0

I am trying to convert an external file (e.g http://url.com/file.ext) using Ghostscript and PHP. It always says undefined filename but if I change the url to my server/local url it works. Is it really possible to convert external file?

"C:/Program Files/gs/gs9.14/bin/gswin32.exe" -sDEVICE=tiffg4 -sPAPERSIZE=legal -dBATCH -sOutputFile="C:/Users/user/Desktop/test.tiff" -dNOPAUSE -dBATCH -dSAFER "http://url.com/file.ext"
Yuusha
  • 175
  • 1
  • 3
  • 10

2 Answers2

2

For Linux/Unix/macOS users something like this is useful:

curl YOUR_URL 2>/dev/null | gs -sOutputFile=%stdout -q ... -

Which gets a PDF from stdin and puts the output on stdout.

Just note the ending -, in many command line programs that means read from standard input and in here that allows Ghostscript to read the input pdf file from the pipe so you should - instead your input file name.

Ebrahim Byagowi
  • 10,338
  • 4
  • 70
  • 81
1

Ghostscript doesn't include any browser code. In order to open files i uses the operating system API. If your OS supports opening URLs by using fopen() then it will work, if not, it won't.

KenS
  • 30,202
  • 3
  • 34
  • 51
  • HI. can you please add an example for this? – MisterCat Jan 02 '23 at 23:00
  • I can't see that you need an example, if your OS permits the C library function fopen() to open a remote URL and then fread/fseek/fclose on it, then supplying a URL to Ghostscript on the command line will work. If your OS does not have that functionality, then it won't work. I don't know of any OS which supports fopen on a URL. – KenS Jan 03 '23 at 11:59