| Current Path : /home/wirbesti/www/php/ |
| Current File : /home/wirbesti/www/php/testgeneratePDF.php |
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
/* include autoloader */
$getimg = getcwd();
//$getimg = 'C:/xampp/htdocs/wirbestimmen.ch';
require_once $getimg.'/../libraries2/dompdf/autoload.inc.php';
/* reference the Dompdf namespace */
use Dompdf\Dompdf;
try {
/* instantiate and use the dompdf class */
$dompdf = new Dompdf();
$options = $dompdf->getOptions();
$options->setDefaultFont('Arial');
$options->setIsHtml5ParserEnabled(true);
$dompdf->setOptions($options);
//$dompdf->set_option('enable_html5_parser', TRUE);
$image=getcwd();
$adresse= 'Kreuzstrasse 27';
$plz= '8802';
$date= '17.05.1966';
$geburtstag=substr("$date", 0, 2);
$geburtstag2=substr("$date", 3, 2);
$geburtstag3=substr("$date", 6, 4);
$stadt= 'Kilchberg';
$kanton= 'Zürich';
//$randnum= $this->data["randnum"];
$randnum = rand(100000,999999);
//$jpgpath = 'http://localhost/wirbestimmen.ch/images/InitiativePDF/Neue-Bundesverfassung-de-1.jpg';
$jpgpath = 'https://wirbestimmen.ch/images/InitiativePDF/Neue-Bundesverfassung-de-1.jpg';
echo 'file exists = '. file_exists($jpgpath).'<br/>';
//$jpgfullpath = $image."/".$jpgpath;
$jpgfullpath = $jpgpath;
$html = '<html>
<head><meta http-equiv=Content-Type content="text/html; charset=UTF-8">
<style type="text/css">
<!--
span.cls_004{font-family:Times,serif;font-size:10.1px;color:rgb(227,31,37);font-weight:normal;font-style:normal;text-decoration: none}
div.cls_004{font-family:Times,serif;font-size:10.1px;color:rgb(227,31,37);font-weight:normal;font-style:normal;text-decoration: none}
span.cls_005{font-family:"Verdana Bold",serif;font-size:10.1px;color:rgb(33,30,31);font-weight:bold;font-style:normal;text-decoration: none}
div.cls_005{font-family:"Verdana Bold",serif;font-size:10.1px;color:rgb(33,30,31);font-weight:bold;font-style:normal;text-decoration: none}
span.cls_006{font-family:Times,serif;font-size:10.1px;color:rgb(43,42,41);font-weight:normal;font-style:normal;text-decoration: none}
div.cls_006{font-family:Times,serif;font-size:10.1px;color:rgb(43,42,41);font-weight:normal;font-style:normal;text-decoration: none}
span.cls_009{font-family:Arial,serif;font-size:16.5px;color:rgb(227,31,37);font-weight:normal;font-style:normal;text-decoration: none}
div.cls_009{font-family:Arial,serif;font-size:16.5px;color:rgb(227,31,37);font-weight:normal;font-style:normal;text-decoration: none}
span.cls_003{font-family:Times,serif;font-size:14.1px;color:rgb(254,255,255);font-weight:normal;font-style:normal;text-decoration: none}
div.cls_003{font-family:Times,serif;font-size:14.1px;color:rgb(254,255,255);font-weight:normal;font-style:normal;text-decoration: none}
span.cls_007{font-family:Arial,serif;font-size:10.1px;color:rgb(43,42,41);font-weight:normal;font-style:normal;text-decoration: none}
div.cls_007{font-family:Arial,serif;font-size:10.1px;color:rgb(43,42,41);font-weight:normal;font-style:normal;text-decoration: none}
span.cls_008{font-family:Times,serif;font-size:10.1px;color:rgb(43,42,41);font-weight:bold;font-style:normal;text-decoration: none}
div.cls_008{font-family:Times,serif;font-size:10.1px;color:rgb(43,42,41);font-weight:bold;font-style:normal;text-decoration: none}
span.cls_010{font-family:Arial,serif;font-size:13.1px;color:rgb(43,42,41);font-weight:bold;font-style:normal;text-decoration: none}
div.cls_010{font-family:Arial,serif;font-size:13.1px;color:rgb(43,42,41);font-weight:bold;font-style:normal;text-decoration: none}
span.cls_011{font-family:Arial,serif;font-size:5.6px;color:rgb(43,42,41);font-weight:normal;font-style:normal;text-decoration: none}
div.cls_011{font-family:Arial,serif;font-size:5.6px;color:rgb(43,42,41);font-weight:normal;font-style:normal;text-decoration: none}
span.cls_013{font-family:Arial,serif;font-size:3.4px;color:rgb(43,42,41);font-weight:normal;font-style:normal;text-decoration: none}
div.cls_013{font-family:Arial,serif;font-size:3.4px;color:rgb(43,42,41);font-weight:normal;font-style:normal;text-decoration: none}
span.cls_012{font-family:Arial,serif;font-size:5.6px;color:rgb(43,42,41);font-weight:normal;font-style:italic;text-decoration: none}
div.cls_012{font-family:Arial,serif;font-size:5.6px;color:rgb(43,42,41);font-weight:normal;font-style:italic;text-decoration: none}
span.cls_014{font-family:Arial,serif;font-size:3.4px;color:rgb(43,42,41);font-weight:normal;font-style:italic;text-decoration: none}
div.cls_014{font-family:Arial,serif;font-size:3.4px;color:rgb(43,42,41);font-weight:normal;font-style:italic;text-decoration: none}
span.cls_015{font-family:Arial,sans-serif;font-size:11px;color:rgb(43,42,41);font-weight:normal;font-style:normal;text-decoration: none}
div.cls_015{font-family:Arial,sans-serif;font-size:11px;color:rgb(43,42,41);font-weight:normal;font-style:normal;text-decoration: none}
span.cls_016{font-family:Arial,serif;font-size:5.6px;color:rgb(43,42,41);font-weight:bold;font-style:normal;text-decoration: none}
div.cls_016{font-family:Arial,serif;font-size:5.6px;color:rgb(43,42,41);font-weight:bold;font-style:normal;text-decoration: none}
span.cls_017{font-family:Arial,serif;font-size:5.6px;color:rgb(254,255,255);font-weight:bold;font-style:normal;text-decoration: none}
div.cls_017{font-family:Arial,serif;font-size:5.6px;color:rgb(254,255,255);font-weight:bold;font-style:normal;text-decoration: none}
@page { margin: 0px!important;size: a4 portrait!important; }
body,html { margin: 0px!important; }
-->
</style>
</head>
<body>
<div style="position:absolute;left:0px;top:0px; right:0;bottom:0">
<img src="'.$jpgfullpath.'" style="width:100%; height:auto" ></div>
</div>
<div style="position:absolute;left:100px;top:507px" class="cls_015"><span class="cls_015">'.$kanton.'</span></div>
<div style="position:absolute;left:590px;top:507px" class="cls_015"><span class="cls_015">'.$plz.'</span></div>
<div style="position:absolute;left:714px;top:507px" class="cls_015"><span class="cls_015">'.$stadt.'</span></div>
<div style="position:absolute;left:577px;top:626px" class="cls_015"><span class="cls_015">'.$geburtstag.'</span></div>
<div style="position:absolute;left:282px;top:902px" class="cls_015"><span class="cls_015">'.$geburtstag2.'</span></div>
<div style="position:absolute;left:305px;top:902px" class="cls_015"><span class="cls_015">'.$geburtstag3.'</span></div>
<div style="position:absolute;left:709px;top:626px" class="cls_015"><span class="cls_015">'.$adresse.'</span></div>
</body>
</html>
';
$dompdf->loadHtml($html);
/* Render the HTML as PDF */
$dompdf->render();
/* Output the generated PDF to Browser */
$filename2 = $randnum.'.pdf';
$output = $dompdf->output();
file_put_contents($filename2, $output);
} catch(\Exception $e) { echo "<pre>" . print_r($e, true); }