Skip to content

Commit

Permalink
Added example to pass options to API request
Browse files Browse the repository at this point in the history
  • Loading branch information
kishan93 committed Nov 24, 2020
1 parent 91c3a7f commit 3534122
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
37 changes: 33 additions & 4 deletions examples/ExampleHtmlToImageAndPdf.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,52 @@
<?php
require __DIR__ . '/app.php';

use CloudLayerIO\Resources\Html;

$html = new Html('<html><body><h1>Test Title</h1><p>Paragraph</p></body></html>');
require __DIR__ . '/app.php';


$htmlString = '<html><body><h1 class="page-header">Test Title</h1><p>Paragraph</p></body></html>';
$options = [
//options
'format' => 'A4',
'margin' => [
'top' => '156px',
],
'headerTemplate' => [
'method' => 'extract',
'selector' => '.page-header',
'margin' => [
'bottom' => '10px',
],
'imageStyle' => [
'padding-bottom' => '10px',
'height' => '52px',
],
'style' => [
'width' => '100%',
'border-top' => '2px solid #354ca1',
'border-bottom' => '2px solid #354ca1',
],
],
];




try {

//convert to image
$html = new Html($htmlString, $options);
$file = $html->toImage();
$file->save(__DIR__ . '/storage/html-example.png');

//convert to pdf
$html = new Html($htmlString);
$file = $html->toPdf();
$file->save(__DIR__ . '/storage/html-example.pdf');

} catch (\CloudLayerIO\Exceptions\UnauthorizedUsage $exception) {
echo $exception->getMessage();
} catch ( \GuzzleHttp\Exception\ServerException $e){
echo $e->getMessage();
}


18 changes: 15 additions & 3 deletions examples/ExampleUrlToImageAndPdf.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
<?php
require __DIR__ . '/app.php';

use CloudLayerIO\Resources\Url;

$url = new Url('http://example.com');
require __DIR__ . '/app.php';


$options = [
//options
'format' => 'A4',
'margin' => [
'top' => '156px',
],
];


try {

//convert to image
$url = new Url('http://example.com', $options);
$file = $url->toImage();
$file->save(__DIR__ . '/storage/url-example.png');

//convert to pdf
$file = $url->toPdf();
$url = new Url('http://example.com');
$file->save(__DIR__ . '/storage/url-example.pdf');

} catch (\CloudLayerIO\Exceptions\UnauthorizedUsage $exception) {
echo $exception->getMessage();
} catch (\GuzzleHttp\Exception\ServerException $e) {
echo $e->getMessage();
}


0 comments on commit 3534122

Please sign in to comment.