Save custom template as PDF on server side

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
josejad
User
Posts: 109
Location: Spain

Save custom template as PDF on server side

Post by josejad »

Hi all,

I have a custom template, and when I export it clicking on the PDF Export button I get what I want.
I need the server send this file to an email address after OnEdit action.
I've seen in a post I can modify the Export() function to get the file saved on server. I've done this, so when I press the export to PDF button, I get my file on my server.
But I can't find the way of saving it automatically after some event.
I see the "export to PDF" button, call a javascript funcion onclick=ew_Export(document.fvdf_kpiview,'vdf_kpiview.php?export=pdf&id=1&custom=1','pdf',true);
I've tried to call from php with no success.
Then I've tried to call the export function before Page_Terminate() event, like this:

$vdf_kpi_view->Export = "pdf";
$vdf_kpi_view->ExportData();

I get the file saved on my server, but no the custom template.
How could I do this?

Thanks in advance


mobhar
User
Posts: 11660

Post by mobhar »

Please note that "Custom Template" does NOT support Export to CSV/HTML/PHPExcel/PHPWord/XML (the data is exported in original tabular format).

If you want to export your data in custom layout, then you should use "Custom Files" and third party PHP library to generate the content to PDF file.

Read "Custom Files" topic from PHPMaker Help menu for more info.


josejad
User
Posts: 109
Location: Spain

Post by josejad »

You're right, I've read it, but when I've seen if I access
mypage.php?export=pdf&id=2&custom=1
I get the right file on my server, I thougth I could do something like:
1) update my record
2) redirect the page to mypage.php?export=pdf&id=2&custom=1 and get the file on the server, then redirect again to my page
3) get the file to pass to SendEmailOnEdit

Trying with the javascript way, I've added

<script type="text/javascript">
ew_Export(document.fvdf_kpiview,'mypage.php?export=pdf&id=2&custom=1','pdf',true);
</script>

at the end of my file, then I get a blank pdf file on my server. Why if I call this function I get a blank page, but if I press the export to pdf button I get the rigth file?

Thanks again


mobhar
User
Posts: 11660

Post by mobhar »

josejad wrote:
Why if I call this function I get a blank page, but if I press the export to pdf
button I get the rigth file?

Because there are another additional code/functions that related to the export functionality in the script files that generated by PHPMaker. That's why when you use that function for your Custom File (you did not handle the logic as well as the files that generated by PHPMaker based on the table object in database), the result will be different between one and another.


josejad
User
Posts: 109
Location: Spain

Post by josejad »

Thanks again.
Finally, this is the way I'm doing it.

A file (createPDF.php for example) with the code:

<?php
$DompdfAutoloader = new \Dompdf\Autoloader();
$DompdfAutoloader->register();
function CreatePdf() {
ob_start();
?>
...
THE HTML I WANT, actually, the same of my custom template
...
$html = ob_get_clean();
$dompdf1 = $dompdf = new \Dompdf\Dompdf(array("pdf_backend" => "Cpdf"));
$dompdf1->set_paper("A4","portrait");
$dompdf1->load_html($html);
$dompdf1->render();
$output = $dompdf1->output();
$filename = 'uploads/'.date("YmdHis").'.pdf';
file_put_contents(trim($tday), $output);
ew_DeleteTmpImages();
return $filename;

}
?>

Then I include my file:
<?php include_once "createPDF.php" ?>

and I call the function before sending the email.

Thanks for everything¡¡


Post Reply