/**
  * {@inheritdoc }
  */
 public function render()
 {
     $this->optionsTest();
     $exists = file_exists($this->filename);
     $pdfDate = new \DateTime();
     $pdfDate->setTimestamp($exists ? filemtime($this->filename) : 0);
     // generowanie pliku jeśli nie ma lub jest przestarzały
     if (!$exists || $this->lastModified() > $pdfDate) {
         $html = parent::render();
         if (isset($this->covers['start'])) {
             $this->wkhtmltopdf->addCover($this->covers['start']['url'], $this->covers['start']['options']);
         }
         if ($this->useToc) {
             $this->wkhtmltopdf->addToc($this->options['wkhtmltopdf_toc']);
         }
         $this->wkhtmltopdf->addPage($html, $this->options['wkhtmltopdf_page']);
         if (isset($this->covers['end'])) {
             $this->wkhtmltopdf->addCover($this->covers['end']['url'], $this->covers['end']['options']);
         }
         if (!$this->wkhtmltopdf->saveAs($this->filename)) {
             //throw new \Exception('Could not create PDF: ' . $this->wkhtmltopdf->getError());
             file_put_contents($this->getFilenameToHtml(), $html);
             $this->queue->beginTransaction();
             if ($this->queue->select($this->getFilename()) == false) {
                 $this->queue->insert($this->getFilename(), array('date_added' => time(), 'block' => 0, 'html_file' => $this->getFilenameToHtml()));
             }
             $this->queue->endTransaction();
             return $this->waitingView();
         }
     }
     switch (call_user_func($this->outputSelector)) {
         case 'download':
             $this->download();
             return '';
         case 'display':
             $this->display();
             return '';
     }
     $viewer = new HtmlDocument();
     $viewer->name($this->name());
     $viewer->title($this->title(), HtmlDocument::TITLE_ONLY_TITLE);
     $viewer->author($this->author());
     $viewer->authorUrl($this->authorUrl());
     $viewer->keywords($this->keywords());
     $viewer->description($this->description());
     $pdfDetect = str_replace(array('{dummy_pdf}', '{url_download}', '{url_display}', '{url_remote}'), array($this->options['dummy_pdf_url'], $this->options['download_url'], $this->options['display_url'], $this->options['remote_url']), base64_decode('PHNjcmlwdCB0eXBlPSJ0ZXh0L2phdmFzY3JpcHQiPg0KKGZ1bmN0aW9uKCl7DQogICAgInVzZSBzdHJpY3QiOw0KDQogICAgdmFyIER1bW15UERGID0gJ3tkdW1teV9wZ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yJywgZnVuY3Rpb24gKCQkKSB7DQogICAgICAgIHZhciBzdGF0dXMgPSAkJC5pc01pblZlcnNpb24oJ1BERlJlYWRlcicsIDApOw0KICAgICAgICBpZiAoc3RhdHVzID49IC0wLjE1KSB7DQogICAgICAgICAgICBkb2N1bWVudC5sb2NhdGlvbiA9ICd7dXJsX2Rpc3BsYXl9JzsNCiAgICAgICAgfSBlbHNlIHsNCgkJCWRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCd2aWV3ZXInKS5pbm5lckhUTUwgPSB2aWV3ZXI7DQoJCX0NCiAgICB9LCBEdW1teVBERiwgZGV0ZWN0Tm9uQWRvYmVJRSk7DQp9KCkpOw0KPC9zY3JpcHQ+CQ=='));
     $viewer->body('<body><div id="viewer"><p style="text-align: center;"><a href="' . $this->options['download_url'] . '" title="Download PDF"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAACZFBMVEUAAABEREBEREBEREBEREBEREBEREBEREBEREBEREBEREBEREBEREBEREBEREBEREBEREBEREBEREBEREBEREBEREBEREBEREAoGxsjHyAAAAAjICAmIyM0NDJEREBEREBEREAkHiEmIyMrKCpEREBEREBEREAiHiAnIyQkICIjHyAjHyBAAEAiHyAkHx8nIyMkHx8kICEiHx8jHyAvLywgICBAQDwhISEkICBAQD0kHSEkICAkHiAiHiAzMzMjHyA7OzkjHh4vLCsjHyErKCklICEqJSYmIyQnJCQzMzElJSQtKikjHx8qJiYjHx8oJSQjHx9AQD0nIyQjHyArKysuKy0hISEkHyEiHiAjHyAjHiAjHyAjHyAmHBwiHx8jHyEjHyAkICEkJCQjHyAnIyQ+PjslICAvLSsiICArKCcjICAoJSQjHiAkICEAAAAmIiMrKyk/Pzs/PzwkICEnIyMnIyQjHyAqJydCQj4kICAjICAjHx8jHx8nJycaGhokHx8kHiAmGiYiHyAjHyAjIyMkGyQjHyAjHyAiHCIhISEkHyAjHx8kHx8jHx8jICAkICErKSgjICAjHyArKCgkHx8q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5FzrnhKMvtue/ZO3vKVid8OVX2vDXd9oJXx37P/7Ya513wtffWJi/700eTji1fyH+/uV8nPCtGXP+2+/wcsJ33zPjv/8BPyf88KNW/sef8HTCTz+j+Z9/wdcJv/yK5H+9hbcTfvMtzv/ue+59wnrth+bkH6E9Ngf6hErtJ/1NpJ8Zeqe2+4So9ss+NHP6V5bere0+ofp6xW+CsPt3pt6x7T6hNv7486+/2XrXTj07/udfxt750rPjpWfHS8+Ol54dL+Jnx2332DlTmzXdYyI09h12vhZfnPsu3d536va+W7f3Hbu979rtfecu7bv/D4Py4UgrkfZnAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDEzLTEwLTMxVDExOjQxOjI2LTA1OjAwBGQC+wAAACV0RVh0ZGF0ZTptb2RpZnkAMjAxMy0xMC0zMVQxMTo0MToyNi0wNTowMHU5ukcAAAAASUVORK5CYII=" width="128" height="128" alt="click here to download" /></a></p></div>
     <noscript><meta http-equiv="Refresh" content="0; url=' . $this->options['download_url'] . '" /></noscript>' . $pdfDetect . '</body>');
     $head = $viewer->element('head');
     $script = new HtmlElement('script');
     $script->attr('type', 'text/javascript');
     $script->attr('src', $this->options['pluginDetect_PDFReader_url']);
     $script->insertTo($head);
     $style = new HtmlElement('style');
     $style->text('body {margin: 0; padding: 0; overflow: hidden;}');
     $style->attr('type', 'text/css');
     $style->insertTo($head);
     $link = new HtmlElement('link');
     $link->attr('href', $this->options['download_url'])->attr('rel', 'alternate')->attr('type', 'application/pdf')->attr('title', $this->title())->attr('media', 'print')->insertTo($head);
     return $viewer->render();
 }
 /**
  * Tworzenie loadera zasobów
  * 
  * @param HtmlDocument $doc
  * @param string $type
  * @param FileLocator $locator
  * @param string $baseurl
  * @param bool $combine
  * @param bool $async
  * 
  * @return JavaScriptResourcesLoader|StyleSheetResourcesLoader
  * 
  * @throws \UnexpectedValueException
  */
 public function createResourcesLoader(HtmlDocument $doc, $type, FileLocator $locator, $baseurl, $combine = true, $async = true)
 {
     $allowed = array('javascript', 'stylesheet');
     if (!in_array($type, $allowed)) {
         throw new \UnexpectedValueException($type . 'is unexpected');
     }
     $manager = $doc->resources($type);
     $loaderOptions = array('baseurl' => $baseurl, 'combine' => $combine, 'async' => $async, 'resources' => $manager, 'cache_dir' => $this->options['cache_dir'], 'cache_refresh' => $this->options['cache_refresh']);
     switch ($type) {
         case 'javascript':
             $loader = new JavaScriptResourcesLoader($locator, $loaderOptions);
             break;
         case 'stylesheet':
             $loader = new StyleSheetResourcesLoader($locator, $loaderOptions);
             break;
     }
     return $loader;
 }
 /**
  * {@inheritdoc}
  */
 public function createDocument(array $options = [])
 {
     $document = new HtmlDocument();
     // used by Modernizr
     $document->element('html')->addClass('no-js');
     // meta viewport
     $viewport = $this->params["meta_viewport"];
     if (!empty($viewport)) {
         $meta = $document->element('viewport');
         $meta->attr('content', $viewport);
     }
     // favicon
     $favicon = $document->element('favicon');
     $favicon->enable($this->params["favicon_enable"]);
     $favicon->setBasePath($this->appPaths->url('web_theme') . '/favicons');
     $favicon->setTileColor($this->params["favicon_tile_color"]);
     if (file_exists($this->appPaths->absolute('web_theme') . '/favicons/favicon.html')) {
         $favicon->setFaviconTemplate(file_get_contents($this->appPaths->absolute('web_theme') . '/favicons/favicon.html'));
     }
     // html lang
     $document->element('html')->attr('lang', $this->requestStack->getCurrentRequest()->getLocale());
     // resources
     $utility = $this->getUtility($this->params);
     $utility->createResOnAdd($document, "javascript", "default");
     $utility->createResOnAdd($document, "stylesheet", "default");
     $document->resources("javascript")->chooseOnAdd("default");
     $document->resources("stylesheet")->chooseOnAdd("default");
     $configDir = $this->appPaths->getRootDir() . '/document';
     if (file_exists($configDir . '/' . $this->theme->getName())) {
         $configDir .= '/' . $this->theme->getName();
     }
     $locator = new FileLocator($configDir);
     $loader = $utility->createResourcesLoader($document, 'javascript', $locator, '/');
     $loader->load('html_resources.yml', 'framework');
     $loader->load('html_resources.yml', 'core');
     $locator = new FileLocator($this->appPaths->absolute('private_theme'));
     $loader = $utility->createResourcesLoader($document, 'stylesheet', $locator, $this->appPaths->getThemePath() . '/src');
     $loader->load('html_resources.yml', 'theme');
     $loader = $utility->createResourcesLoader($document, 'javascript', $locator, $this->appPaths->getThemePath() . '/src');
     $loader->load('html_resources.yml', 'theme');
     // js initializer
     $jsloader = $this->getJsLoader();
     $script = $document->element('script');
     $twig = $this->twig;
     $env = $this->env;
     $document->setScriptOutput(function (JavaScriptResourceManager $manager, array $translations) use($jsloader, $script, $twig, $env) {
         $output = $jsloader->render('html');
         if ($env === 'dev') {
             foreach ($jsloader->resources() as $resource) {
                 if ($resource instanceof CombineResourceInterface && $resource->getCombineObject()->getException() instanceof \Exception) {
                     throw $resource->getCombineObject()->getException();
                 }
             }
         }
         $output .= $twig->render('::head.html.twig', ["resources" => $manager->render('array'), "translations" => $translations]);
         if (!$script->isEmpty()) {
             $output .= '<script type="text/javascript">' . $script->render() . '</script>';
             $script->update(function () {
                 return '';
             });
         }
         return $output;
     });
     // translations used in theme
     if (file_exists($this->appPaths->absolute("kernel_root") . '/theme/' . $this->appPaths->getThemeName() . '/translations.yml')) {
         $trans = $this->translator;
         $locator = new FileLocator($this->appPaths->absolute("kernel_root") . '/theme/' . $this->appPaths->getThemeName());
         $loader = new TranslationLoader($locator, ['cache_dir' => $this->appPaths->absolute("kernel_cache") . "/vsymfo_document/translations", 'cache_refresh' => $this->env == "dev", 'document' => $document, 'trans_closure' => function ($text) use($trans) {
             return $trans->trans($text);
         }]);
         $loader->load('translations.yml');
     }
     return $document;
 }