File tree Expand file tree Collapse file tree 2 files changed +48
-7
lines changed Expand file tree Collapse file tree 2 files changed +48
-7
lines changed Original file line number Diff line number Diff line change 1
1
<?php
2
- require __DIR__ . '/app.php ' ;
3
2
4
3
use CloudLayerIO \Resources \Html ;
5
4
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
+
7
34
8
35
9
36
try {
10
37
11
38
//convert to image
39
+ $ html = new Html ($ htmlString , $ options );
12
40
$ file = $ html ->toImage ();
13
41
$ file ->save (__DIR__ . '/storage/html-example.png ' );
14
42
15
43
//convert to pdf
44
+ $ html = new Html ($ htmlString );
16
45
$ file = $ html ->toPdf ();
17
46
$ file ->save (__DIR__ . '/storage/html-example.pdf ' );
18
47
19
48
} catch (\CloudLayerIO \Exceptions \UnauthorizedUsage $ exception ) {
20
49
echo $ exception ->getMessage ();
50
+ } catch ( \GuzzleHttp \Exception \ServerException $ e ){
51
+ echo $ e ->getMessage ();
21
52
}
22
-
23
-
Original file line number Diff line number Diff line change 1
1
<?php
2
- require __DIR__ . '/app.php ' ;
3
2
4
3
use CloudLayerIO \Resources \Url ;
5
4
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
+
7
16
8
17
try {
9
18
10
19
//convert to image
20
+ $ url = new Url ('http://example.com ' , $ options );
11
21
$ file = $ url ->toImage ();
12
22
$ file ->save (__DIR__ . '/storage/url-example.png ' );
13
23
14
24
//convert to pdf
15
25
$ file = $ url ->toPdf ();
26
+ $ url = new Url ('http://example.com ' );
16
27
$ file ->save (__DIR__ . '/storage/url-example.pdf ' );
17
28
18
29
} catch (\CloudLayerIO \Exceptions \UnauthorizedUsage $ exception ) {
19
30
echo $ exception ->getMessage ();
31
+ } catch (\GuzzleHttp \Exception \ServerException $ e ) {
32
+ echo $ e ->getMessage ();
20
33
}
21
34
22
-
You can’t perform that action at this time.
0 commit comments