diff --git a/composer.json b/composer.json index e2a781d..2060ec6 100644 --- a/composer.json +++ b/composer.json @@ -1,11 +1,11 @@ { "name": "grabzit/grabzit", "type": "library", - "keywords": ["screenshots","PDF","DOCX","HTML","table","capture","PNG","JPG","BMP","TIFF","API","web","images","videos","animated gif","csv","xlsx","video conversion","HTML to PDF","HTML to DOCX","HTML to Image","URL to PDF","URL to DOCX","URL to Image"], + "keywords": ["screenshots","PDF","DOCX","HTML","table","capture","PNG","JPG","BMP","TIFF","API","web","images","videos","animated gif","csv","xlsx","video conversion","HTML to PDF","HTML to DOCX","HTML to Image","URL to PDF","URL to DOCX","URL to Image", "Rendered HTML"], "homepage": "https://grabz.it/", "description": "Use our API to allow your app to create images, DOCX documents and PDF's from URL's or raw HTML. Additionally GrabzIt allows you to convert online videos into animated GIF's or HTML tables into CSV's.", "license": "MIT", - "version":"3.3.4.3", + "version":"3.3.5", "autoload": { "psr-4": { "GrabzIt\\": "lib/" diff --git a/lib/GrabzItClient.php b/lib/GrabzItClient.php index 8991b45..07e2c14 100644 --- a/lib/GrabzItClient.php +++ b/lib/GrabzItClient.php @@ -16,6 +16,7 @@ class GrabzItClient const TakeTable = "taketable.ashx"; const TakePDF = "takepdf.ashx"; const TakeDOCX = "takedocx.ashx"; + const TakeHTML = "takehtml.ashx"; const TrueString = "True"; private $applicationKey; @@ -217,6 +218,54 @@ public function FileToImage($path, GrabzItImageOptions $options = null) $this->HTMLToImage(file_get_contents($path), $options); } + /* + This method specifies the URL that should be converted into rendered HTML. + + url - The URL to capture as rendered HTML. + options - A instance of the GrabzItHTMLOptions class that defines any special options to use when creating the rendered HTML. + */ + public function URLToRenderedHTML($url, GrabzItHTMLOptions $options = null) + { + if ($options == null) + { + $options = new GrabzItHTMLOptions(); + } + + $this->request = new GrabzItRequest($this->getRootUrl(false) . GrabzItClient::TakeHTML, false, $options, $url); + } + + /* + This method specifies the HTML that should be converted into rendered HTML. + + html - The HTML to convert into rendered HTML. + options - A instance of the GrabzItHTMLOptions class that defines any special options to use when creating the rendered HTML. + */ + public function HTMLToRenderedHTML($html, GrabzItHTMLOptions $options = null) + { + if ($options == null) + { + $options = new GrabzItHTMLOptions(); + } + + $this->request = new GrabzItRequest($this->getRootUrl(true) . GrabzItClient::TakeHTML, true, $options, $html); + } + + /* + This method specifies a HTML file that should be converted into rendered HTML. + + path - The file path of a HTML file to convert into rendered HTML. + options - A instance of the GrabzItHTMLOptions class that defines any special options to use when creating the rendered HTML. + */ + public function FileToRenderedHTML($path, GrabzItHTMLOptions $options = null) + { + if (!file_exists($path)) + { + throw new GrabzItException("File: " . $path . " does not exist", GrabzItException::FILE_NON_EXISTANT_PATH); + } + + $this->HTMLToRenderedHTML(file_get_contents($path), $options); + } + /* This method specifies the URL that the HTML tables should be extracted from. diff --git a/lib/GrabzItHTMLOptions.php b/lib/GrabzItHTMLOptions.php new file mode 100644 index 0000000..f96354d --- /dev/null +++ b/lib/GrabzItHTMLOptions.php @@ -0,0 +1,191 @@ +browserWidth = $value; + } + + /* + Get the width of the browser in pixels. + */ + public function getBrowserWidth() + { + return $this->browserWidth; + } + + /* + Set the height of the browser in pixels. Use -1 to screenshot the whole web page. + */ + public function setBrowserHeight($value) + { + $this->browserHeight = $value; + } + + /* + Get the height of the browser in pixels. + */ + public function getBrowserHeight() + { + return $this->browserHeight; + } + + /* + Set the CSS selector of the HTML element in the web page that must be visible before the capture is performed. + */ + public function setWaitForElement($value) + { + $this->waitForElement = $value; + } + + /* + Get the CSS selector of the HTML element in the web page that must be visible before the capture is performed. + */ + public function getWaitForElement() + { + return $this->waitForElement; + } + + /* + Set the number of milliseconds to wait before creating the capture. + */ + public function setDelay($value) + { + $this->delay = $value; + } + + /* + Get the number of milliseconds to wait before creating the capture. + */ + public function getDelay() + { + return $this->delay; + } + + /* + Set which user agent type should be used: Standard Browser = 0, Mobile Browser = 1, Search Engine = 2 and Fallback Browser = 3. + */ + public function setRequestAs($value) + { + $this->requestAs = $value; + } + + /* + Get which user agent type should be used. + */ + public function getRequestAs() + { + return $this->requestAs; + } + + /* + Set to true if adverts should be automatically hidden. + */ + public function setNoAds($value) + { + $this->noAds = $value; + } + + /* + Get if adverts should be automatically hidden. + */ + public function getNoAds() + { + return $this->noAds; + } + + /* + Set to true if cookie notification should be automatically hidden. + */ + public function setNoCookieNotifications($value) + { + $this->noCookieNotifications = $value; + } + + /* + Get if cookie notification should be automatically hidden. + */ + public function getNoCookieNotifications() + { + return $this->noCookieNotifications; + } + + /* + Set the URL to execute the HTML code in. + */ + public function setAddress($value) + { + $this->address = $value; + } + + /* + Get the URL to execute the HTML code in. + */ + public function getAddress() + { + return $this->address; + } + + /* + Define a HTTP Post parameter and optionally value, this method can be called multiple times to add multiple parameters. Using this method will force + GrabzIt to perform a HTTP post. + + name - The name of the HTTP Post parameter. + value - The value of the HTTP Post parameter. + */ + public function AddPostParameter($name, $value) + { + $this->post = $this->appendParameter($this->post, $name, $value); + } + + public function _getSignatureString($applicationSecret, $callBackURL, $url = null) + { + $urlParam = ''; + if ($url != null) + { + $urlParam = $this->nullToEmpty($url)."|"; + } + + $callBackURLParam = ''; + if ($callBackURL != null) + { + $callBackURLParam = $this->nullToEmpty($callBackURL); + } + + return $this->nullToEmpty($applicationSecret)."|". $urlParam . $callBackURLParam . + "|".$this->nullToEmpty($this->browserHeight) + ."|".$this->nullToEmpty($this->browserWidth)."|".$this->nullToEmpty($this->getCustomId())."|".$this->nullToEmpty($this->delay)."|".$this->nullToEmpty(intval($this->requestAs))."|".$this->nullToEmpty($this->getCountry())."|". + $this->nullToEmpty($this->getExportURL())."|". + $this->nullToEmpty($this->waitForElement)."|".$this->nullToEmpty($this->getEncryptionKey())."|".$this->nullToEmpty(intval($this->noAds))."|".$this->nullToEmpty($this->post)."|".$this->nullToEmpty($this->getProxy())."|".$this->nullToEmpty($this->address)."|".$this->nullToEmpty(intval($this->noCookieNotifications)); + } + + public function _getParameters($applicationKey, $sig, $callBackURL, $dataName, $dataValue) + { + $params = $this->createParameters($applicationKey, $sig, $callBackURL, $dataName, $dataValue); + $params['bwidth'] = $this->nullToEmpty($this->browserWidth); + $params['bheight'] = $this->nullToEmpty($this->browserHeight); + $params['delay'] = $this->nullToEmpty($this->delay); + $params['requestmobileversion'] = $this->nullToEmpty(intval($this->requestAs)); + $params['waitfor'] = $this->nullToEmpty($this->waitForElement); + $params['noads'] = $this->nullToEmpty(intval($this->noAds)); + $params['post'] = $this->nullToEmpty($this->post); + $params['address'] = $this->nullToEmpty($this->address); + $params['nonotify'] = $this->nullToEmpty(intval($this->noCookieNotifications)); + + return $params; + } +} +?> \ No newline at end of file