imalhasaranga / PDFLib

Current Release provide you methods to convert PDF to Images as well as Images to PDF, future releases will included more functions to interact with PDF files
MIT License
58 stars 37 forks source link

GPL Ghostscript 9.52: Unrecoverable error, exit code 1 #19

Open imansa opened 3 years ago

imansa commented 3 years ago

this is result of running following php sample codes in command line

$pdflib = new ImalH\PDFLib\PDFLib();
$pdflib->setPdfPath('./sample.pdf');
$pdflib->setOutputPath('./images/');
$pdflib->setImageFormat(\ImalH\PDFLib\PDFLib::$IMAGE_FORMAT_PNG);
$pdflib->setDPI(96);
$pdflib->setPageRange(1,$pdflib->getNumberOfPages());
$pdflib->setFilePrefix('page-'); // Optional
$pdflib->convert();

GPL Ghostscript 9.52: Unrecoverable error, exit code 1

error is for running getNumberOfPages method

sample.pdf is near to php file and there is an images folder there

imansa commented 3 years ago

pdf file is an standard pdf file and is converted before with other pdf to image php classes like https://github.com/spatie/pdf-to-image

imalhasaranga commented 3 years ago

hmm.. will have to look into, @mablae do you think you can check this issue ?

Fegra commented 3 years ago

I modified this library for me.

public function getNumberOfPages(){ if($this->number_of_pages == -1){ if($this->gs_command == "gswin32c.exe" || $this->gs_command == "gswin64c.exe"){ $this->pdf_path = str_replace('\', '/', $this->pdf_path); $delimiter = "\/"; $exit=preg_split("/".$delimiter."([^".$delimiter."]+)$/", $this->pdf_path,-1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); $ex="--permit-file-read=".$exit[0]."/"; } $pages = $this->executeGS('-q '.$ex.' -dNODISPLAY -c "('.$this->pdf_path.') (r) file runpdfbegin pdfpagecount = quit"',true); $this->number_of_pages = intval($pages); } return $this->number_of_pages; }

yannickl88 commented 3 years ago

I'm running into the same problem. Have you had time to look at this?