source: Common/Pdf.php

Last change on this file was 14, checked in by chronos, 3 years ago
  • Modified: Updated files to newer version.
File size: 1.4 KB
Line 
1<?php
2
3class Pdf extends Model
4{
5 public bool $Checked = false;
6 public string $BorderTop = '';
7 public string $BorderLeft = '';
8 public string $BorderRight = '';
9 public string $BorderBottom = '';
10 public int $FontSize = 0;
11 public string $OutputFormat = 'pdf';
12 public string $Charset = '8859-2';
13
14 function GenerateHTML(): string
15 {
16 return '';
17 }
18
19 function SaveToFile(string $FileName): void
20 {
21 $PdfData = $this->HtmlToPdf($this->GenerateHTML());
22 file_put_contents($FileName, $PdfData);
23 }
24
25 function HtmlToPdf(string $HtmlCode): string
26 {
27 $Encoding = new Encoding();
28 if ($this->Checked == false) {
29 if (CommandExist('htmldoc')) {
30 $this->Checked = true;
31 } else throw new Exception('htmldoc is not installed.');
32 }
33 $Parameters = '--no-numbered --footer . --webpage --no-embedfonts --charset '.$this->Charset.' -t '.$this->OutputFormat;
34 if ($this->FontSize > 0) $Parameters .= ' --fontsize '.$this->FontSize;
35 if ($this->BorderLeft != '') $Parameters .= ' --left '.$this->BorderLeft;
36 if ($this->BorderTop != '') $Parameters .= ' --top '.$this->BorderTop;
37 if ($this->BorderRight != '') $Parameters .= ' --right '.$this->BorderRight;
38 if ($this->BorderBottom != '') $Parameters .= ' --bottom '.$this->BorderBottom;
39 $Output = shell_exec('echo "'.addslashes($Encoding->FromUTF8($HtmlCode)).
40 '"|htmldoc '.$Parameters.' -');
41 return $Output;
42 }
43}
Note: See TracBrowser for help on using the repository browser.