-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added example to pass options to API request
- Loading branch information
Showing
2 changed files
with
48 additions
and
7 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 |
---|---|---|
@@ -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(); | ||
} | ||
|
||
|
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 |
---|---|---|
@@ -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(); | ||
} | ||
|
||
|