PDF Generation Too Slow
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 11.2k
- Forks
- 1.8k
- PR merge metrics
- No merged PRs in 30d
Description
Hello everyone.
Maybe I'm doing something wrong, but I'm generating a PDF based on a blade view in Laravel 10. It's a very simple view with only two images, not very large. The problem is that the generation process takes more than 20 seconds. If I remove the images, the generation is instantaneous.
The PDF is generated and saved to disk. As I mentioned, if I do it without the images, it generates it instantly; if I add the images, it takes more than 20 seconds to generate. Am I doing something wrong? Is there any way to speed up this process?
This is my generation code.
$data = [
'documento' => $documento,
'documentoPasos' => $documentoPasos,
'documentoPasoUsuarios' => $documentoPasoUsuarios,
'documentoArchivos' => $documentoArchivos
];
// Generar el PDF con el tamaño y orientación correctos
$options = new \Dompdf\Options();
$options->set('isHtml5ParserEnabled', true);
$options->set('isRemoteEnabled', true); // Permitir imágenes externas
$options->set('defaultFont', 'Arial'); // Establecer la fuente
$options->set('defaultPaperSize', 'letter');
$pdf = new \Dompdf\Dompdf($options);
$pdf->setPaper('letter', 'portrait');
$pdf->loadHtml(view('operacion.documento.documento_auditoria_show', $data)->render());
$pdf->render();
// Grabo el PDF en disco temporalmente para firmarlo
Storage::disk('local')->put('temp/documento_temporal_' . $documento->id . '.pdf', $pdf->output());
Thanks.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generation code and the Blade view at operacion.documento.documento_auditoria_show, reproducing the PDF with and without the two images. Inspect the Dompdf options, especially remote image loading, and compare where the extra time is spent. Done means identifying the cause of the image-related delay and documenting a verified way to reduce it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- laravel, php
- Domain
- backend, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100