Form to PDF

Has anyone created a form to pdf method before I start? Idea is to allow downloading a PDF of the form's data. i.e. for paper or document management systems.
8 Replies
toeknee
toekneeOP5mo ago
Thanks I know how to generate PDF's, it's more if anyone has built a method for generating the page for printing/pdf.
Matthew
Matthew4w ago
Hi @toeknee Did you progress with this? Looking for a solution to convert a completed form/page, into a stored PDF.
toeknee
toekneeOP4w ago
Not really I built a custom quick render
Matthew
Matthew4w ago
Ahh..ok. Is that easily done, can you point me somewhere ?
toeknee
toekneeOP3w ago
Sorry, I just used DomPDF and did it on an action, rendering a blade. i.e.
$filepath = 'pdfs/my_view';
$filename = $record->name . '_' .now() . '.pdf';
$pdf = Pdf::loadView('pdf.my_view', [
'record' => $record,
]);
$pdf->render();
$canvas = $pdf->getDomPDF()->getCanvas();
$canvas->page_script(function ($pageNumber, $pageCount, $canvas, $fontMetrics) {
// Text to display
$text = "Page $pageNumber of $pageCount";
// Margins from the bottom right
$marginRight = 10;
$marginBottom = 20;
// Font and font size
$fontSize = 10;
$font = $fontMetrics->getFont('Helvetica');
// Set position
$textWidth = $fontMetrics->getTextWidth($text, $font, $fontSize);
$xPosition = $canvas->get_width() - $textWidth - $marginRight;
$yPosition = $canvas->get_height() - $marginBottom;
// Draw text
$canvas->text($xPosition, $yPosition, $text, $font, $fontSize);
});

$pdf->save(
$filepath.$filename, 's3'
);
return response()->streamDownload(function () use ($file) {
echo $file;
}, $filename);
$filepath = 'pdfs/my_view';
$filename = $record->name . '_' .now() . '.pdf';
$pdf = Pdf::loadView('pdf.my_view', [
'record' => $record,
]);
$pdf->render();
$canvas = $pdf->getDomPDF()->getCanvas();
$canvas->page_script(function ($pageNumber, $pageCount, $canvas, $fontMetrics) {
// Text to display
$text = "Page $pageNumber of $pageCount";
// Margins from the bottom right
$marginRight = 10;
$marginBottom = 20;
// Font and font size
$fontSize = 10;
$font = $fontMetrics->getFont('Helvetica');
// Set position
$textWidth = $fontMetrics->getTextWidth($text, $font, $fontSize);
$xPosition = $canvas->get_width() - $textWidth - $marginRight;
$yPosition = $canvas->get_height() - $marginBottom;
// Draw text
$canvas->text($xPosition, $yPosition, $text, $font, $fontSize);
});

$pdf->save(
$filepath.$filename, 's3'
);
return response()->streamDownload(function () use ($file) {
echo $file;
}, $filename);
SoraKeyheart
SoraKeyheart3w ago
I use Typeset.sh
Matthew
Matthew3w ago
@toeknee Thanks for supplying this. It is similar to what I am doing, but I have an issue with the extensive CSS from filament and the other locations not being available. Other than creating the css and making them statically available (not keen), have you found a way around that ? @SoraKeyheart , does Typeset.sh go anyway to solve the CSS issue?
Want results from more Discord servers?
Add your server