PDFLib icon indicating copy to clipboard operation
PDFLib copied to clipboard

Added --permit-file-read when getting number of pages

Open yannickl88 opened this issue 3 years ago • 3 comments

See https://www.ghostscript.com/doc/current/Use.htm#Safer

As of ghostscript 9.50 a more strict implementation is used for managing access to files. This means it now defaults to -dSAFER when calling command. This will cause PDFLib to not be able to read the number of pages in a PDF and will given an error "GPL Ghostscript 9.52: Unrecoverable error, exit code 1", falling back to 0 pages.

By adding --permit-file-read to the command this solved this issues and should solve #19. This should work on both Linux and Windows. (My guess is that is also required for Linux, but I cannot verify this.)

Note: All the tests were broken for me with a fresh clone and using PHP 7.5 and Ghostscript 9.52 on a Windows machine. With this patch I was able to successfully run the tests except testImageToPdf which fails with the following error:

mkdir(): No such file or directory
 C:\...\PDFLib\tests\PDFLibTest.php:153
 C:\...\PDFLib\tests\PDFLibTest.php:113

yannickl88 avatar Apr 25 '21 13:04 yannickl88

Also note, I've tested this fix on my local machine. So I guess all I can provide in the way of proof that it works is "Works on my machine".

yannickl88 avatar Apr 25 '21 13:04 yannickl88

I just realized the option might not be available in all versions of ghostscript that pdflib supports. I might need to do a feature check. It seems like this commit introduced them, http://git.ghostscript.com/?p=ghostpdl.git;a=log;h=7ecbfda92b4c8dbf6f6c2bf8fc82020a29219eff

My guess is that this might be version 9.50. Their git repository is a bit difficult to browse.

I can do two things:

  1. check the version and only add the extra option if 9.50 or higher. Or,
  2. Drop support for 9.50 or lower.

yannickl88 avatar Apr 25 '21 15:04 yannickl88

Just a bump: Ubuntu 20.04.5 LTS; gs 9.50 and PHP 7.4.3, still won't write out PNG files from a PDF, and dies with Ghostscript 9.50: Unrecoverable error, exit code 1

Tried applying soulution like in this PR, but to no avail.

Anyone found a solution?

sveby avatar Jan 23 '23 15:01 sveby