public function generateTickets($booking, $seatSet, $customer) { $facBuild = \PHPPdf\Core\FacadeBuilder::create(); // WHY CANNOT I JUST new?!?! $fac = $facBuild->build(); $tixPdf = $fac->render($this->getTix($booking, $seatSet, $customer), $this->getTixSheet()); file_put_contents(storage_path() . "/app/tickets-{$booking->id}.pdf", $tixPdf); $booking->ticketsGenerated = 1; $booking->save(); return $tixPdf; }
/** * @return string */ protected function generate() { $content = ''; foreach ($this->views as $view) { $content .= $this->renderTemplate($view, $this->params); } $xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . $this->renderTemplate($this->layout, array('content' => $content)); $loader = new LoaderImpl(); $builder = FacadeBuilder::create($loader); $builder->setEngineOptions(['quality' => 100, 'engine' => 'imagick']); $facade = $builder->build(); $content = $facade->render($xml, $this->renderStyle()); return $content; }
/** * @test * @dataProvider createParameterizeDocumentUsingEngineFromEngineFactoryProvider */ public function createParameterizeDocumentUsingEngineFromEngineFactory($type, $options) { $engineFactory = $this->getMock('PHPPdf\\Core\\Engine\\EngineFactory'); $builder = FacadeBuilder::create(null, $engineFactory); $builder->setEngineType($type)->setEngineOptions($options); $engine = $this->getMock('PHPPdf\\Core\\Engine\\Engine'); $engineFactory->expects($this->once())->method('createEngine')->with($type, $options)->will($this->returnValue($engine)); $facade = $builder->build(); $this->assertInstanceOf(get_class($engine), $facade->getDocument()->getEngine()); }
/** * */ public function pdfartistAction($id) { $id = $this->get('request')->get($this->admin->getIdParameter()); $object = $this->admin->getObject($id); Autoloader::register(); Autoloader::register(__DIR__ . '/../../../../../vendor/PHPPdf/lib/vendor/Zend/library'); Autoloader::register(__DIR__ . '/../../../../../vendor/PHPPdf/lib/vendor/ZendPdf/library'); Autoloader::register(__DIR__ . '/../../../../../vendor/PHPPdf/lib/vendor/Imagine/lib'); $engine = 'pdf'; $facade = FacadeBuilder::create()->setEngineType($engine)->setEngineOptions(array('format' => 'jpg', 'quality' => 70, 'engine' => 'imagick'))->build(); $name = 'artist'; $documentFilename = __DIR__ . '/../Resources/models_xml/' . $name . '.xml'; $stylesheetFilename = __DIR__ . '/../Resources/models_xml/' . $name . '-style.xml'; $testXml = '<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE pdf SYSTEM "%resources%/dtd/doctype.dtd"> <pdf> <dynamic-page> <placeholders> <header> <div height="65px"> <div float="right" color="white" width="270px" padding="8px 0" text-align="center" font-size="16px" font-style="bold" margin-bottom="27px" background.color="black" background.radius="15"> Artist : ' . $object->getLastName() . ' ' . $object->getFirstName() . ' </div> </div> </header> <footer> <div class="footer"> <table> <tr> <td><b></b></td> <td><b></b></td> </tr> </table> </div> </footer> </placeholders> <div> <div class="invoice-data"> <p>Birth Date: ' . date_format($object->getBirthDate(), "d-m-Y") . '</p> <p>Death Date: ' . date_format($object->getDeathDate(), "d-m-Y") . '</p> </div> </div> <table class="invoice"> <tr class="head"> <td width="20">Id</td> <td width="100">Nom</td> <td width="120">Prénom</td> <td>Birth Date</td> <td>Death Date</td> </tr> <tr> <td class="center">' . $object->getId() . '</td> <td class="center">' . $object->getLastName() . '</td> <td class="center">' . $object->getFirstName() . '</td> <td class="center">' . date_format($object->getBirthDate(), "d-m-Y") . '</td> <td class="center">' . date_format($object->getDeathDate(), "d-m-Y") . '</td> </tr> </table> <div width="85%" margin="27px auto"> Fiche artiste auto-générée à la demande de l\'admin. </div> </dynamic-page> </pdf>'; $toto = str_replace('dir:', __DIR__ . '/', file_put_contents($documentFilename, $testXml)); $xml = str_replace('dir:', __DIR__ . '/', file_get_contents($documentFilename)); $stylesheetXml = is_readable($stylesheetFilename) ? str_replace('dir:', __DIR__ . '/', file_get_contents($stylesheetFilename)) : null; $stylesheet = $stylesheetXml ? DataSource::fromString($stylesheetXml) : null; $start = microtime(true); $content = $facade->render($xml, $stylesheet); header('Content-Type: application/pdf'); echo $content; }
/** * 导出 PDF * @author Hanxiang */ public function genPDF() { $input = Input::only('ids'); if (sizeof($input['ids']) == 0) { return response()->json(['result' => 0, 'link' => "", 'msg' => '请选择要导出的设备']); } $snList = Device::findSNsByIds($input['ids']); $count = count($snList); $loader = new LoaderImpl(); $loader->setFontFile(public_path("pdf/style/fonts.xml")); $facade = FacadeBuilder::create($loader)->setEngineType('pdf')->build(); $documentFilename = public_path("pdf/style/table.xml"); $stylesheetFilename = public_path("pdf/style/table-style.xml"); if (!is_readable($documentFilename)) { return response()->json(['result' => 0, 'link' => ""]); } if (!is_readable($stylesheetFilename)) { return response()->json(['result' => 0, 'link' => ""]); } $i = 0; $xml = simplexml_load_file($documentFilename); $table = $xml->xpath('/pdf/dynamic-page/div/table')[0]; $pageCount = (int) ($count / 80) + 1; for ($p = 0; $p < $pageCount; $p++) { $tr = $table->addChild('tr'); $tr['class'] = 'head-foot'; for ($t = 0; $t < 10; $t++) { $td = $tr->addChild('td'); if ($t == 0 or $t == 9) { $td['class'] = "top-left-right"; } else { $td['class'] = "top-bottom"; } } for ($j = 0; $j < 10; $j++) { $tr = $table->addChild('tr'); for ($t = 0; $t < 10; $t++) { $td = $tr->addChild('td'); if ($t == 0 or $t == 9) { $td['class'] = "left-right"; } else { $td['class'] = 'content'; if ($i < $count) { $sn = $snList[$i]; $qrName = public_path() . "/pdf/qr/url_qr_" . $sn . ".png"; QRcode::png(Config::get("app.QR_URL") . '?sn=' . $sn, $qrName, Constants::QR_ECLEVEL_M, 4, 0); $this->fillTd($td, "SN:" . $sn, $qrName); $i++; } else { $div = $td->addChild('div'); $div->addChild('span', ''); } } } } $tr = $table->addChild('tr'); $tr['class'] = 'head-foot'; for ($t = 0; $t < 10; $t++) { $td = $tr->addChild('td'); if ($t == 0 or $t == 9) { $td['class'] = "bottom-left-right"; } else { $td['class'] = "top-bottom"; } } } $newName = "pdf/documents/" . time(); $tableXmlStr = $xml->asXML(); // $stylesheetXml = file_get_contents($stylesheetFilename); // $stylesheet = $stylesheetXml ? \PHPPdf\DataSource\DataSource::fromString($stylesheetXml) : null; $content = $facade->render($tableXmlStr, $stylesheetFilename); $newFilename = $newName . ".pdf"; file_put_contents(public_path($newFilename), $content); return response()->json(['result' => 1, 'link' => url($newFilename)]); }
protected function getPsPdf_FacadeBuilderService() { $this->services['ps_pdf.facade_builder'] = $instance = \PHPPdf\Core\FacadeBuilder::create(new \PHPPdf\Core\Configuration\LoaderImpl(NULL, NULL, NULL, NULL)); $instance->addStringFilter(new \Ps\PdfBundle\PHPPdf\Util\BundleBasedStringFilter($this->get('kernel', ContainerInterface::NULL_ON_INVALID_REFERENCE))); $instance->setCache('File', array('cache_dir' => __DIR__)); $instance->setUseCacheForStylesheetConstraint(true); $instance->setMarkdownStylesheetFilepath(NULL); $instance->setMarkdownDocumentTemplateFilepath(NULL); $instance->setDocumentParserType('xml'); return $instance; }
/** * @return \PHPPdf\Core\Facade */ private function createFacade() { $facade = \PHPPdf\Core\FacadeBuilder::create()->build(); return $facade; }
protected function setUp() { $loader = new \PHPPdf\Core\Configuration\LoaderImpl(); $builder = \PHPPdf\Core\FacadeBuilder::create($loader); $this->facade = $builder->build(); }