function download($resumeId) { $this->_check_auth(); if (!$this->_is_paid_for()) { redirect('checkout', 'refresh'); } $markup = $this->input->post('markup'); $html = file_get_contents("http://www.google.com"); $pdf = new WKPDF(); //$pdf->set_html($html); $pdf->set_url(site_url('resumes/pdf/' . $resumeId)); $pdf->render(); $pdf->output(WKPDF::$PDF_EMBEDDED, 'resume.pdf'); }
/** * Function that attempts to return the kind of CPU. * @return string CPU kind ('amd64' or 'i386'). */ private static function _getCPU() { if (self::$cpu == '') { if (`getconf LONG_BIT` == 64) { self::$cpu = 'amd64'; } elseif (`getconf LONG_BIT` == 32) { self::$cpu = 'i386'; } else { throw new Exception('WKPDF couldn\'t determine CPU ("' . `grep -i vendor_id /proc/cpuinfo` . '").'); } } return self::$cpu; }
/** * Function that attempts to return the correct executable path. * @return string WKHTMLTOPDF path. */ protected static function _getCMD() { if (self::$_cmd == '') { // the end filename is in the form of "(%PATH%)wkhtmltopdf[-(win|osx|lin)-(amd64|i386|ppc)][.exe]" self::$_cmd = $GLOBALS['WKPDF_BASE_PATH']; self::$_cmd .= self::_getOS() == 'win' ? 'wkhtmltopdf.exe' : 'wkhtmltopdf-' . self::_getOS() . '-' . self::_getCPU(); } switch (self::_getOS()) { case 'win': // checks file existence (permissions on windows isn't much of a problem) // for windows, the command is "exists %filename%" ... try it out? break; case 'lin': case 'osx': // checks file existence and permissions using LS $exists = self::_pipeExec('test -f "' . self::$_cmd . '"'); if ($exists['return'] > 0) { throw new Exception('WKPDF executable couldn\'t be found ("' . htmlspecialchars(self::$_cmd) . '").'); } $exists = explode(' ', str_replace(' ', ' ', str_replace(' ', ' ', $exists['stdout']))); // perms, unused, group, user, ... if (count($exists) > 1) { // "test" command ran, keep testing settings, otherwise just ignore tests... if (strstr($exists[0], 'rwxrwxrwx') === false) { if ($exists[2] != get_current_user() || $exists[3] != get_current_user()) { throw new Exception('WKPDF executable permissions are not 0777 or user/group does not match with current user/group.'); } } } break; } return self::$_cmd; }
public function wkhtml() { $pdf = WKPDF::make(); $pdf->addPage('<html><head></head><body><b>Hello World</b></body></html>'); $pdf->send(); //return ; }
private static function downloadPDF($content, $filename) { if (!is_executable(WKPDF_PATH)) { throw new \Exception('WKPDF is not installed or executable', 666); } $pdf = new \WKPDF(WKPDF_PATH); if (USE_XVFB) { $pdf->setXVFB(XVFB_PATH); } $pdf->set_html($content); $pdf->render(); $pdf->output(\WKPDF::$PDF_DOWNLOAD, '/tmp/' . $filename); exit; }
$id = trim($_GET['id']); } else { header("Location: /404"); exit; } $report = $erapi->report($_GET['id']); if (empty($report)) { header('Location: /404'); exit; } $user = !empty($current_user) ? $current_user->ID : ''; switch ($type) { case 'pdf': $reporthtml = file_get_contents('http://' . $_SERVER['HTTP_HOST'] . '/index.php?p=report&id=' . $report->id . '&pdf=1'); $reportheader = file_get_contents('http://' . $_SERVER['HTTP_HOST'] . '/libs/report-pdf-header.php'); $reportfooter = file_get_contents('http://' . $_SERVER['HTTP_HOST'] . '/libs/report-pdf-footer.php'); $pdf = new WKPDF(); $pdf->set_html($reporthtml); $pdf->set_header($reportheader); $pdf->set_footer($reportfooter); $pdf->set_toc(false); $pdf->set_zoom(0.75); $pdf->set_page_size("A4"); $pdf->render(); $pdf->output(WKPDF::$PDF_DOWNLOAD, 'report-' . $report->domain . '.pdf'); break; default: header("Location: /404"); exit; } exit;
function qa_book_plugin_create_pdf($return = false) { include 'wkhtmltopdf.php'; //echo $html; $pdf = new WKPDF(); $pdf->render_q2a(); if ($return) { $pdf->output(WKPDF::$PDF_DOWNLOAD, 'book.pdf'); } else { $pdf->output(WKPDF::$PDF_SAVEFILE, qa_opt('book_plugin_loc_pdf')); } error_log('Q2A PDF Book Created on ' . date('M j, Y \\a\\t H\\:i\\:s')); }
public function setXVFB($path) { self::$PDF_USE_XVFB = true; if (!is_file($path)) { throw new \Exception('xvfb executable not found'); } self::$PDF_XVFB_PATH = $path; }
<?php include "./findconfig.php"; include $_SERVER['DOCUMENT_ROOT'] . "/" . $ROOTPATH . "/Includes/Top.php"; $DB = new conn(); $DB->connect(); $DB->close(); require_once 'wk.php'; $pdf = new WKPDF(); $pdf->set_html('http://www.google.com'); $pdf->render(); $pdf->output(WKPDF::$PDF_EMBEDDED, 'tmp/sample.pdf'); ?>
include "./findconfig.php"; include $_SERVER['DOCUMENT_ROOT'] . "/" . $ROOTPATH . "/class_inc.php"; $DB = new conn(); $DB->connect(); $sql = "select data from reports where id = " . $DB->sanitize($_REQUEST["report_id"]); $result = $DB->query_scalar($sql); $time = time(); $css = "<link rel=\"StyleSheet\" href=\"" . $FQDN . "/" . $ROOTPATH . "/CSS/main.css.php?" . $time . "/>"; // Get Querystring params $output = $DB->sanitize($_REQUEST["output"]); $footer = $DB->sanitize($_REQUEST["footer"]); $orient = $DB->sanitize($_REQUEST["orient"]); $result = str_replace("<HTML><HEAD></HEAD>", "<HTML><HEAD>" . $css . "</HEAD>", $result); require_once "wk.php"; $pdf = new WKPDF(); $pdf->set_html($result); if ($footer) { $pdf->set_footer("Page [page] of [toPage]"); } if ($orient) { $pdf->set_orientation($orient); } $pdf->render(); if ($output) { if ($output == "pdf") { } $pdf->output(WKPDF::$PDF_DOWNLOAD, 'sample.pdf'); } else { $pdf->output(WKPDF::$PDF_EMBEDDED, 'sample.pdf'); }
/** * @param $id * @throws CHttpException */ public function actionPdf($id) { Yii::import('application.extensions.less.*'); $lessc = new lessc(); $lessc->checkedCompile(Yii::getPathOfAlias('webroot.less') . '/' . 'html2pdf.less', Yii::getPathOfAlias('webroot.css') . '/' . 'html2pdf.css'); $model = $this->loadModel($id); if (!$model) { throw new CHttpException(404, 'Property not found'); } $settings = InstructionToPdfSettings::model()->findByAttributes(['instructionId' => $id]); if (!$settings) { $settings = new InstructionToPdfSettings(); } $pdf = new WKPDF(); $pdf->setMargins(['top' => '40']); $pdf->addResource('css', Yii::getPathOfAlias('webroot.css') . '/' . 'html2pdf.css'); $cssFiles = ['html2pdf.css']; /** @var $browser Browser */ $browser = Yii::app()->browser; if ($browser->getBrowser() == Browser::BROWSER_FIREFOX && $browser->getVersion() >= 19) { $pdf->addResource('css', Yii::getPathOfAlias('webroot.css') . '/' . 'helvetica_html2pdf.css'); $cssFiles[] = 'helvetica_html2pdf.css'; } $pdf->set_html($this->renderPartial('instructionToPDF', ['model' => $model, 'settings' => $settings, 'pdf' => $pdf, 'cssFiles' => $cssFiles], true)); $pdf->set_htmlHeader($this->renderPartial('instructionToPDF/header', ['model' => $model, 'settings' => $settings, 'pdf' => $pdf, 'cssFiles' => $cssFiles], true)); $pdf->set_htmlFooter($this->renderPartial('instructionToPDF/footer', ['model' => $model, 'settings' => $settings, 'pdf' => $pdf, 'cssFiles' => $cssFiles, 'offices' => Office::model()->active()->findAll()], true)); $pdf->set_orientation(WKPDF::$PDF_PORTRAIT); $pdf->render(); $pdf->output(WKPDF::$PDF_EMBEDDED, null); }
<?php /** * !! SECURITY WARNING !! * This file may be used maliciously on your server. * REMOVE THIS FILE FROM YOUR PRODUCTION SERVER. */ // load class file require_once 'wkhtmltopdf.php'; if (isset($_REQUEST['URL'])) { // if URL is set... // generate PDF given URL and force embed try { $urls = explode(';', $_REQUEST['URL']); if (count($urls) <= 1) { $pdf = new WKPDF(); $pdf->set_url($urls[0]); $pdf->render(); $pdf->output(WKPDF::$PDF_EMBEDDED, 'converted.pdf'); } else { $pdf = new WKPDF_MULTI(); foreach ($urls as $url) { $pdf->add_url($url); } $pdf->render(); $pdf->output(WKPDF::$PDF_EMBEDDED, 'converted.pdf'); } } catch (Exception $e) { die('Exception (line ' . $e->getLine() . '): ' . $e->getMessage()); } } else {
/** * Function that attempts to return the kind of CPU. * @return string CPU kind ('amd64' or 'i386'). */ private static function _getCPU2() { if (self::$cpu == '') { if (`uname -m` != 'x86_64') { self::$cpu = 'amd64'; } elseif (`uname -m` != 'i686') { self::$cpu = 'i386'; } else { throw new Exception('WKPDF couldn\'t determine CPU ("' . `grep -i vendor_id /proc/cpuinfo` . '").'); } } return self::$cpu; }