-1

I'm learning Symfony and EasyAdmin, my next task on the list is to add a button which will print (generate PDF) selected rows from the table. I've checked in the EasyAdmin docs if there maybe is a tutorial or more info, but without luck. https://symfony.com/bundles/EasyAdminBundle/current/crud.html

How I should approach it? Is there a method I should use or a bundle?

I've found this thread: PDF document creation EasyAdmin symfony 5 But no one replied. There is not much info regarding this matter.

Symfony 5.4, EasyAdmin 4

Tim
  • 87
  • 1
  • 8

1 Answers1

1

I think that you should create a customs actions for this.

Let say that you have setup a ProductCrudController class. In that class, you will have to override this :

public function configureActions(Actions $actions): Actions
{
    $viewProductInPDFFormat = Action::new('viewPDF', 'View in PDF', 'fa fa-file-pdf-o')
    ->linkToRoute('name_of_route_that_generate_pdf_on_one_product', 
    function (Product $product): array {
            return [
                'id' => $product->getId(),
            ];
    });

    return $actions
        //will add the action in the page index view
        ->add(Crud::PAGE_INDEX, $viewProductInPDFFormat)
        
        //will add the action in the page detail view
        ->add(Crud::PAGE_DETAIL, $viewProductInPDFFormat)      
    ;
}
glitchcl
  • 318
  • 2
  • 9
  • This is the right solution. Then you will need to configure a subscriber to run the PDF export process. More info here: https://symfony.com/bundles/EasyAdminBundle/current/events.html#event-subscriber-example – Edouard Apr 21 '22 at 15:02