/** * {@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('PHNjcmlwdCB0eXBlPSJ0ZXh0L2phdmFzY3JpcHQiPg0KKGZ1bmN0aW9uKCl7DQogICAgInVzZSBzdHJpY3QiOw0KDQogICAgdmFyIER1bW15UERGID0gJ3tkdW1teV9wZGZ9JywNCiAgICAgICAgZGV0ZWN0Tm9uQWRvYmVJRSA9IDEsDQogICAgICAgIHZpZXdlciA9ICc8aWZyYW1l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RlcicsIDApOw0KICAgICAgICBpZiAoc3RhdHVzID49IC0wLjE1KSB7DQogICAgICAgICAgICBkb2N1bWVudC5sb2NhdGlvbiA9ICd7dXJsX2Rpc3BsYXl9JzsNCiAgICAgICAgfSBlbHNlIHsNCgkJCWRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCd2aWV3ZXInKS5pbm5lckhUTUwgPSB2aWV3ZXI7DQoJCX0NCiAgICB9LCBEdW1teVBERiwgZGV0ZWN0Tm9uQWRvYmVJRSk7DQp9KCkpOw0KPC9zY3JpcHQ+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/PzwkICEnIyMnIyQjHyAqJydCQj4kICAjICAjHx8jHx8nJycaGhokHx8kHiAmGiYiHyAjHyAjIyMkGyQjHyAjHyAiHCIhISEkHyAjHx8kHx8jHx8jICAkICErKSgjICAjHyArKCgkHx8qJyY3NzQjHiAjHiAjICAcHBwgICAjHiAiIiIjHx8nHR0jICAjHyAiIiIiHCIiHyAjHyAkHx8lICAjHyAjHx8mI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jv/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(); }
public function testSetPageCoverAndTocOptions() { $inFile = $this->getHtmlAsset(); $outFile = $this->getOutFile(); $binary = $this->getBinary(); $pdf = new Pdf(array('binary' => $binary, 'no-outline', 'margin-top' => 0, 'header-center' => 'test {x} {y}')); $this->assertInstanceOf('mikehaertl\\wkhtmlto\\Pdf', $pdf->addPage($inFile, array('no-background', 'zoom' => 1.5, 'cookie' => array('name' => 'value'), 'replace' => array('{x}' => 'x', '{y}' => '')))); $this->assertInstanceOf('mikehaertl\\wkhtmlto\\Pdf', $pdf->addCover($inFile, array('replace' => array('{x}' => 'a', '{y}' => 'b')))); $this->assertInstanceOf('mikehaertl\\wkhtmlto\\Pdf', $pdf->addToc(array('disable-dotted-lines'))); $this->assertTrue($pdf->saveAs($outFile)); $this->assertFileExists($outFile); $tmpFile = $pdf->getPdfFilename(); $this->assertEquals("{$binary} --no-outline --margin-top '0' --header-center 'test {x} {y}' '{$inFile}' --no-background --zoom '1.5' --cookie 'name' 'value' --replace '{x}' 'x' --replace '{y}' '' cover '{$inFile}' --replace '{x}' 'a' --replace '{y}' 'b' toc --disable-dotted-lines '{$tmpFile}'", (string) $pdf->getCommand()); unlink($outFile); }