File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11<?php
2- require __DIR__ . '/app.php ' ;
32
43use 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
936try {
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-
Original file line number Diff line number Diff line change 11<?php
2- require __DIR__ . '/app.php ' ;
32
43use 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
817try {
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-
You can’t perform that action at this time.
0 commit comments