<?php

/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */

namespace Kufer\Webbasys\Includee\Pdf;

include_once_ex('extern/composer/vendor/autoload.php');
use Spipu\Html2Pdf\Html2Pdf;


class KuferWebHtml2Pdf
{
  
  private $pdfContent;
  
  private $myPdf;

  public function __construct($pPdfContent)
  {
    $this->pdfContent = $pPdfContent;
    $this->myPdf = new Html2Pdf('P', 'A4', 'de');
    $this->myPdf->setTestTdInOnePage(false);
  }

  
  public function setParams($pUrlparameter)
  {
    $this->pdfContent->setParams($pUrlparameter);
  }

  
  public function generatePdf()
  {
    $html = '<!doctype html>
          <html>
          <head>
            <meta>
            <title>' . $this->pdfContent->getContentTitle() . '</title>
            <style>' . $this->pdfContent->getStyleInfo() . '
            </style>
          </head>
          <body>'
          . $this->pdfContent->getContent()
          . ' 
            </body>
          </html>';

    $encodeCharset = new \EncodeCharsetFromTo(\CodingOperations::getInternalEncoding(), UTF_8);
    $this->myPdf->writeHTML($encodeCharset->encode($html));
  }

  
  public function sendPdf()
  {
    $this->myPdf->Output($this->pdfContent->getFileName());
  }
}