How to "USE DomPDF to create PDF reports rather than TCPDF"? #405
Replies: 5 comments 1 reply
-
|
Hi @pakricard Unfortunately I am doing them by hand, but I think the effort is worthwhile. Basically I convert them to html, but instead of echoing them straight to the browser I store it in a variable - I use $HTML just for consistency. Then to convert them to a PDF I just run: This method has the advantage that if I want to output to a spreadsheet as well I can just run: (To output as an Excel file just change ods and Ods to xls and Xls) and obviously to display it in the browser just run: So the report logic is only written once, regardless of the output format required. They are fairly easy to change, just a bit laborious to actually do. The first one I did as a proof of concept was ReorderLevel.php and I tend to use that as my template. Thanks |
Beta Was this translation helpful? Give feedback.
-
|
Thanks, @timschofield Both with Claude 3.7 and Gemini 2.5. The results are great. Only minor touch-ups needed. It really speeds up the coding time. Thanks, |
Beta Was this translation helpful? Give feedback.
-
|
Thanks Ricard. I hadn't used any of the AI coding assistants, but I have
just tried it with your suggestions, and the results look good
…On Wed, 30 Apr 2025 at 03:05, pakricard ***@***.***> wrote:
Thanks, @timschofield <https://github.com/timschofield>
As I am developing with VS Code, I tried this prompt
Modify this script to use DomPDF instead of TCPDF.
To create the HTML Code, use the variable $HTML.
the DomPDF should be loaded via Composer with this line:
require_once 'vendor/autoload.php'; // Ensure DomPDF is loaded via Composer
Use the variables $_POST['PrintPDF'], to ask the user if he wants to download/print the PDF, download an ODS file or just view the data on the screen
If user has selected $_POST['PrintPDF'] use code similar to:
$dompdf = new Dompdf(['chroot' => __DIR__]);
$dompdf->loadHtml($HTML);
// (Optional) Setup the paper size and orientation
$dompdf->setPaper($_SESSION['PageSize'], 'landscape');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$dompdf->stream($_SESSION['DatabaseName'] . '_NameOfReport_' . date('Y-m-d') . '.pdf', array(
"Attachment" => false
));
If user has selected $_POST['PrintPDF'] use code similar to:
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
$File = 'NameOfReport-' . Date('Y-m-d') . '.' . 'ods';
header('Content-Disposition: attachment;filename="' . $File . '"');
header('Cache-Control: max-age=0');
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Html();
$spreadsheet = $reader->loadFromString($HTML);
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Ods');
$writer->save('php://output');
If user has selected $_POST['View'] use code similar to:
$Title = _('NameOfReport');
include ('includes/header.php');
echo '<p class="page_title_text"><img src="' . $RootPath . '/css/' . $Theme . '/images/maintenance.png" title="' . _('Search') . '" alt="" />' . ' ' . $Title . '</p>';
echo $HTML;
include ('includes/footer.php');
Use FixedAssetRegister.php as example and proof of concept.
Both with Claude 3.7 and Gemini 2.5. The results are great. Only minor
touch-ups needed. It really speeds up the coding time.
Thanks,
R
—
Reply to this email directly, view it on GitHub
<#405 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAL6LBFK2XVBTPPRIJC5G324A4Y3AVCNFSM6AAAAAB37V2NHKVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTEOJYG43DONI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
--
www.weberp.org
@TimSchofield.or.uk - bsky.app
Blog: https://kwamoja.home.blog/
|
Beta Was this translation helpful? Give feedback.
-
|
I'm just trying to understand.... You guys are guru level! :-) Is there a mistake in the 2nd option? Instead of:
should it read: Also, could this approach (using Gemini...) save effort to create a new report? Cheers, |
Beta Was this translation helpful? Give feedback.
-
|
I think you're right Dale. Good spot! I think there are certain aspects of writing a report such as the SQL, that the AI would struggle with, though Ricard is more experienced at this so he may know better. Tim |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi @timschofield:
I have around 10 custom PDF reports with TCPDF and would like to convert to DomPDF.
Do you have a prompt that you feed to your IDE to convert them that you could share? Or what strategy are you using?
Thanks,
R
Beta Was this translation helpful? Give feedback.
All reactions