Skip to content

Commit

Permalink
htmlpdf
Browse files Browse the repository at this point in the history
  • Loading branch information
maztch committed Sep 25, 2019
1 parent 037fd51 commit e404f15
Show file tree
Hide file tree
Showing 11 changed files with 262 additions and 6 deletions.
3 changes: 3 additions & 0 deletions init.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

//Specific processes
require_once __DIR__ . '/src/CompressTask.php';
require_once __DIR__ . '/src/ExtractTask.php';
require_once __DIR__ . '/src/HtmlpdfTask.php';
require_once __DIR__ . '/src/ImagepdfTask.php';
require_once __DIR__ . '/src/MergeTask.php';
require_once __DIR__ . '/src/OfficepdfTask.php';
Expand All @@ -34,5 +36,6 @@
require_once __DIR__ . '/src/RotateTask.php';
require_once __DIR__ . '/src/SplitTask.php';
require_once __DIR__ . '/src/UnlockTask.php';
require_once __DIR__ . '/src/ValidatepdfaTask.php';
require_once __DIR__ . '/src/WatermarkTask.php';

33 changes: 33 additions & 0 deletions samples/htmlpdf_advanced.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
//include the autoloader
require_once('../vendor/autoload.php');
//if manual installation has been used comment line that requires the autoload and uncomment this line:
//require_once('../init.php');


use Ilovepdf\HtmlpdfTask;


// you can call task class directly
// to get your key pair, please visit https://developer.ilovepdf.com/user/projects
$myTask = new HtmlpdfTask('project_public_id','project_secret_key');

// file var keeps info about server file id, name...
// it can be used latter to cancel file
$file = $myTask->addUrl('https://ilovepdf.com');

// set page margin
$myTask->setPageMargin(20);

// set one large page
$myTask->setSinglePage(true);

// and set name for output file.
// the task will set the correct file extension for you.
$myTask->setOutputFilename('ilovepdf_web');

// process files
$myTask->execute();

// and finally download file. If no path is set, it will be downloaded on current folder
$myTask->download('path/to/download');
22 changes: 22 additions & 0 deletions samples/htmlpdf_basic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
//include the autoloader
require_once('../vendor/autoload.php');
//if manual installation has been used comment line that requires the autoload and uncomment this line:
//require_once('../init.php');

use Ilovepdf\HtmlpdfTask;


// you can call task class directly
// to get your key pair, please visit https://developer.ilovepdf.com/user/projects
$myTask = new HtmlpdfTask('project_public_id','project_secret_key');

// file var keeps info about server file id, name...
// it can be used latter to cancel file
$file = $myTask->addUrl('https://ilovepdf.com');

// process files
$myTask->execute();

// and finally download file. If no path is set, it will be downloaded on current folder
$myTask->download();
1 change: 1 addition & 0 deletions src/CompressTask.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace Ilovepdf;

/**
* Class CompressTask
*
Expand Down
3 changes: 2 additions & 1 deletion src/ExtractTask.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

namespace Ilovepdf;

/**
* Class CompressTask
* Class ExtractTask
*
* @package Ilovepdf
*/
Expand Down
196 changes: 196 additions & 0 deletions src/HtmlpdfTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
<?php

namespace Ilovepdf;
/**
* Class Ilovepdf
*
* @package Ilovepdf
*/
class HtmlpdfTask extends Task
{
/**
* Viewer width
* @var integer
*/
public $view_width = 1920;

/**
* Viewer height
* @var integer
*/
public $view_height;

/**
* Time to waith for page response
* - default is 10
*
* @var integer
*/
public $navigation_timeout = 10;

/**
* Time to wait for javscript execution in page
* - value must be between 0 and 5
* - default is 2
*
* @var integer
*/
public $delay = 2;

/**
* @var string
*/
public $page_size;

private $pageSizeValues = ['A3', 'A4', 'A5', 'A6', 'Letter'];

/**
* @var string
*/
public $page_orientation;

private $pageOrientationyValues = ['portrait', 'landscape'];

/**
* Pixels for page margin
* @var integer
*/
public $page_margin = 0;

/**
* Remove z-index (high value) based elements
*
* @var boolean
*/
public $remove_popups;

/**
* @var boolean
*/
public $single_page;

/**
* AddnumbersTask constructor.
*
* @param null|string $publicKey Your public key
* @param null|string $secretKey Your secret key
* @param bool $makeStart Set to false for chained tasks, because we don't need the start
*/
function __construct($publicKey, $secretKey, $makeStart = true)
{
$this->tool = 'htmlpdf';
parent::__construct($publicKey, $secretKey, $makeStart);

return true;
}

/**
* @param int $view_width
* @return HtmlpdfTask
*/
public function setViewWidth(int $view_width): HtmlpdfTask
{
$this->view_width = $view_width;
return $this;
}

/**
* @param int $view_height
* @return HtmlpdfTask
*/
public function setViewHeight(int $view_height): HtmlpdfTask
{
$this->view_height = $view_height;
return $this;
}

/**
* @param int $navigation_timeout
* @return HtmlpdfTask
*/
public function setNavigationTimeout(int $navigation_timeout): HtmlpdfTask
{
if ($navigation_timeout < 0 && $navigation_timeout > 20) {
new \InvalidArgumentException('Delay must be under 5 seconds');
}
$this->navigation_timeout = $navigation_timeout;
return $this;
}

/**
* @param int $delay
* @return HtmlpdfTask
*/
public function setDelay(int $delay): HtmlpdfTask
{
if ($delay < 0 && $delay > 5) {
new \InvalidArgumentException('Delay must be under 5 seconds');
}
$this->delay = $delay;
return $this;
}

/**
* @param string $page_size
* @return HtmlpdfTask
*/
public function setPageSize(string $page_size): HtmlpdfTask
{
$this->checkValues($page_size, $this->pageSizeValues);
$this->page_size = $page_size;
return $this;
}

/**
* @param string $page_orientation
* @return HtmlpdfTask
*/
public function setPageOrientation(string $page_orientation): HtmlpdfTask
{
$this->checkValues($page_orientation, $this->pageOrientationyValues);

$this->page_orientation = $page_orientation;
return $this;
}

/**
* @param int $page_margin
* @return HtmlpdfTask
*/
public function setPageMargin(int $page_margin): HtmlpdfTask
{
$this->page_margin = $page_margin;
return $this;
}

/**
* @param bool $remove_popups
* @return HtmlpdfTask
*/
public function setRemovePopups(bool $remove_popups): HtmlpdfTask
{
$this->remove_popups = $remove_popups;
return $this;
}

/**
* @param bool $single_page
* @return HtmlpdfTask
*/
public function setSinglePage(bool $single_page): HtmlpdfTask
{
$this->single_page = $single_page;
return $this;
}

/**
* Add an url to process.
*
* @param string $url
* @return File|mixed
*/
public function addUrl($url)
{
return $this->addFileFromUrl($url);
}
}
2 changes: 1 addition & 1 deletion src/Ilovepdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Ilovepdf
// @var string|null The version of the Ilovepdf API to use for requests.
public static $apiVersion = 'v1';

const VERSION = 'php.1.1.16';
const VERSION = 'php.1.1.17';

public $token = null;

Expand Down
2 changes: 1 addition & 1 deletion src/ImagepdfTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


/**
* Class Ilovepdf
* Class ImagepdfTask
*
* @package Ilovepdf
*/
Expand Down
2 changes: 1 addition & 1 deletion src/PdfaTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Ilovepdf;
/**
* Class CompressTask
* Class PdfaTask
*
* @package Ilovepdf
*/
Expand Down
2 changes: 1 addition & 1 deletion src/ProtectTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Ilovepdf;
/**
* Class LockTask
* Class ProtectTask
*
* @package Ilovepdf
*/
Expand Down
2 changes: 1 addition & 1 deletion src/ValidatepdfaTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Ilovepdf;
/**
* Class CompressTask
* Class ValidatepdfaTask
*
* @package Ilovepdf
*/
Expand Down

0 comments on commit e404f15

Please sign in to comment.