Run calc element on demand (TCPDF or any other PHP code)

AlexTCGPro

Member
Hey!
I'm using TCPDF to generate some on-the-fly PDF files.
I have put the PHP code in a calc element to take advantage of the placeholders of other elements and such. When the calc element is set to calc on load, it works perfectly, however, as none of the other elements have been filled yet that data remains blank.

So, I set the code to run whenever a checkbox element gets set, as to manually run the code after the form has been filled, however, it doesn't work, it outputs garbage data.

Could you give me a hand?

Here's the code I'm using
Code:
require_once JPATH_SITE . '/tcpdf/tcpdf.php';
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
    require_once(dirname(__FILE__).'/lang/eng.php');
    $pdf->setLanguageArray($l);
}
$pdf->SetFont('helvetica', '', 9);
if ('{pdf_gen___generate_raw}' == 1) {
$pdf->AddPage();
$content = array();
$content[] = '<html>';
$content[] = 'Test' . '{pdf_gen___input1_raw}';
$content[] = '</html>';
$pdf->writeHTML(implode($content), true, 0, true, 0);
$pdf->lastPage();
ob_end_clean();
$pdf->Output('test.pdf', 'D');
}
That should generate the PDF file when the checkbox is set to 1, however it just outputs garbage data, I'm guessing is not executing the 'ob_end_clean()' command.
Code:
https://pastebin.com/2AbmwtKt
Removing the 'if' and setting the element to calc on load makes the code work, but I want to generate it on demand, not just on load
 
Last edited:
You should not do complicated stuff in calc elements set to "Only run on save"=no (the default). This will run multiple times even on list load.
Better use a php plugin.
 
Thank you, yes I started messing with the php plugin, but is has the same issue, seems to only run correctly when setting it to run before the form loads, anything else gives
Code:
SyntaxError: Unexpected Token in JSON
I'm going to try the whole process with Ajax.
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top