/**
  * {@inheritdoc}
  */
 public function createDocument(array $options = [])
 {
     $document = new PdfDocument();
     $params = $this->params;
     $request = $this->requestStack->getCurrentRequest();
     $document->setOptions($this->getWkHtmlToPdfOptions($request->getUri(), $params['pdf_wkhtmltopdf_bin']));
     $document->outputSelector(function () use($request) {
         return $request->query->get('do');
     });
     $head = $document->element('head');
     $bootstrap = new HtmlElement('link');
     $bootstrap->attr('rel', 'stylesheet');
     $bootstrap->attr('type', 'text/css');
     $bootstrap->attr('href', $request->getSchemeAndHttpHost() . $this->appPaths->url("web") . '/pdf/css/bootstrap.min.css');
     $bootstrap->insertTo($head);
     $style = new HtmlElement('link');
     $style->attr('rel', 'stylesheet');
     $style->attr('type', 'text/css');
     $style->attr('href', $request->getSchemeAndHttpHost() . $this->appPaths->url("web") . '/pdf/css/pdf.css');
     $style->insertTo($head);
     $filename = $this->appPaths->getRootDir() . '/../pdf/' . $request->getPathInfo();
     $dir = dirname($filename);
     if (!is_dir($dir)) {
         mkdir($dir, 0755, true);
     }
     $document->setFilename($filename);
     return $document;
 }
Пример #2
0
 public function testTest()
 {
     $doc = new PdfDocument();
     $doc->title('Sample Page');
     $doc->body(file_get_contents(__DIR__ . '/tmp/pdf.html'));
     $head = $doc->element('head');
     $bootstrap = new HtmlElement('link');
     $bootstrap->attr('rel', 'stylesheet');
     $bootstrap->attr('type', 'text/css');
     $bootstrap->attr('href', 'http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css');
     $bootstrap->insertTo($head);
     $style = new HtmlElement('style');
     $style->text(file_get_contents(__DIR__ . '/tmp/pdf.css'));
     $style->attr('type', 'text/css');
     $style->insertTo($head);
     $now = new DateTime();
     $doc->lastModified($now->format('Y-m-d H:i:s'));
     $doc->setOptions(array('dummy_pdf_url' => 'empty.pdf', 'display_url' => 'test.pdf', 'download_url' => 'test.pdf', 'remote_url' => 'http://www.foo.bar/test.pdf', "pluginDetect_PDFReader_url" => "/pdf/PluginDetect_PDFReader.js", "waiting_view_path" => __DIR__ . '/tmp/waiting-view.html', "queue_db_path" => __DIR__ . '/tmp/pdf-queue.db', "wkhtmltopdf_global" => array("binary" => "wkhtmltopdf")));
     $doc->outputSelector(function () {
         return isset($_GET['do']) ? $_GET['do'] : null;
     });
     $doc->setFilename(__DIR__ . '/tmp/cache/test.pdf');
     $doc->toc(true, __DIR__ . '/tmp/toc.xsl');
     $doc->addCover('start', 'http://www.loremipsum.net');
     $doc->addCover('end', 'http://www.loremipsum.net');
     var_dump($doc->render());
 }