-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
172 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
//include the autoloader | ||
require_once('../vendor/autoload.php'); | ||
|
||
use Ilovepdf\Ilovepdf; | ||
use Ilovepdf\SplitTask; | ||
|
||
|
||
try { | ||
// start the manager classy | ||
$ilovepdf = new Ilovepdf("PUBLIC_KEY", "SECRET_KEY"); | ||
|
||
// and get the task tool | ||
$myTask = $ilovepdf->newTask('split'); | ||
|
||
// or you can call task class directly, this set the same tool as before | ||
$myTask = new SplitTask("PUBLIC_KEY", "SECRET_KEY"); | ||
|
||
|
||
// file var keeps info about server file id, name... | ||
// it can be used latter to cancel file | ||
$file = $myTask->addFile('/path/to/file/document.pdf'); | ||
|
||
// set ranges to split the document | ||
$myTask->setRanges("2-4,6-8"); | ||
|
||
// and set name for output file. | ||
// in this case it will output a zip file, so we set the package name. | ||
$myTask->setPackagedFilename('split_documents'); | ||
|
||
// and name for splitted document (inside the zip file) | ||
$myTask->setOutputFilename('split'); | ||
|
||
// process files | ||
// time var will have info about time spent in process | ||
$time = $myTask->execute(); | ||
|
||
// and finally download file. If no path is set, it will be donwloaded on current folder | ||
$myTask->download('path/to/download'); | ||
|
||
} catch (\Ilovepdf\Exceptions\StartException $e) { | ||
echo "An error occured on start: " . $e->getMessage() . " "; | ||
} catch (\Ilovepdf\Exceptions\AuthException $e) { | ||
echo "An error occured on auth: " . $e->getMessage() . " "; | ||
echo implode(', ', $e->getErrors()); | ||
} catch (\Ilovepdf\Exceptions\UploadException $e) { | ||
echo "An error occured on upload: " . $e->getMessage() . " "; | ||
echo implode(', ', $e->getErrors()); | ||
} catch (\Ilovepdf\Exceptions\ProcessException $e) { | ||
echo "An error occured on process: " . $e->getMessage() . " "; | ||
echo implode(', ', $e->getErrors()); | ||
} catch (\Exception $e) { | ||
echo "An error occured: " . $e->getMessage(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace Ilovepdf\Exceptions; | ||
|
||
class DownloadException extends ExtendedException { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Ilovepdf\Exceptions; | ||
|
||
class ExtendedException extends \Exception | ||
{ | ||
|
||
private $params; | ||
private $type; | ||
|
||
/** | ||
* ExtendedException constructor. | ||
* @param string $message | ||
* @param int $code | ||
* @param Exception|null $previous | ||
* @param $response | ||
*/ | ||
public function __construct($message, $code = 0, Exception $previous = null, $response) | ||
{ | ||
$this->type = $response->body->error->type; | ||
$this->params = $response->body->error->param; | ||
|
||
if (is_array($this->params) && isset($this->params[0]) && isset($this->params[0]->error)) { | ||
parent::__construct($message . ' (' . $this->params[0]->error . ')', $code, $previous); | ||
} else { | ||
parent::__construct($message, $code, $previous); | ||
} | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getErrors() | ||
{ | ||
return $this->params; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getType() | ||
{ | ||
return $this->type; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Ilovepdf; | ||
/** | ||
* Class LockTask | ||
* | ||
* @package Ilovepdf | ||
*/ | ||
class ProtectTask extends Task | ||
{ | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $password; | ||
|
||
/** | ||
* UnlockTask constructor. | ||
* @param string $publicKey | ||
* @param string $secretKey | ||
*/ | ||
function __construct($publicKey, $secretKey) | ||
{ | ||
$this->tool = 'protect'; | ||
parent::__construct($publicKey, $secretKey); | ||
} | ||
|
||
/** | ||
* @param string $password | ||
*/ | ||
public function setPassword($password) | ||
{ | ||
$this->password = $password; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters