This exceeds my knowledge about PHP, but I’m going to throw some ideas anyway.
Backup your files, and then start using the following base:
<?php
namespace modules;
use \lib\core\Module;
require_once __DIR__ . '/../../../vendor/autoload.php';
class HtmlToPDF extends Module
{
use TCPDF;
public $backgroundImage = "";
public function Header() {
// $this refers to this class called "HtmlToPdf"
// $pdf refers to class TCPDF
// https://tcpdf.org/examples/example_001/
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$bMargin = $pdf->getBreakMargin();
$auto_page_break = $pdf->AutoPageBreak;
$pdf->SetAutoPageBreak(false, 0);
//$img_file = __DIR__.'/../../../assets/certificados/plantillas/CertificadoAsistenciaCITEDIS-I.png';
$img_file = $this->backgroundImage; // ConvertToPDF($options, $name) needs to be called first (by Wappler), so $this->backgroundImage is populated
$pdf->Image($img_file, 0, 0, 297, 210, '', '', '', false, 300, '', false, false, 0);
$pdf->SetAutoPageBreak($auto_page_break, $bMargin);
$pdf->setPageMark();
}
public function ConvertToPDF($options, $name)
{
$pageHeight = $this->app->parseObject($options->pageHeight);
$pageWidth = $this->app->parseObject($options->pageWidth);
$fileName = $this->app->parseObject($options->fileName);
$folderName = $this->app->parseObject($options->folderName);
// I need to call this:
$backgroundImage = $this->app->parseObject($options->backgroundImage);
$this->backgroundImage = $backgroundImage; // Put $backgroundImage in class variable $this->backgroundImage
// FILL IN CONTENTS FROM THE REST OF THE ORIGINAL FILE
I got rid of class MYPDF extends TCPDF
, because I’m not really sure how you would end up calling that within Wappler. I have moved your function Header() to inside class HtmlToPDF, so there you could have access to $backgroundImage after calling ConvertToPDF.
You have to realize you still can’t call Header() from Wappler. It would need to be like:
public function Header($options, $name)
And you would need to edit the .hjson to add the ability for Wappler to call that function.
Or just put all your custom code inside function ConvertToPDF? Maybe easiest option if you don’t need the original function