<?php // reference the Dompdf namespace
use Dompdf\Dompdf;
require_once 'dompdf/autoload.inc.php';
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == "generate-one-sheet" && check_admin_referer( 'verify_generate_one_sheet', 'nonce_generate_one_sheet' )) {
ob_start();
$my_postid = $_POST['postid'];
$logo = get_field('logo','options');
$content_post = get_post($my_postid);
$thecontent = $content_post->post_content;
$thecontent = apply_filters('the_content', $thecontent);
$omschrijving = get_field('omschrijving',$my_postid);
$inhoud = get_field('inhoud',$my_postid);
$doelgroep = get_field('doelgroep',$my_postid);
$voorkennis = get_field('voorkennis',$my_postid);
$duur = get_field('duur',$my_postid);
$groepsgrootte = get_field('groepsgrootte',$my_postid);
$certificaat = get_field('certificaat',$my_postid); ?>
<?php the_field('omschrijving'); ?>
<div class="row doelgroep">
<span class="ttle">Inhoud</span>
<?php the_field('inhoud');?>
</div>
<div id="inf">
<?php if(get_field('doelgroep')):?>
<div class="row doelgroep">
<span class="ttle">Doelgroep</span>
<p><?php the_field('doelgroep');?></p>
</div>
<?php endif; ?>
<?php if(get_field('voorkennis')):?>
<div class="row voorkennis">
<span class="ttle">Voorkennis</span>
<p><?php the_field('voorkennis');?></p>
</div>
<?php endif; ?>
<?php if(get_field('duur')):?>
<div class="row duur">
<span class="ttle">Duur</span>
<p><?php the_field('duur');?></p>
</div>
<?php endif; ?>
<?php if(get_field('groepsgrootte')):?>
<div class="row groepsgrootte">
<span class="ttle">Groepsgrootte</span>
<p><?php the_field('groepsgrootte');?></p>
</div>
<?php endif; ?>
<?php if(get_field('certificaat')):?>
<div class="row certificaat">
<span class="ttle">Certificaat</span>
<p><?php the_field('certificaat');?></p>
</div>
<?php endif; ?>
<div class="row prijs">
<span class="ttle">Kosten</span>
<p>
<?php if(get_field("prijs_op_aanvraag")):?>
<span>Prijs op aanvraag.</span>
<?php else:
$prijs_uf = get_field('prijs');
$prijs = number_format($prijs_uf, 2, ',', '.');
$prijs_korting_uf = get_field('prijs_inclusief_korting');
$prijs_korting = number_format($prijs_korting_uf, 2, ',', '.');
?>
<?php if(get_field("vanaf_prijs")):?><span style="padding-right: 2px;">Vanaf</span><?php endif; ?>
<?php if($prijs_korting || $prijs): if($prijs_korting):?><strike>€ <?php echo $prijs;?></strike> <span>€ <?php echo $prijs_korting; ?></span><?php else: ?><span>€ <?php echo $prijs;?></span><?php endif; ?><?php endif; ?>
<span>(excl. BTW).</span>
</p>
<?php endif; ?>
</div>
</div>
<?php
$data = ob_get_contents();
ob_end_clean();
$content = '
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Cabin:400,500,600,700" rel="stylesheet">
<style>
body {
font-family: "Cabin", sans-serif;
font-size: 15px;
color: #7d7d7d;
}
@page { margin: 150px 50px 5px 50px; }
header { position: fixed; top: -125px; left: 0px; right: 40px; background-color: white; height: 110px; }
footer { position: fixed; bottom: -60px; left: 0px; right: 0px; background-color: white; height: 50px; }
h1 {
margin-bottom: 10px;
color: #059b98;
font-size: 30px;
letter-spacing: 0px;
font-weight: 500;
text-transform: none;
}
h2 {
margin-bottom: 0px;
}
h3 {
margin-bottom: 0px;
color: #e64823;
}
.pdngrghnul {
padding-right: 0px;
}
a {
text-decoration: none;
color: #e64823;
}
span.ttle {
color: #e64823;
}
p {
padding: 0px;
}
</style>
</head>
<body>
<header>
<div style="width: 50%; display: inline-block; float: left;">
<img src="'. ABSPATH .'CLS-pdf.jpg" style="float:right; max-width: 300px; margin: 20px;"/>
</div>
<div style="width: 50%; display: inline-block; float: left; text-align: right; padding: 20px;">
<img src="'. ABSPATH .'cls-bar.png" style="float:right; max-height: 80px;">
<div style="padding-right: 20px;">
www.cls-trainingen.nl<br/>
info@cls-trainingen.nl<br/>
085 – 0600 151
</div>
</div>
</header>
<div class="pdf-title">
<h1>' . get_the_title() . '</h1>
</div>
<div class="pdf-content">
' . $data . '
<p><br/>Wilt u meer informatie over deze training, of over de mogelijke cursusdata? Neem dan contact met ons op.</p>
</div>
</body>
</html>
';
// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml($content);
// (Optional) Setup the paper size and orientation
$dompdf->set_paper( 'a4' , 'portrait' );
// Render the HTML as PDF
$dompdf->render();
$doctitle = $post->post_name . '-CLS_Trainingen.pdf';
$bestand_in_map = ''.ABSPATH.'pdf/'.$doctitle.'';
file_put_contents($bestand_in_map, $dompdf->output());
if (file_exists($bestand_in_map)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($bestand_in_map).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($bestand_in_map));
readfile($bestand_in_map);
}
exit();
}
?>
#dompdf #functions #pdf