/**
  * Generates the pdf with Snappy
  *
  * @param string $content
  * @param string $path
  *
  * @return string
  */
 protected function doPdf($content, $path, $io)
 {
     $snappy = new Pdf();
     //@TODO: catch exception if binary path doesn't exist!
     $snappy->setBinary($this->wkhtmltopdfPath);
     $snappy->setOption('orientation', "Landscape");
     $snappy->generateFromHtml($content, "/" . $path . 'dc-cheatsheet.pdf');
     $io->success("cheatsheet generated at /" . $path . "/dc-cheatsheet.pdf");
     // command execution ends here
 }
Example #2
0
<?php

require_once 'vendor/knplabs/knp-snappy/src/autoload.php';
use Knp\Snappy\Pdf;
$snappy = new Pdf('/usr/local/bin/wkhtmltopdf');
$snappy->setOption('disable-javascript', true);
$snappy->setOption('disable-local-file-access', true);
$snappy->setOption('orientation', 'Landscape');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="My NUSMods.com Timetable.pdf"');
echo $snappy->getOutputFromHtml(urldecode($_POST['html']));
Example #3
0
 public function setOption($name, $value)
 {
     $this->snappy->setOption($name, $value);
     return $this;
 }
Example #4
0
use Knp\Snappy\Pdf;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Seld\JsonLint\JsonParser;
use Symfony\Component\PropertyAccess\PropertyAccess;
//Request::setTrustedProxies(array('127.0.0.1'));
$app->post('/', function (Request $request) use($app) {
    $parser = new JsonParser();
    $accessor = PropertyAccess::createPropertyAccessor();
    $snappy = new Pdf();
    $snappy->setBinary($app['wkhtmltopdf.binary']);
    $parameters = $parser->parse($request->getContent());
    if ($accessor->isReadable($parameters, 'options')) {
        foreach ((array) $accessor->getValue($parameters, 'options') as $name => $value) {
            $snappy->setOption($name, $value);
        }
    }
    $app['tmpFile'] = sys_get_temp_dir() . '/' . md5($request->getContent());
    if ($accessor->isReadable($parameters, 'source.url')) {
        $dns = new Net_DNS2_Resolver();
        $dns->query(parse_url($accessor->getValue($parameters, 'source.url'), PHP_URL_HOST));
        $snappy->generate($accessor->getValue($parameters, 'source.url'), $app['tmpFile'], [], true);
    } elseif ($accessor->isReadable($parameters, 'source.html')) {
        $snappy->generateFromHtml($accessor->getValue($parameters, 'source.html'), $app['tmpFile'], [], true);
    } elseif ($accessor->isReadable($parameters, 'source.base64')) {
        $snappy->generateFromHtml(base64_decode($accessor->getValue($parameters, 'source.base64')), $app['tmpFile'], [], true);
    }
    return new BinaryFileResponse($app['tmpFile']);
})->bind('api');
$app->finish(function () use($app) {
Example #5
0
<?php

require_once realpath(dirname(__FILE__) . '/../vendor/autoload.php');
use Knp\Snappy\Pdf;
$parsedUrl = parse_url($_GET['url']);
$url = $_GET['url'];
if ($parsedUrl != false) {
    // add http if needed
    if (!isset($parsedUrl['scheme'])) {
        $url = 'http://' . $_GET['url'];
    }
    $snappy = new Pdf('xvfb-run -s \'-screen 0 1100x1024x16\' -a wkhtmltopdf');
    $snappy->setOption('lowquality', false);
    $snappy->setOption('disable-javascript', true);
    $snappy->setOption('disable-smart-shrinking', false);
    $snappy->setOption('print-media-type', true);
    checkSnappyparams($snappy);
    // Display the resulting pdf in the browser
    // by setting the Content-type header to pdf
    header('Content-Type: application/pdf');
    // Download file instead of viewing it in the browser
    if (isset($_GET['ddl'])) {
        $filename = empty($_GET['ddl']) ? 'file' : $_GET['ddl'];
        header('Content-Disposition: attachment; filename="' . $filename . '.pdf"');
    }
    // Convert pdf in CMYK colorspace
    // Need GhostScript
    // Need a writeable temporary directory for php process
    if (filter_input(INPUT_GET, 'cmyk', FILTER_VALIDATE_BOOLEAN)) {
        $tmpRGBFileName = tempnam(sys_get_temp_dir(), 'pdf-rgb');
        $tmpCMYKFileName = tempnam(sys_get_temp_dir(), 'pdf-cmyk');
Example #6
0
include_once $root . '/vendor/autoload.php';
include_once $errors . 'errorProcessing.php';
$pageUrl = urlencode("https://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}");
//validate the user before sending the print operation. This ensures that no
//call to print page can be executed without user session enabled
printValidation($site_prefix, $pageUrl);
use Knp\Snappy\Pdf;
//Pay attention to the path statement to executable -- escape 'spaces with slashes
//Note: When installing the executable make not to install outside of Program Files directory
//The try catch Exception block may not catch anything thrown as the KNLabs-SNAPPY
// classes throw minimal set of Exception
//TODO route exception thrown to site Error page
try {
    $log->debug("printPage.php - set exe location and options");
    $snappy = new Pdf('C://"Program Files/"/wkhtmltopdf/bin/wkhtmltopdf.exe');
    $snappy->setOption('page-size', 'A3');
    $snappy->setOption('disable-external-links', true);
} catch (Exception $e) {
    $log->error("printPage.php - New PDF Class Exception: " . $e->getMessage());
}
if (isset($_POST['url'])) {
    $urlIn = urldecode($_POST['url']);
    $url = setPrintEncryptionUrl($urlIn);
    $log->debug("Use Post to get URL: " . $url);
    header('Content-Type: application/pdf');
    header('Cache-Control: public, must-revalidate, max-age=0');
    // HTTP/1.1
    header('Pragma: public');
    header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
    // Date in the past
    header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
Example #7
0
 /**
  * @param $orderUid
  * @return string
  * @throws \Exception
  */
 protected function generatePdfReceipt($orderUid)
 {
     $snappy = new Pdf($this->pixie->config->get('parameters.wkhtmltopdf_path'));
     //$snappy->setOption('cookie', $_COOKIE);
     $snappy->setOption('viewport-size', '800x600');
     $snappy->setOption('toc', false);
     $snappy->setOption('outline', false);
     $snappy->setOption('outline-depth', 0);
     $url = ($_SERVER['HTTPS'] == 'on' ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/payment/request_bill/' . $orderUid . '?print=1' . '&code=' . $this->generatePrintCode($orderUid);
     return $snappy->getOutput($url);
 }
Example #8
0
 private function creerdevispdf($id)
 {
     $em = $this->getDoctrine()->getManager();
     $devis = $em->getRepository('AcmeProsalesBundle:Devis')->find($id);
     $parametrepaiement = $em->getRepository('AcmeProsalesBundle:Parametres')->findOneBy(array('nom' => 'paiement'));
     $nomfichier = "Devis_" . $devis->getReference() . '.pdf';
     //        $nomfichier = "Devis".$id.'.pdf';
     $outputfile = $this->getUploadRootDir() . '/' . $nomfichier;
     if (!$devis) {
         throw $this->createNotFoundException('Impossible de trouver le devis recherché.');
     }
     $html = $this->renderView('AcmeProsalesBundle:Devis:imprimer.html.twig', array('entity' => $devis, 'paiement' => $parametrepaiement));
     if (file_exists($outputfile)) {
         unlink($outputfile);
     }
     //        $this->get('knp_snappy.pdf')->generateFromHtml($html,$outputfile);
     //        return $outputfile;
     $snappy = new Pdf($this->getWebDir() . '../vendor/h4cc/wkhtmltopdf-i386/bin/wkhtmltopdf-i386');
     //        $snappy->setOption('disable-javascript', true);
     $snappy->setOption('outline', true);
     $snappy->setOption('background', true);
     //        $snappy->setOption('margin-top', '15mm');
     //        $snappy->setOption('margin-bottom', '15mm');
     //        $snappy->setOption('header-center', 'ceci et l\'entête');
     $snappy->setOption('header-right', '[page]/[toPage]');
     $snappy->setOption('header-left', '[date]');
     $snappy->setOption('header-line', true);
     //$snappy->setOption('header-font-size', '18');
     $snappy->setOption('footer-center', '20 Allée des Erables Bat D- Bp64162 - 95978 Roissy CDG Cedex  FRANCE<br>Info@progiss.com - www.progiss.com - Tel 01 49 89 07 90 - Fax 01 49 89 07 91<br>SAS au capital de 43750 Euros  - Siret :49901977600024 R.C.S Bobigny N° TVA : FR43499019776');
     //        $snappy->setOption('footer-right', '[page]/[toPage]');
     $snappy->setOption('footer-line', true);
     //        $snappy->setOption('no-footer-line', true);
     $snappy->setOption('footer-font-size', '6');
     //$snappy->setOption('no-background', true);
     //$snappy->setOption('allow', array('/path1', '/path2'));
     //$snappy->setOption('cookie', array('key' => 'value', 'key2' => 'value2'));
     $snappy->generateFromHtml($html, $outputfile);
     return $outputfile;
 }
Example #9
0
 public function makeFromUri(Request $request)
 {
     // post値の取得
     $data = $request->all();
     $address = $data['address'];
     //$headers = array(
     //"HTTP/1.0",
     //"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
     //"Accept-Encoding:gzip ,deflate",
     //"Accept-Language:ja,en-us;q=0.7,en;q=0.3",
     //"Connection:keep-alive",
     //"User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:26.0) Gecko/20100101 Firefox/26.0"
     //);
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $address);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     //curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     $html = curl_exec($ch);
     curl_close($ch);
     // リンクの置換処理
     $url = parse_url($address);
     $protocol = "{$url['scheme']}://";
     $hostName = "{$protocol}{$url['host']}/";
     //var_dump($protocol);
     //var_dump($hostName);
     // リンクの置換(="/),(="//)
     //$html = preg_replace('{="//}', "=\"{$protocol}", $html);
     //$html = preg_replace('{="/}', "=\"{$hostName}", $html);
     // PDFの作成
     $snappy = new Pdf('/usr/local/bin/wkhtmltopdf');
     $snappy->setOption('disable-javascript', true);
     // filename
     $pdfName = date("YmdHis") . ".pdf";
     //$snappy->generateFromHtml($html, storage_path(). "/app/pdf/$pdfName");
     $snappy->generate($address, storage_path() . "/app/pdf/{$pdfName}");
     // htmlをpdfに変換
     return response()->json(array("name" => $pdfName));
 }
Example #10
-1
 /**
  * {@inheritDoc}
  */
 public function generate($path, $html)
 {
     $ext = pathinfo($path, PATHINFO_EXTENSION);
     if (null === $ext) {
         $path .= ".ext";
     } elseif ("pdf" !== $ext) {
         throw new InvalidArgumentException(sprintf("Your destination path must have a .pdf extension for conversion, '%s' passed.", $ext));
     }
     $pdf = new Pdf();
     $pdf->setBinary($this->_getBinDir() . 'wkhtmltopdf-' . $this->_getBinaryType());
     foreach ($this->_options as $key => $value) {
         $pdf->setOption($key, $value);
     }
     if (is_file($path)) {
         unlink($path);
     }
     // Strip out `@font-face{ ... }` style tags as these break the pdf
     $html = preg_replace('/@font-face{([^}]*)}/ms', '', $html);
     $pdf->generateFromHTML($html, $path);
     return new File($path);
 }