Example #1
1
 public function uploadHtmlFile(Request $request)
 {
     $file = $request->file('file');
     $html = file_get_contents($file->getPathName());
     // PDFの作成
     $snappy = new Pdf('/usr/local/bin/wkhtmltopdf');
     // filename
     $pdfName = pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME) . "_" . date("YmdHis") . ".pdf";
     $snappy->generateFromHtml($html, storage_path() . "/app/pdf/{$pdfName}");
     return response()->json(array("name" => $pdfName));
 }
 public function rootAction(Application $app, Request $request)
 {
     $data = $this->prepareInput();
     if ($data === null) {
         return new JsonResponse(['error' => 'no json data found'], 400);
     }
     $templateName = isset($data['template']) ? $data['template'] : null;
     $templateData = isset($data['data']) ? $data['data'] : null;
     if (!$templateName || !$templateData) {
         return new JsonResponse(['error' => 'template and data must be set'], 400);
     }
     $repo = $app->getTemplateRepository();
     $template = $repo->getByName($templateName);
     if (!$template) {
         return new JsonResponse(['error' => "template {$templateName} not found"], 404);
     }
     $twig = new \Twig_Environment(new \Twig_Loader_String());
     $html = $twig->render($template->getTemplate(), $templateData);
     $file = new File();
     $file->setId(Uuid::uuid4()->toString());
     $file->setCreatedAt(date('Y-m-d H:i:s'));
     $file->setPath($this->getFilePath($file));
     $snappy = new Pdf();
     if (substr(php_uname(), 0, 7) == "Windows") {
         $snappy->setBinary('vendor\\bin\\wkhtmltopdf.exe.bat');
     } else {
         $snappy->setBinary('vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64');
     }
     $snappy->generateFromHtml($html, $file->getPath());
     $repo = $app->getFileRepository();
     $repo->add($file);
     return new JsonResponse(['id' => $file->getId()], 201);
 }
Example #3
0
 /**
  * Save the PDF to a file
  *
  * @param $filename
  * @return static
  */
 public function save($filename)
 {
     if ($this->html) {
         $this->snappy->generateFromHtml($this->html, $filename, $this->options);
     } elseif ($this->file) {
         $this->snappy->generate($this->file, $filename, $this->options);
     }
     return $this;
 }
 public function test()
 {
     $bin = BASE_PATH . 'vendor/bin/wkhtmltopdf-amd64';
     // Display the resulting pdf in the browser
     // by setting the Content-type header to pdf
     $snappy = new Pdf();
     $snappy->setBinary($bin);
     $snappy->generateFromHtml('<h1>Bill</h1><p>You owe me money, dude.</p>', BASE_PATH . 'storage/bill-123.pdf');
 }
Example #5
0
 public function doGetIt(SS_HTTPRequest $request)
 {
     // var_dump($request->params());
     global $baseDir;
     $result = $this->getMovieList()->byId($request->param('ID'));
     printf($result->ID);
     $filePath = $baseDir . '/pdfs/movie-' . $result->ID . '.pdf';
     $pdf_creator = new Pdf($baseDir . '\\vendor\\bin\\wkhtmltopdf');
     return $pdf_creator->generateFromHtml($result->renderWith('SingleMovie'), $filePath, array('disable-javascript' => false), true);
 }
 /**
  * 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 #7
0
<?php

require '../autoloader.php';
use OpenBoleto\Banco\Bradesco;
use OpenBoleto\Agente;
use Knp\Snappy\Pdf;
$sacado = new Agente('Fernando Maia', '023.434.234-34', 'ABC 302 Bloco N', '72000-000', 'Brasília', 'DF');
$cedente = new Agente('Empresa de cosméticos LTDA', '02.123.123/0001-11', 'CLS 403 Lj 23', '71000-000', 'Brasília', 'DF');
$boleto = new Bradesco(array('dataVencimento' => new DateTime('2013-01-24'), 'valor' => 23.0, 'sequencial' => 75896452, 'sacado' => $sacado, 'cedente' => $cedente, 'agencia' => 1172, 'carteira' => 6, 'conta' => 0403005, 'contaDv' => 2, 'agenciaDv' => 1, 'descricaoDemonstrativo' => array('Compra de materiais cosméticos', 'Compra de alicate'), 'instrucoes' => array('Após o dia 30/11 cobrar 2% de mora e 1% de juros ao dia.', 'Não receber após o vencimento.')));
$conteudo = $boleto->getOutput();
$lib = getcwd() . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'wkhtmltopdf.exe';
$snappy = new Pdf($lib);
$snappy->generateFromHtml($conteudo, 'nome.pdf');
Example #8
0
 public function saveDocument($data)
 {
     $this->load->helper('file');
     $docNameNew = uniqid('', true);
     $docName = $docNameNew . '.php';
     //add slashes to file path
     $path = addslashes(FCPATH);
     $header = '<?php include("' . $path . $this->config->item('dataDir') . 'includes/header.php"); ?>';
     $footer = '<?php include("' . $path . $this->config->item('dataDir') . 'includes/footer.php"); ?>';
     if (!write_file($this->config->item('dataDir') . $docName, $header, 'w')) {
         $msg = array('status' => 'error', 'msg' => 'There was an error writing the new document to a file.');
         echo json_encode($msg);
         exit;
     }
     foreach ($data['modules'] as $module) {
         $modData = new Module_Model($module);
         $location = $modData->getLocation();
         $cat = $modData->getCategory();
         //make sure we can load the module data successfully before creating a bogus file
         if ($location != '' && $cat != '') {
             $innerHtml = '<?php include("' . $path . $this->config->item('moduleDir') . $cat . '/files/' . $location . '") ?>';
             if (!write_file($this->config->item('dataDir') . $docName, $innerHtml, 'a')) {
                 $msg = array('status' => 'error', 'msg' => 'There was an error writing the new document to a file.');
                 echo json_encode($msg);
                 exit;
             }
         } else {
             $msg = array('status' => 'error', 'msg' => 'There was an error loading the modules location and category information.');
             echo json_encode($msg);
             exit;
         }
     }
     if (!write_file($this->config->item('dataDir') . $docName, $footer, 'a')) {
         $msg = array('status' => 'error', 'msg' => 'There was an error writing the new document to a file.');
         echo json_encode($msg);
         exit;
     }
     $pdf = new Pdf($this->config->item('pdf_binary'));
     $image = new Image($this->config->item('image_binary'));
     $options = array('format' => 'jpg', 'user-style-sheet' => FCPATH . 'assets/css/bootstrap.css', 'load-error-handling' => 'skip');
     $html = $this->load->file(FCPATH . $this->config->item('dataDir') . $docName, true);
     $newImage = $this->config->item('dataDir') . 'thumbnails/' . $docNameNew . '.jpg';
     $image->generateFromHtml($html, $newImage, $options, true);
     $fileName = str_replace(' ', '-', strtolower($data['fileName']));
     $newPdf = $this->config->item('dataDir') . 'pdf/' . $docNameNew . '.pdf';
     $options = array('viewport-size' => '1250', 'load-error-handling' => 'skip');
     $pdf->generateFromHtml($html, $newPdf, $options, true);
     $config['source_image'] = $newImage;
     $config['maintain_ratio'] = true;
     $config['height'] = 200;
     $this->load->library('image_lib', $config);
     $this->image_lib->resize();
     if (isset($data['department']) && $data['department'] !== '') {
         $department = $data['department'];
     } else {
         $department = $this->session->department;
     }
     $modules = array();
     foreach ($data['modules'] as $module) {
         $modules[] = array('id' => $module);
     }
     $document = array('category' => $data['category'], 'owner' => $this->session->id, 'realname' => $fileName . '.php', 'created' => date('Y-m-d H:i:s'), 'description' => $data['description'], 'status' => 0, 'department' => $department, 'publishable' => 0, 'location' => $docName, 'modules' => json_encode($modules));
     $this->db->insert('documents', $document);
     $fileId = $this->db->insert_id();
     $data = array('fid' => $fileId, 'dept_id' => $department, 'rights' => 1);
     $this->db->insert('dept_perms', $data);
     $data = array('fid' => $fileId, 'uid' => $this->session->id, 'rights' => 4);
     $this->db->insert('user_perms', $data);
     $data = array('id' => $fileId, 'modified_on' => date('Y-m-d H:i:s'), 'modified_by' => $this->session->username, 'note' => 'Initial Import', 'revision' => 'current');
     $this->db->insert('log', $data);
     $msg = array('status' => 'success', 'msg' => 'We successfully created the new document, and inserted the data into the database.');
     echo json_encode($msg);
 }
 public function taskToPDF(Request $request, Task $task)
 {
     //        $binary = base_path().'/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64';
     $binary = '/usr/bin/xvfb-run /usr/bin/wkhtmltopdf';
     $snappy = new Pdf($binary);
     //$html = file_get_contents('http://www.google.com');
     $pdf = base_path() . '/storage/app/pdfs/task_id' . $task->id . '.pdf';
     $snappy->generateFromHtml('<h1>' . $task->name . '</h1><p>' . $task->user->name . '</p>', $pdf, array(), true);
     return response()->download($pdf, 'task.pdf', ['Content-Type' => 'application/pdf']);
     // or you can do it in two steps
     //        $snappy = new Pdf();
     //        $snappy->setBinary($binary);
     //// Display the resulting pdf in the browser
     //// by setting the Content-type header to pdf
     //        //$snappy = new Pdf($binary);
     //        header('Content-Type: application/pdf');
     //        header('Content-Disposition: attachment; filename="file.pdf"');
     //        echo $snappy->getOutput('http://www.github.com');
     //
     //// Merge multiple urls into one pdf
     //// by sending an array of urls to getOutput()
     //        $snappy = new Pdf($binary);
     //        header('Content-Type: application/pdf');
     //        header('Content-Disposition: attachment; filename="file.pdf"');
     //        echo $snappy->getOutput(array('http://www.github.com','http://www.knplabs.com','http://www.php.net'));
     //
     //// .. or simply save the PDF to a file
     //        $snappy = new Pdf($binary);
     //        $snappy->generateFromHtml('<h1>Bill</h1><p>You owe me money, dude.</p>', base_path().'/resources/bill-123.pdf');
     //        return response();
     //
     //// Pass options to snappy
     //// Type wkhtmltopdf -H to see the list of options
     //        $snappy = new Pdf($binary);
     //        $snappy->setOption('disable-javascript', true);
     //        $snappy->setOption('no-background', true);
     //        $snappy->setOption('allow', array('/path1', '/path2'));
     //        $snappy->setOption('cookie', array('key' => 'value', 'key2' => 'value2'));
     //        $snappy->setOption('cover', 'pathToCover.html');
     //// .. or pass a cover as html
     //        $snappy->setOption('cover', '<h1>Bill cover</h1>');
     //        $snappy->setOption('toc', true);
     //        $snappy->setOption('cache-dir', '/path/to/cache/dir');
 }
Example #10
0
 public function uploadMdFile(Request $request)
 {
     $file = $request->file('file');
     $mdText = file_get_contents($file->getPathName());
     $data = $request->all();
     $cssData = $data['css_data'];
     $disabledCss = $data['css_disabled'];
     //echo $file->getFileName(); // tmp file name
     // Markdown をhtmlに変換
     $parsedown = new Parsedown();
     $body = $parsedown->text($mdText);
     // html全体を生成
     //$html = $this->_createHtml($body);
     $html = $this->_createHtml($body, $cssData, $disabledCss);
     // PDFの作成
     $snappy = new Pdf('/usr/local/bin/wkhtmltopdf');
     // filename
     $pdfName = pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME) . "_" . date("YmdHis") . ".pdf";
     $snappy->generateFromHtml($html, storage_path() . "/app/pdf/{$pdfName}");
     return response()->json(array("name" => $pdfName));
 }
Example #11
0
    $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) {
    if (file_exists($app['tmpFile'])) {
        unlink($app['tmpFile']);
    }
});
$app->error(function (\Exception $e, $code) use($app) {
    if ($app['debug']) {
        return;
    }
    $response = ['status' => 'error', 'code' => $code];
Example #12
0
<?php

require_once "vendor/autoload.php";
use Knp\Snappy\Pdf;
if (isset($_POST) && isset($_POST["envoyer"])) {
    $myProjectDirectory = '/var/www/html/mouskipd';
    $snappy = new Pdf();
    $snappy->setBinary('/var/www/html/mouskipd/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64');
    $snappy->generateFromHtml('<h1>Bill</h1><p>You owe me money, dude.</p>', '/var/www/html/mouskipd/tmp/bill-123.pdf');
    var_dump($snappy);
    echo "<pre>";
    var_dump($snappy);
    echo "</pre>";
}
?>

<form action="index.php" method="POST" accept-charset="utf-8">
    <input type="submit" name="envoyer">
</form>
Example #13
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;
 }