Skip to content

Commit

Permalink
Added JPG exporter for a single paged PDF
Browse files Browse the repository at this point in the history
  • Loading branch information
petericebear committed Jul 21, 2019
1 parent 3c6b616 commit 940d0c0
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/Jpg.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace ThreeWS\PdfTools;

use ThreeWS\PdfTools\Exceptions\OpenOutputException;
use ThreeWS\PdfTools\Exceptions\OpenPDFException;
use ThreeWS\PdfTools\Exceptions\OtherException;
use ThreeWS\PdfTools\Exceptions\PDFPermissionException;

class Jpg
{
protected $file;
protected $quality;
protected $progressive;

public function __construct($file, $quality = '60', $progressive = 'y')
{
$this->file = $file;
$this->quality = $quality;
$this->progressive = $progressive;
}

public function convert()
{
exec("pdftocairo -jpeg -jpegopt quality=$this->quality,progressive=$this->progressive -singlefile $this->file $this->file", $output, $returnVar);

switch ($returnVar) {
case 1:
throw new OpenPDFException("Error opening PDF file: {$this->file}.");
break;
case 2:
throw new OpenOutputException();
break;
case 3:
throw new PDFPermissionException();
break;
case 99:
throw new OtherException();
break;
default:
break;
}

return $returnVar;
}
}

0 comments on commit 940d0c0

Please sign in to comment.