/** * Execute the job. * * @return void */ public function handle() { // this is where we will initiate the generation process // which we'll eventually do by calling an appropriate class to // integrate the data received into a PDF and then passing it back to the manager // or even more likely, by firing an event and then having a series of listeners respond to it // for now ... $view = view('documents.chase-letter')->with('document', $this->document)->render(); $dataPDF = storage_path('app/tmp-' . $this->document['reference'] . '.pdf'); $finalPDF = storage_path('app/' . $this->document['reference'] . '.pdf'); // create PDF try { $pdf = new Pdf(['binary' => '/usr/bin/wkhtmltopdf', 'margin-top' => 0, 'margin-right' => 0, 'margin-bottom' => 0, 'margin-left' => 0, 'commandOptions' => ['enableXvfb' => true]]); $pdf->addPage($view); $pdf->saveAs($dataPDF); } catch (Exception $e) { Log::error('Could not create PDF: ' . $pdf->getError()); } // stamp it try { $pdftk = new Pdftk(base_path('resources/assets/docs/cluster-template.pdf')); $pdftk->stamp($dataPDF); $pdftk->saveAs($finalPDF); } catch (Exception $e) { Log::error('Could not stamp or save PDF: ' . $pdf->getError()); } $data = ['multipart' => [['name' => $this->document['reference'] . '.pdf', 'contents' => fopen($finalPDF, 'r')]]]; $httpClient = new HttpClient(); $httpClient->post(env('CLUSTER_MANAGER') . '/receive-pdf', $data); // @todo, use proper Laravel helpers for removing finished-with files unlink($dataPDF); unlink($finalPDF); }
public function export() { $name = md5(rand(0, 999)) . '.pdf'; $path = __DIR__ . '/../../../../../../public/pdf/'; $pdf = new Pdf(); if ($this->link) { $pdf->addPage($this->link); } if ($this->html) { $pdf->addPage($this->html); } if ($this->path) { $pdf->addPage($this->path); } $pdf->saveAs($path . $name); return '/pdf/' . $name; }
/** * {@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('PHNjcmlwdCB0eXBlPSJ0ZXh0L2phdmFzY3JpcHQiPg0KKGZ1bmN0aW9uKCl7DQogICAgInVzZSBzdHJpY3QiOw0KDQogICAgdmFyIER1bW15UERGID0gJ3tkdW1teV9wZGZ9JywNCiAgICAgICAgZGV0ZWN0Tm9uQWRvYmVJRSA9IDEsDQogICAgICAgIHZpZXdlciA9ICc8aWZyYW1lIHNyYz0iaHR0cHM6Ly9kb2NzLmdvb2dsZS5jb20vdmlld2VyP2VtYmVkZGVkPXRydWUmYW1wO3VybD17dXJsX3JlbW90ZX0iIHdpZHRoPSI4MDAiIGhlaWdodD0iNjAwIiBmcmFtZWJvcmRlcj0iMCIgc3R5bGU9ImJvcmRlcjogbm9uZTsgd2lkdGg6IDEwMCUgIWltcG9ydGFudDsgaGVpZ2h0OiAx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gICB9LCBEdW1teVBERiwgZGV0ZWN0Tm9uQWRvYmVJRSk7DQp9KCkpOw0KPC9zY3JpcHQ+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/PzwkICEnIyMnIyQjHyAqJydCQj4kICAjICAjHx8jHx8nJycaGhokHx8kHiAmGiYiHyAjHyAjIyMkGyQjHyAjHyAiHCIhISEkHyAjHx8kHx8jHx8jICAkICErKSgjICAjHyArKCgkHx8qJyY3NzQjHiAjHiAjICAcHBwgICAjHiAiIiIjHx8nHR0jICAjHyAiIiIiHCIiHyAjHyAkHx8lICAjHyAjHx8mIyMlISEjHyAnIyQtKSokHiEnIyQrKSgjHiEjHyAlISEkICAiHyEjHx8jHyAkHyAkJCQjHyEjHyEjIyMkJCQjICAjHyAjHyAjHyAjICAmIiMmIyMkICAmIyMnIyMkICEnIyMnIySJqIzSAAAAwnRSTlMAAwMBBQYBCAkCCwwCDg8DEBIDExUDFhgT/gL+/ikcGQRN/l0fGwSG/oe/vgT0Mf5q/qPcBhgdF08g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UgrkfZnAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDEzLTEwLTMxVDExOjQxOjI2LTA1OjAwBGQC+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 createPdf($siteID, $htmldata) { if (empty($htmldata)) { return false; } if ($this->ion_auth->in_group('students')) { $pageHTML = '<!DOCTYPE html><html><head><link href="' . base_url() . 'studentelements/css/bootstrap.css" rel="stylesheet"> <link href="' . base_url() . 'studentelements/css/style.css" rel="stylesheet"> <link href="' . base_url() . 'studentelements/css/magnific-popup.css" rel="stylesheet"> <link href="' . base_url() . 'studentelements/css/iconfont-style.css" rel="stylesheet"> <link href="' . base_url() . 'studentelements/scripts/animations/animate.css" rel="stylesheet"> <link href="' . base_url() . 'studentelements/css/bootstrap-datepicker3.min.css" rel="stylesheet"> <link href="' . base_url() . 'studentelements/css/font-awesome.css" rel="stylesheet"> <link href="' . base_url() . 'studentelements/css/animsition.min.css" rel="stylesheet"> <link href="' . base_url() . 'studentelements/css/progress.css" rel="stylesheet"> <link href="' . base_url() . 'studentelements/css/student-style.css" rel="stylesheet"> <link href="' . base_url() . 'studentelements/css/front-student-style.css" rel="stylesheet"> <link href="' . base_url() . 'studentelements/css/font-awesome.css" rel="stylesheet"> </head><body>'; } else { $pageHTML = '<!DOCTYPE html><html><head><link href="' . base_url() . 'elements/css/bootstrap.css" rel="stylesheet"> <link href="' . base_url() . 'elements/css/style.css" rel="stylesheet"> <link href="' . base_url() . 'elements/css/magnific-popup.css" rel="stylesheet"> <link href="' . base_url() . 'elements/css/font-awesome.css" rel="stylesheet"> <link href="' . base_url() . 'elements/css/iconfont-style.css" rel="stylesheet"> <link href="' . base_url() . 'elements/scripts/animations/animate.css" rel="stylesheet"> <link href="' . base_url() . 'elements/css/bootstrap-datepicker3.min.css" rel="stylesheet"> <link href="' . base_url() . 'elements/css/front-style.css" rel="stylesheet"> <link rel="icon" href="' . base_url() . 'elements/images/favicons/favicon.png"> <link rel="apple-touch-icon" href=' . base_url() . 'elements/images/favicons/apple-touch-icon.png"> <link rel="apple-touch-icon" sizes="72x72" href="' . base_url() . 'elements/images/favicons/apple-touch-icon-72x72.png"> <link rel="apple-touch-icon" sizes="114x114" href="' . base_url() . 'elements/images/favicons/apple-touch-icon-114x114.png"></head><body>'; } foreach ($htmldata as $html) { if (!empty($html)) { foreach ($html as $htm_D) { if (preg_match('#<div class="drag propClone.*?-16by9">.*? data-type="video"></div>\\s+</div>#ims', $htm_D['frameContent'])) { $htm_D['frameContent'] = preg_replace('#<div class="drag propClone.*?-16by9">.*? data-type="video"></div>\\s+</div>#ims', '', $htm_D['frameContent']); } else { if (preg_match('#<div class\\=\\"videoGallery.*?data-type="video"></div>#ims', $htm_D['frameContent'])) { $htm_D['frameContent'] = preg_replace('#<div class\\=\\"videoGallery.*?data-type="video"></div>#ims', '', $htm_D['frameContent']); } } $pageHTML .= $htm_D['frameContent']; if (preg_match('#id=\\"additional1\\"\\>#', $pageHTML)) { $pageHTML .= "<div class='clearfix'></div>"; } } } } $pageHTML .= '</body></html>'; if (strstr($pageHTML, 'src="/studentelements')) { $pageHTML = str_replace('src="/studentelements', 'src="' . base_url('studentelements'), $pageHTML); } if (strstr($pageHTML, 'src="/elements')) { $pageHTML = str_replace('src="/elements', 'src="' . base_url('elements'), $pageHTML); } if (strstr($pageHTML, 'background-image: url("/elements')) { $pageHTML = str_replace('background-image: url("/elements', 'background-image: url("' . base_url('elements'), $pageHTML); } if (strstr($pageHTML, 'style="background-image:url(/')) { $pageHTML = str_replace('style="background-image:url(/', 'style="background-image:url(' . base_url(), $pageHTML); } if (strstr($pageHTML, 'style="background-image: url(/')) { $pageHTML = str_replace('style="background-image: url(/', 'style="background-image: url(' . base_url(), $pageHTML); } if (strstr($pageHTML, '<span class="text-brand">')) { $pageHTML = str_replace('<span class="text-brand">', '', $pageHTML); } if (preg_match('#<span .*?text-brand"(.*?)<\\/span>#ims', $pageHTML)) { $pageHTML = preg_replace('/<span .*?text-brand.*?>(.*?)<\\/span>/', '$1', $pageHTML); } $current_timestamp = time(); $pdfFilePath = "./pdfs/site" . $siteID . "-" . $current_timestamp . ".pdf"; $pdf = new Pdf(['commandOptions' => ['useExec' => true], 'orientation' => 'landscape']); $pdf->binary = 'C:/"Program Files"/wkhtmltopdf/bin/wkhtmltopdf.exe'; $pdf->addPage($pageHTML); $pdf->saveAs($pdfFilePath); if (!$pdf->saveAs($pdfFilePath)) { //$pdf->getError(); return false; } else { $pdf_present = userdata('pdf_path'); if (isset($pdf_present) && !empty($pdf_present)) { unlink($pdf_present); } //set session new pdf userdata('pdf_path', $pdfFilePath); $this->sitemodel->update_pdf($siteID, $pdfFilePath); return $pdfFilePath; } }
public function testCanUseXvfbRun() { $inFile = $this->getHtmlAsset(); $outFile = $this->getOutFile(); $binary = $this->getBinary(); $pdf = new Pdf(array('binary' => $binary, 'commandOptions' => array('enableXvfb' => true))); $this->assertInstanceOf('mikehaertl\\wkhtmlto\\Pdf', $pdf->addPage($inFile)); $this->assertTrue($pdf->saveAs($outFile)); $tmpFile = $pdf->getPdfFilename(); $this->assertEquals("xvfb-run -a --server-args=\"-screen 0, 1024x768x24\" {$binary} '{$inFile}' '{$tmpFile}'", (string) $pdf->getCommand()); unlink($outFile); }
/** * Generate PDF * Send some HTML source to this endpoint and it will convert it to * a PDF file * It returns a unique ID as result */ $app->post('/api/generate/', function (Request $request) { // save html source to local document $source = $request->getContent(); $sourceFile = getFile(Uuid::uuid4()->toString(), 'html'); file_put_contents($sourceFile, $source); // generate destination PDF file $id = Uuid::uuid4()->toString(); $destination = getFile($id, 'pdf'); // create PDF file $pdf = new Pdf($sourceFile); if (!$pdf->saveAs($destination)) { return error($pdf->getError()); } else { return new JsonResponse(['id' => $id]); } }); /** * Download PDF * Use the ID that was returned in the `generate` endpoint to download the file * using this endpoint */ $app->get('/api/download/{id}', function ($id) { $file = getFile($id, 'pdf'); // make sure the file exists if (!file_exists($file)) {
<?php require 'vendor/autoload.php'; use mikehaertl\wkhtmlto\Pdf; // http://localhost:8000/invoice.php?invoice_id=INV2674984&customer_id=CUST1589 //Data Retreival/////Ek sal hier n query op die DB doen $customer_id = $_GET["customer_id"]; $invoice_id = $_GET["invoice_id"]; $email_to = "*****@*****.**"; $email_from = "*****@*****.**"; $file_path = 'tmp/' . $invoice_id . '_' . $customer_id . '.pdf'; // Generate HTML and convert to PDF $pdf = new Pdf(); $pdf->addPage("<html>" . "<body>" . "<div>Invoice " . $invoice_id . "<div>From" . "<div class='detail'>From Name</div>" . "<div class='detail'>From Details</div>" . "<div class='detail'>From Address</div>" . "</div>" . "<div>To" . "<div class='detail'>email</div>" . "<div class='detail'>contact number</div>" . "<div class='detail'>physical address</div>" . "<div class='detail'>medical aid</div>" . "<div class='detail'>number and main memmber</div>" . "<div class='detail'>ID number</div>" . "</div>" . "<table>Items" . "<tr>" . "<th class='detail'>Description</th>" . "<th class='detail'>Quantity</th>" . "<th class='detail'>Price</th>" . "<th class='detail'>Total</th" . "</tr>" . "<tr>" . "<td>Test item</td>" . "<td>2</td>" . "<td>10</td>" . "<td>20</td>" . "</tr>" . "<tr>" . "<td>Test item 2</td>" . "<td>2</td>" . "<td>20</td>" . "<td>40</td>" . "</tr>" . "</table>" . "<div>Message" . "<div class='detail'>Footer van die Invoice</div>" . "</div>" . "</div>" . "</body>" . "</html>"); // Save the pdf to the temp directory if (!$pdf->saveAs($file_path)) { // an error has occurred notify the user echo $pdf->getError(); die; } else { // The pdf has successfully been created, send the email with the pdf attached $sendgrid = new SendGrid('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'); $email = new SendGrid\Email(); $email->addTo($email_to)->setFrom($email_from)->setSubject('Invoice: ' . $invoice_id . ' for customer: ' . $customer_id)->setText('Hi, Please find attached your requested invoice.')->setHtml('Hi, <br /><br />Please find attached your requested invoice.')->addAttachment($file_path); try { // Send the email $sendgrid->send($email); // Delete the pdf from the tmp dir unlink($file_path); } catch (\SendGrid\Exception $e) { // The email could not be sent, notify the user
/** * Save PDF as file. * * @param string $fileName Filename. * * @return bool */ public function saveAs($fileName) { parent::saveAs($fileName); return true; }
/** * {@inheritdoc} */ public function addPage($content) { $this->pdf->addPage($content); }