PHP code example of roadiz / abstract-pdf-theme

1. Go to this page and download the library: Download roadiz/abstract-pdf-theme library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

roadiz / abstract-pdf-theme example snippets


# AppKernel.php
/**
 * {@inheritdoc}
 */
public function register(\Pimple\Container $container)
{
    parent::register($container);

    /*
     * Add your own service providers.
     */
    $container->register(new \Themes\AbstractPdfTheme\Services\PdfServiceProvider());
}


namespace Themes\MyTheme\Controllers;

use Themes\AbstractPdfTheme\Controllers\PdfControllerTrait;
use Themes\MyTheme\MyThemeThemeApp;
use RZ\Roadiz\Core\Entities\Node;
use RZ\Roadiz\Core\Entities\Translation;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class PageController extends MyThemeThemeApp
{
    use PdfControllerTrait;
    
    /**
     * @param Request $request
     * @param Node|null $node
     * @param Translation|null $translation
     * @return Response
     */
    public function indexAction(
        Request $request,
        Node $node = null,
        Translation $translation = null
    ) {
        $this->prepareThemeAssignation($node, $translation);

        if ($request->query->has('_format') && $request->query->get('_format') == 'pdf') {
            return $this->generatePdf($request, $this->nodeSource);
        }

        $response = $this->render('pages/page.html.twig', $this->assignation);

        return $response;
    }

    protected function getPdfTemplate()
    {
        return 'pdf/page.xml.twig';
    }
}