Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/PDFLib.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class PDFLib{
private $imageDeviceCommand;
private $imageExtention;
private $pngDownScaleFactor;
private $convertOptions = array();

private $is_os_win = null;
private $gs_command = null;
Expand All @@ -53,6 +54,7 @@ public function __construct(){
$this->imageDeviceCommand = "";
$this->imageExtention = "";
$this->pngDownScaleFactor = "";
$this->convertOptions = array(array("NumRenderingThreads", 4));

$this->setDPI(self::$MAX_RESOLUTION);
$this->setImageFormat(self::$IMAGE_FORMAT_JPEG);
Expand Down Expand Up @@ -99,6 +101,27 @@ public function setImageFormat($imageformat,$pngScaleFactor = null){
}
}

public function setConvertOption($name, $token) {
$this->unsetConvertOption($name);
$this->convertOptions[] = array($name, $token);
}

public function unsetConvertOption($name) {
foreach ($this->convertOptions as $key => $nametoken) {
if ($nametoken[0] == $name) {
unset($this->convertOptions[$key]);
}
}
}

protected function getConvertOptionsString() {
$options = array();
foreach ($this->convertOptions as $nametoken) {
$options[] = "-d$nametoken[0]=$nametoken[1]";
}
return implode(" ", $options);
}

public function getNumberOfPages(){
if($this->number_of_pages == -1){
$pages = $this->executeGS('-q -dNODISPLAY -c "("'.$this->pdf_path.'") (r) file runpdfbegin pdfpagecount = quit"',true);
Expand Down Expand Up @@ -126,7 +149,7 @@ public function convert(){
$this->jpeg_quality = 100;
}
$image_path = $this->output_path."/page-%d.".$this->imageExtention;
$output = $this->executeGS("-dSAFER -dBATCH -dNOPAUSE -sDEVICE=".$this->imageDeviceCommand." ".$this->pngDownScaleFactor." -r".$this->resolution." -dNumRenderingThreads=4 -dFirstPage=".$this->page_start." -dLastPage=".$this->page_end." -o\"".$image_path."\" -dJPEGQ=".$this->jpeg_quality." -q \"".($this->pdf_path)."\" -c quit");
$output = $this->executeGS("-dSAFER -dBATCH -dNOPAUSE -sDEVICE=".$this->imageDeviceCommand." ".$this->pngDownScaleFactor." -r".$this->resolution." ".$this->getConvertOptionsString()." -dFirstPage=".$this->page_start." -dLastPage=".$this->page_end." -o\"".$image_path."\" -dJPEGQ=".$this->jpeg_quality." -q \"".($this->pdf_path)."\" -c quit");

$fileArray = [];
for($i=1; $i<=($this->page_end - $this->page_start + 1); ++$i){
Expand Down