106 lines
5.2 KiB
PHP
106 lines
5.2 KiB
PHP
<?php
|
|
require(dirname(__FILE__).'/../../classes/My_PDF.php');
|
|
|
|
class ConfiguratorGetPdfModuleFrontController extends ModuleFrontController
|
|
{
|
|
public $token;
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
|
|
$this->controller_name = 'getpdf';
|
|
}
|
|
|
|
public function init()
|
|
{
|
|
parent::init();
|
|
|
|
$this->token = Tools::getValue('token');
|
|
|
|
if (!$this->token)
|
|
{
|
|
$this->redirect_after = '404';
|
|
$this->redirect();
|
|
}
|
|
}
|
|
|
|
public function initContent()
|
|
{
|
|
parent::initContent();
|
|
$q = "SELECT * FROM `" . _DB_PREFIX_ . "config_product` where `token` = '".pSQL($this->token)."'";
|
|
$configproduct = Db::getInstance()->getRow($q);
|
|
$configurator_fields = array();
|
|
$q = "SELECT * FROM `" . _DB_PREFIX_ . "config` where `id_product` = ".(int)$configproduct['id_cart_product'].' AND `id_page` = '.(int)$configproduct['page'];
|
|
$configsIds = Db::getInstance()->executeS($q);
|
|
$fonts = json_decode(file_get_contents(dirname(__FILE__)."/../../fonts.json"), true);
|
|
if($configsIds) {
|
|
foreach ($configsIds as $configId) {
|
|
$print_width = $configId['print_width'];
|
|
$print_height = $configId['print_height'];
|
|
$orientation = 'H';
|
|
// if($configId['print_width'] < $configId['print_height']) {
|
|
// $print_width = $configId['print_height'];
|
|
// $print_height = $configId['print_width'];
|
|
// $orientation = 'H';
|
|
// }
|
|
$q = "SELECT * FROM `" . _DB_PREFIX_ . "config_field_value` where `id_config` = ".$configId['id_config']." AND `id_config_product` = ".$configproduct['id_config_product'];
|
|
$fields = Db::getInstance()->executeS($q);
|
|
$html_first = '<img id="configurator_main_image" src="'.'https://wyczarujprezent.pl'.$configId['image'].'"/>';
|
|
$pdf = new My_PDF($orientation, PDF_UNIT, array($this->getUnitsCount($print_width), $this->getUnitsCount($print_height)), true, 'UTF-8', true);
|
|
$pdf->changeTheDefault(false);
|
|
$pdf->AddPage();
|
|
$pdf->SetMargins(0, 0, 0,true);
|
|
$pdf->writeHTMLCell($this->pixelsToUnits($configId['width']), $this->pixelsToUnits($configId['height']), 0, 0, $html_first);
|
|
|
|
foreach ($fields as $field) {
|
|
$width = (float)(($configId['width']*$field['width'])/100);
|
|
$height = (float)(($configId['height']*$field['height'])/100);
|
|
$x = (float)(($configId['width']*$field['x'])/100);
|
|
$y = (float)(($configId['height']*$field['y'])/100);
|
|
foreach($fonts as $font) {
|
|
if($font['font-family'] === $field['font']) {
|
|
$fontname = TCPDF_FONTS::addTTFfont($font['src'], 'TrueTypeUnicode', '', 96);
|
|
$pdf->SetFont($fontname, '', $this->pixelsToUnits($field['fontsize']), '', false);
|
|
break;
|
|
}
|
|
}
|
|
// die($this->percentToUnits($configId['width'], $width).", ".$this->percentToUnits($configId['height'], $height).", ".$this->percentToUnits($configId['width'], $x).", ".$this->percentToUnits($configId['height'], $y));
|
|
if($field['type'] == 1) {
|
|
$html_first = '<div class="configurator_field" style="line-height: normal;transform: rotate('.$field['rotation'].'deg);'.(isset($field['textalign']) && $field['textalign'] ? ' text-align: '.$field['textalign'].';' : '').' color: '.$field['color'].'; overflow: hidden; font-size: '.$this->pixelsToUnits($field['fontsize']).'mm;">'.$field['text'].'</div>';
|
|
$pdf->writeHTMLCell($this->pixelsToUnits($width), $this->pixelsToUnits($height), $this->pixelsToUnits($x), $this->pixelsToUnits($y), $html_first);
|
|
}
|
|
else {
|
|
$html_first = '<img id="configurator_main_image" src="'.'https://wyczarujprezent.pl'.$field['text'].'" width="'.$this->pixelsToUnits($width).'mm" height="'.$this->pixelsToUnits($height).'mm"/>';
|
|
$pdf->writeHTMLCell($this->pixelsToUnits($width), $this->pixelsToUnits($height), $this->pixelsToUnits($x), $this->pixelsToUnits($y), $html_first);
|
|
}
|
|
}
|
|
$pdf->endPage();
|
|
$pdf->Output('test.pdf', 'I');
|
|
}
|
|
}
|
|
}
|
|
|
|
public function percentToUnits($pixels, $percentage) {
|
|
return (float)(($pixels*($percentage/100)) / 12);
|
|
}
|
|
|
|
public function pixelsToUnits($pixels) {
|
|
return (float)($pixels / 12);
|
|
}
|
|
|
|
public function unitsToPixels($units) {
|
|
return (float)($units * 12);
|
|
}
|
|
|
|
public function getUnitsCount($units) {
|
|
return (float)$this->pixelsToUnits($this->unitsToPixels($units));
|
|
}
|
|
|
|
public function generatePDF($object, $template)
|
|
{
|
|
require_once _PS_MODULE_DIR_ . 'configurator/HTMLTemplateConfigurator.php';
|
|
$pdf = new PDF($object, $template, Context::getContext()->smarty);
|
|
$pdf->render();
|
|
}
|
|
}
|