Skip to content

Commit 3534122

Browse files
committed
Added example to pass options to API request
1 parent 91c3a7f commit 3534122

File tree

2 files changed

+48
-7
lines changed

2 files changed

+48
-7
lines changed

examples/ExampleHtmlToImageAndPdf.php

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,52 @@
11
<?php
2-
require __DIR__ . '/app.php';
32

43
use CloudLayerIO\Resources\Html;
54

6-
$html = new Html('<html><body><h1>Test Title</h1><p>Paragraph</p></body></html>');
5+
require __DIR__ . '/app.php';
6+
7+
8+
$htmlString = '<html><body><h1 class="page-header">Test Title</h1><p>Paragraph</p></body></html>';
9+
$options = [
10+
//options
11+
'format' => 'A4',
12+
'margin' => [
13+
'top' => '156px',
14+
],
15+
'headerTemplate' => [
16+
'method' => 'extract',
17+
'selector' => '.page-header',
18+
'margin' => [
19+
'bottom' => '10px',
20+
],
21+
'imageStyle' => [
22+
'padding-bottom' => '10px',
23+
'height' => '52px',
24+
],
25+
'style' => [
26+
'width' => '100%',
27+
'border-top' => '2px solid #354ca1',
28+
'border-bottom' => '2px solid #354ca1',
29+
],
30+
],
31+
];
32+
33+
734

835

936
try {
1037

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

1543
//convert to pdf
44+
$html = new Html($htmlString);
1645
$file = $html->toPdf();
1746
$file->save(__DIR__ . '/storage/html-example.pdf');
1847

1948
} catch (\CloudLayerIO\Exceptions\UnauthorizedUsage $exception) {
2049
echo $exception->getMessage();
50+
} catch ( \GuzzleHttp\Exception\ServerException $e){
51+
echo $e->getMessage();
2152
}
22-
23-

examples/ExampleUrlToImageAndPdf.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
11
<?php
2-
require __DIR__ . '/app.php';
32

43
use CloudLayerIO\Resources\Url;
54

6-
$url = new Url('http://example.com');
5+
require __DIR__ . '/app.php';
6+
7+
8+
$options = [
9+
//options
10+
'format' => 'A4',
11+
'margin' => [
12+
'top' => '156px',
13+
],
14+
];
15+
716

817
try {
918

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

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

1829
} catch (\CloudLayerIO\Exceptions\UnauthorizedUsage $exception) {
1930
echo $exception->getMessage();
31+
} catch (\GuzzleHttp\Exception\ServerException $e) {
32+
echo $e->getMessage();
2033
}
2134

22-

0 commit comments

Comments
 (0)