/** * Function that attempts to return the kind of CPU. * @return string CPU kind ('amd64' or 'i386'). */ private static function _getCPU() { if (self::$cpu == '') { if (`grep -i amd /proc/cpuinfo` != '') { self::$cpu = 'amd64'; } elseif (`grep -i intel /proc/cpuinfo` != '') { self::$cpu = 'i386'; } else { throw new Exception('WKPDF couldn\'t determine CPU ("' . `grep -i vendor_id /proc/cpuinfo` . '").'); } } return self::$cpu; }
function getPDF($orders = null) { global $user, $timer; //$invoice = '<HTML><HEAD><link rel="stylesheet" type="text/css" href="'.NONSSL_URL.YUI2_PATH.'reset-fonts-grids/reset-fonts-grids.css" ><link rel="stylesheet" type="text/css" href="'.NONSSL_URL.THEME_RELATIVE.'css/base-styles.css"><link rel="stylesheet" type="text/css" href="'.NONSSL_URL.PATH_RELATIVE.'framework/modules/ecommerce/assets/css/print-invoice.css"><style>html{background:none;} #store-header{text-align:left;}</style></HEAD><BODY>'; $invoice = '<!DOCTYPE HTML><HTML><HEAD></HEAD><BODY>'; if (is_array($orders)) { foreach ($orders as $order) { if ($user->isAdmin()) { $invoice .= renderAction(array('controller' => 'order', 'action' => 'show', 'view' => 'show_printable', 'id' => $order['id'], 'printerfriendly' => '1', 'no_output' => 'true')); //eDebug($order['id'] . ": " . $timer->mark()); } else { $invoice .= renderAction(array('controller' => 'order', 'action' => 'myOrder', 'view' => 'show_printable', 'id' => $order['id'], 'printerfriendly' => '1', 'no_output' => 'true')); } $invoice .= '<p style="page-break-before: always;"></p>'; } $invoice = substr($invoice, 0, strlen($invoice) - 42); } else { if ($user->isAdmin()) { $invoice .= renderAction(array('controller' => 'order', 'action' => 'show', 'view' => 'show_printable', 'id' => $this->params['id'], 'printerfriendly' => '1', 'no_output' => 'true')); } else { $invoice .= renderAction(array('controller' => 'order', 'action' => 'myOrder', 'view' => 'show_printable', 'id' => $this->params['id'], 'printerfriendly' => '1', 'no_output' => 'true')); } } $invoice .= "</BODY></HTML>"; $invoice = mb_convert_encoding($invoice, 'HTML-ENTITIES', "UTF-8"); // eDebug($invoice); $org_name = str_ireplace(" ", "_", ORGANIZATION_NAME); //eDebug("Here",1); if (stristr(PHP_OS, 'Win')) { if (file_exists(HTMLTOPDF_PATH)) { do { $htmltopdftmp = HTMLTOPDF_PATH_TMP . mt_rand() . '.html'; } while (file_exists($htmltopdftmp)); } file_put_contents($htmltopdftmp, $invoice); exec(HTMLTOPDF_PATH . " " . $htmltopdftmp . " " . HTMLTOPDF_PATH_TMP . $org_name . "_Invoice.pdf"); $this->returnFile(HTMLTOPDF_PATH_TMP . $org_name . "_Invoice.pdf", $org_name . "_Invoice.pdf", "pdf"); exit; } else { //require_once(BASE.'external/tcpdf/config/lang/eng.php'); //require_once(BASE.'external/tcpdf/tcpdf.php'); //---- // create new PDF document /*$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('Nicola Asuni'); $pdf->SetTitle('TCPDF Example 001'); $pdf->SetSubject('TCPDF Tutorial'); $pdf->SetKeywords('TCPDF, PDF, example, test, guide'); // set default header data pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING); // set header and footer fonts $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); //set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); // remove default header/footer $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); //set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); //set some language-dependent strings $pdf->setLanguageArray($l); // --------------------------------------------------------- // set default font subsetting mode //$pdf->setFontSubsetting(true); // Set font // dejavusans is a UTF-8 Unicode font, if you only need to // print standard ASCII chars, you can use core fonts like // helvetica or times to reduce file size. //$pdf->SetFont('helvetica', '', 14, '', true); // Add a page // This method has several options, check the source code documentation for more information. $pdf->AddPage(); //eDebug($invoice,1); // Print text using writeHTMLCell() //$pdf->writeHTML($w=0, $h=0, $x='', $y='', $invoice, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true); $pdf->writeHTML($invoice); // --------------------------------------------------------- // Close and output PDF document // This method has several options, check the source code documentation for more information. ob_clean(); $pdf->Output('example_001.pdf', 'I'); exit(); //============================================================+ // END OF FILE //============================================================+ // create new PDF document $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor(ORGANIZATION_NAME); $pdf->SetTitle($org_name . "_Invoice"); $pdf->SetSubject($org_name . "_Invoice"); // remove default header/footer $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); //set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); $pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $invoice, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true); $pdf->Output($org_name . "_Invoice" . ".pdf", 'I'); exit();*/ eDebug("Done rendering invoice html. Starting PDF Generation: " . $timer->mark()); $pdfer = new expHtmlToPDF(); $pdfer->set_html($invoice); $pdfer->set_orientation('Portrait'); $pdfer->set_page_size('Letter'); $pdfer->set_grayscale(true); $pdfer->render(); eDebug("Done rendering PDF " . $timer->mark()); exit; ob_clean(); $pdfer->output('D', $org_name . "_Invoice" . ".pdf"); exit; } }