生成一个URL或HTML页面缩略图的PHP库:snappy

jopen 11年前

这是一个PHP5库能够根据给定的URL或HML页面生成缩略图,快照,PDF文件。它封装自 wkhtmltopdf/wkhtmltoimage

http://KnpLabs.com。支持: OSX, linux, windows。

<?php    require_once '/path/to/snappy/src/autoload.php';    use Knp\Snappy\Pdf;    $snappy = new Pdf('/usr/local/bin/wkhtmltopdf');    // or you can do it in two steps  $snappy = new Pdf();  $snappy->setBinary('/usr/local/bin/wkhtmltopdf');    // Display the resulting pdf in the browser  // by setting the Content-type header to pdf  $snappy = new Pdf('/usr/local/bin/wkhtmltopdf');  header('Content-Type: application/pdf');  header('Content-Disposition: attachment; filename="file.pdf"');  echo $snappy->getOutput('http://www.github.com');    // .. or simply save the PDF to a file  $snappy = new Pdf('/usr/local/bin/wkhtmltopdf');  $snappy->generateFromHtml('<h1>Bill</h1><p>You owe me money, dude.</p>', '/tmp/bill-123.pdf');    // Pass options to snappy  // Type wkhtmltopdf -H to see the list of options  $snappy = new Pdf('/usr/local/bin/wkhtmltopdf');  $snappy->setOption('disable-javascript', true);  $snappy->setOption('no-background', true);  $snappy->setOption('allow', array('/path1', '/path2'));  $snappy->setOption('cookie', array('key' => 'value', 'key2' => 'value2'));

项目主页:http://www.open-open.com/lib/view/home/1388458165250