ProcessWire - RockPdf (Module): Unterschied zwischen den Versionen
Aus Wikizone
(Die Seite wurde neu angelegt: „Modul zum Erzeugen von pdf Dateien. Basiert auf der mpdf Library. == PDF aus HTML Vorlage == Beispiel aus eigener PadLoper Erweiterung <syntaxhighlight lang="…“) |
|||
| Zeile 207: | Zeile 207: | ||
</body> | </body> | ||
</html> | </html> | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | == Weitere Beispiele == | ||
| + | === Aus Modul in Datei schreiben === | ||
| + | Beispiel aus dem Modul EasyOffice (eigenes Modul) | ||
| + | <syntaxhighlight lang="php"> | ||
| + | $filename = $p->invoice_number_external.'.pdf'; | ||
| + | $path = wire()->config->paths->siteModules.'EasyOffice/pdf/'.$filename; | ||
| + | $mpdf->output($path,'F'); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Version vom 5. Februar 2021, 07:56 Uhr
Modul zum Erzeugen von pdf Dateien. Basiert auf der mpdf Library.
PDF aus HTML Vorlage
Beispiel aus eigener PadLoper Erweiterung
// Create HTML
$t = $this->modules->get("PadRender")->getPadTemplate("invoice.php");
$t->set("order", $order);
$html = $t->render();
// Create PDF from HTML
$pdf = $this->modules->get('RockPdf');
$mpdf = $pdf->mpdf;
//$mpdf->Bookmark('RECHNUNG');
$mpdf->WriteHTML($html);
$mpdf->output();
exit();
<?php namespace ProcessWire;
/**
* INVOICE
* we have PadOrder object $order ready to go
*/
if(!$order->invoice_id){
echo("Für diese Bestellung wurde noch keine Rechnungsnummer erstellt. Du kannst unter Verwaltung > Padloper Rechnungen eine Nummer erstellen.");
exit();
}
$configpage = $pages->get("/site_configuration/");
$padRender = $modules->get("PadRender");
$padInvoices = $modules->get("PadInvoices"); //needed for order prefix
$prefix = $padInvoices->getPrefix();
//$padProcess = $modules->get("PadProcess");
// logo
$logo = $configpage->site_brandmark;
$logoUrl = $logo->first()->httpUrl;
//bd($order,'order');
// Customer Data
$customerAddress = '';
$customerAddress .= $order->pad_firstname . " " . $order->pad_lastname.'<br>';
if ($order->pad_address) $customerAddress .= $order->pad_address . "<br>";
if ($order->pad_address_cont) $customerAddress .= $order->pad_address_cont . "<br>";
if ($order->pad_city || $order->pad_postcode) {
if ($order->pad_postcode) $customerAddress .= $order->pad_postcode . " ";
$customerAddress .= $order->pad_city;
}
// Company Data
$companyAddress = nl2br($configpage->company_information);
// Products Table
$t = $padRender->getPadTemplate("order-products-table.php");
$t->set("order", $order);
$productsTable = $t->render();
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta title="Rechnung">
<title><?= __("Invoice") ?></title>
<style>
/* LETTER A4 Styles (oriented at DIN 5008) */
body{
font-family: sans-serif;
font-size: 10pt;
}
div {
box-sizing: border-box;
/*border: 1px solid pink;*/
}
.small {
font-size: 9pt;
}
table{
border-collapse: collapse;
font-size: 10pt;
}
td{
border-top: 1px solid #999;
}
#header{
position: absolute;
top: 0;
left:0;
width: 100%;
text-align: center;
}
#logo{
padding-top:0.7cm;
width: 3cm;
}
#anschrift{
position: absolute;
top: 4.5cm;
left: 2cm;
height: 4.5cm;
width: 8.5cm;
padding-left: 0.5cm;
}
#vermerkzone{
position: absolute;
top: 0;
left: 0;
height: 1.77cm;
width: 8.5cm;
padding-top: 0.5rem;
}
#anschriftzone{
position: absolute;
top: 1.77cm;
left: 0;
width: 8.5cm;
height: 2.73cm;
}
#informationsblock{
font-size: 10pt;
position: absolute;
top: 5cm;
right: 1cm;
width: 7.5cm;
height: auto;
}
#datum{
position: relative;
text-align: right;
padding: 2rem 0 2rem 0;
}
#rechnungsnummer{
position: relative;
text-align: left;
margin-top: 1rem;
}
#textblock{
position: absolute;
top: 10.1cm;
left: 2.5cm;
right: 2cm;
height: auto;
}
#betreff{
position: absolute;
top: 2rem;
}
#text{
position: absolute;
margin-top: 1rem;
}
#rechtstexte{
position: relative;
padding-top: 1rem;
}
#footer{
text-align: center;
font-size: 9pt;
}
</style>
</head>
<body>
<div id="header" class="section">
<img id="logo" src="<?=$logoUrl?>">
</div>
<div id="anschrift">
<div id="vermerkzone" class="small" >
<div style="margin-top: 2rem; border-bottom: 1px solid black; position: relative;">
Oßwald & Schlegel GbR, Uhlandstr.3, 72820 Sonnenbühl
</div>
</div>
<div id="anschriftzone">
<?=$customerAddress?>
</div>
</div>
<div id="informationsblock">
<?=$companyAddress?>
<div id="rechnungsnummer">UStID: DE378376036<br>Rechnungsnummer: <?=$prefix.$order->invoice_id?></div>
</div>
<div id="textblock">
<div id="betreff">
<div id="datum"><?=date('d.m.Y')?></div>
<strong>RECHNUNG</strong>
</div>
<div id="text">
<?=$productsTable?>
<div id="rechtstexte">
Es wird gemäß §19 Abs. 1 Umsatzsteuergesetz keine Umsatzsteuer erhoben (Kleinunternehmerregelung).<br>
Leistungsdatum = Rechnungsdatum
</div>
</div>
</div>
<htmlpagefooter name="InvoiceFooter">
<div id="footer">
<strong>Oßwald & Schlegel GbR | Geschenke vom Lande</strong><br>
Volksbank Ermstal-Alb eG | IBAN: DE09 6409 1200 05 71 2200 02 | BIC: GENODES1MTZ | Kontoinhaber: Stephan Schlegel
</div>
</htmlpagefooter>
<sethtmlpagefooter name="InvoiceFooter" />
</body>
</html>
Weitere Beispiele
Aus Modul in Datei schreiben
Beispiel aus dem Modul EasyOffice (eigenes Modul)
$filename = $p->invoice_number_external.'.pdf';
$path = wire()->config->paths->siteModules.'EasyOffice/pdf/'.$filename;
$mpdf->output($path,'F');