/**
  * Create and return the Html2Pdf view strategy
  *
  * Retrieves the ViewHtml2PdfRenderer service from the service locator, and
  * injects it into the constructor for the Html2Pdf strategy.
  *
  * It then attaches the strategy to the View service, at a priority of 100.
  *
  * @param  ServiceLocatorInterface $serviceLocator
  * @return JsonStrategy
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $html2pdfRenderer = new Html2PdfRenderer();
     $html2pdfRenderer->setViewRenderer($serviceLocator->get('ViewManager')->getRenderer());
     $html2pdfStrategy = new Html2PdfStrategy($html2pdfRenderer);
     return $html2pdfStrategy;
 }
 public function testPassingValidHtmlToRenderAsString()
 {
     $model = new Html2PdfModel();
     $model->setTemplate('template00.phtml');
     $model->setDest('S');
     $this->renderer->resolver()->addPath('./test/_templates');
     $pdfContentAsString = $this->renderer->render($model);
     $this->assertStringStartsWith('%PDF', $pdfContentAsString);
 }
 /**
  * Create an object
  *
  * @param  ContainerInterface $container
  * @param  string             $requestedName
  * @param  null|array         $options
  * @return Html2PdfStrategy
  * @throws ServiceNotFoundException if unable to resolve the service.
  * @throws ServiceNotCreatedException if an exception is raised when
  *     creating a service.
  * @throws ContainerException if any other error occurs
  */
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     $config = $container->get('Config');
     $html2pdfOptions = isset($config['zff-html2pdf']['options']) ? $config['zff-html2pdf']['options'] : [];
     $html2pdfRenderer = new Html2PdfRenderer();
     $html2pdfRenderer->setViewRenderer($container->get('ViewRenderer'));
     $html2pdfRenderer->setDefaultHtml2pdfOptions($html2pdfOptions);
     $html2pdfStrategy = new Html2PdfStrategy($html2pdfRenderer);
     return $html2pdfStrategy;
 }
 public function testMergeConstructorOptionsFromModel()
 {
     $model = new Html2PdfModel();
     $model->setDest('S');
     $model->setTemplate('template00.phtml');
     $model->setHtml2PdfOptions(['orientation' => 'L', 'format' => 'A3', 'lang' => 'pt', 'encoding' => 'ISO-8859-1', 'margins' => [5, 10, 20, 30]]);
     $this->renderer->resolver()->addPath('./test/_templates');
     $this->renderer->render($model);
     $html2pdfObject = $model->getVariable('html2pdf');
     $this->assertNotNull($html2pdfObject);
     $this->assertAttributeEquals('L', '_orientation', $html2pdfObject);
     $this->assertAttributeEquals('A3', '_format', $html2pdfObject);
     $this->assertAttributeEquals('pt', '_langue', $html2pdfObject);
     $this->assertAttributeEquals(true, '_unicode', $html2pdfObject);
     $this->assertAttributeEquals('ISO-8859-1', '_encoding', $html2pdfObject);
 }