trinion_tp-1.0.x-dev/src/Controller/PDFPoluchenniyPlatezh.php

src/Controller/PDFPoluchenniyPlatezh.php
<?php

namespace Drupal\trinion_tp\Controller;

use Dompdf\Dompdf;
use Drupal\Core\Controller\ControllerBase;
use Drupal\node\Entity\Node;

/**
 * PDF Полученный платеж
 */
class PDFPoluchenniyPlatezh extends ControllerBase {

  /**
   * Builds the response.
   */
  public function build(Node $node) {
    $build['content'] = [
      '#theme' => 'poluchennyy_platezh_pdf',
      "#node" => $node,
      "#root_path" => \Drupal::service('file_system')->realpath(''),
    ];
    $html = \Drupal::service('renderer')->render($build);
    $dompdf = new Dompdf();
    $dompdf->loadHtml($html);
    $options = $dompdf->getOptions();
    $options->set('chroot', DRUPAL_ROOT);
    $dompdf->setOptions($options);

    $dompdf->render();

    $dompdf->stream("poluchennyy-platezh.pdf", ["Attachment" => false]);
    return ['#cache' => ['max-age' => 0]];
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc