-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExampleHtmlToImageAndPdf.php
52 lines (41 loc) · 1.18 KB
/
ExampleHtmlToImageAndPdf.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
use CloudLayerIO\Resources\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();
}