/** * Save PHPExcel to file * * @param string $pFilename Name of the file to save as * @throws PHPExcel_Writer_Exception */ public function save($pFilename = null) { $fileHandle = parent::prepareForSave($pFilename); // Default PDF paper size $paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.) // Check for paper size and page orientation if (is_null($this->getSheetIndex())) { $orientation = $this->_phpExcel->getSheet(0)->getPageSetup()->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE ? 'L' : 'P'; $printPaperSize = $this->_phpExcel->getSheet(0)->getPageSetup()->getPaperSize(); $printMargins = $this->_phpExcel->getSheet(0)->getPageMargins(); } else { $orientation = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE ? 'L' : 'P'; $printPaperSize = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize(); $printMargins = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageMargins(); } $this->setOrientation($orientation); // Override Page Orientation if (!is_null($this->getOrientation())) { $orientation = $this->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT ? PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT : $this->getOrientation(); } $orientation = strtoupper($orientation); // Override Paper Size if (!is_null($this->getPaperSize())) { $printPaperSize = $this->getPaperSize(); } if (isset(self::$paperSizes[$printPaperSize])) { $paperSize = self::$paperSizes[$printPaperSize]; } // Create PDF $pdf = new mpdf(); $ortmp = $orientation; $pdf->_setPageSize(strtoupper($paperSize), $ortmp); $pdf->DefOrientation = $orientation; $pdf->AddPage($orientation); // Document info $pdf->SetTitle($this->_phpExcel->getProperties()->getTitle()); $pdf->SetAuthor($this->_phpExcel->getProperties()->getCreator()); $pdf->SetSubject($this->_phpExcel->getProperties()->getSubject()); $pdf->SetKeywords($this->_phpExcel->getProperties()->getKeywords()); $pdf->SetCreator($this->_phpExcel->getProperties()->getCreator()); $pdf->WriteHTML($this->generateHTMLHeader(false) . $this->generateSheetData() . $this->generateHTMLFooter()); // Write to file fwrite($fileHandle, $pdf->Output('', 'S')); parent::restoreStateAfterSave($fileHandle); }
/** * Save PHPExcel to file * * @param string $pFileName * @throws Exception */ public function save($pFilename = null) { // garbage collect $this->_phpExcel->garbageCollect(); $saveArrayReturnType = PHPExcel_Calculation::getArrayReturnType(); PHPExcel_Calculation::setArrayReturnType(PHPExcel_Calculation::RETURN_ARRAY_AS_VALUE); // Open file $fileHandle = fopen($pFilename, 'w'); if ($fileHandle === false) { throw new Exception("Could not open file {$pFilename} for writing."); } // Set PDF $this->_isPdf = true; // Build CSS $this->buildCSS(true); // Default PDF paper size $paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.) // Check for paper size and page orientation if (is_null($this->getSheetIndex())) { $orientation = $this->_phpExcel->getSheet(0)->getPageSetup()->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE ? 'L' : 'P'; $printPaperSize = $this->_phpExcel->getSheet(0)->getPageSetup()->getPaperSize(); $printMargins = $this->_phpExcel->getSheet(0)->getPageMargins(); } else { $orientation = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE ? 'L' : 'P'; $printPaperSize = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize(); $printMargins = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageMargins(); } $this->setOrientation($orientation); // Override Page Orientation if (!is_null($this->getOrientation())) { $orientation = $this->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT ? PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT : $this->getOrientation(); } $orientation = strtoupper($orientation); // Override Paper Size if (!is_null($this->getPaperSize())) { $printPaperSize = $this->getPaperSize(); } if (isset(self::$_paperSizes[$printPaperSize])) { $paperSize = self::$_paperSizes[$printPaperSize]; } // Create PDF $pdf = new mpdf(); $pdf->_setPageSize(strtoupper($paperSize), $orientation); $pdf->DefOrientation = $orientation; // Document info $pdf->SetTitle($this->_phpExcel->getProperties()->getTitle()); $pdf->SetAuthor($this->_phpExcel->getProperties()->getCreator()); $pdf->SetSubject($this->_phpExcel->getProperties()->getSubject()); $pdf->SetKeywords($this->_phpExcel->getProperties()->getKeywords()); $pdf->SetCreator($this->_phpExcel->getProperties()->getCreator()); $pdf->WriteHTML($this->generateHTMLHeader(false) . $this->generateSheetData() . $this->generateHTMLFooter()); // Write to file fwrite($fileHandle, $pdf->Output('', 'S')); // Close file fclose($fileHandle); PHPExcel_Calculation::setArrayReturnType($saveArrayReturnType); }
$payment_staus = $reservations->reservationPaymentStatus(); $pdf_message = ""; if ($payment_staus) { $pdf_message = "Your Reservation is Successful. Thank you for choosing Roomista.com as your booking engine"; } else { $pdf_message = "Sorry Reservation is Unsuccessful. Thank you for choosing Roomista.com as your booking engine"; } ob_start(); include dirname(__FILE__) . "/res/voucher_template.php"; $content = ob_get_clean(); require_once dirname(__FILE__) . '/../mPDF/mpdf.php'; try { $pdf = new mpdf('', strtoupper('A4'), 0, 'Arial, Helvetica, sans-serif', 20, 15, 20, 5, 0, 0, 'L'); $pdf->AddPage($orientation); // Document info $pdf->SetTitle("Customer Invoice"); $pdf->SetAuthor("roomista.com"); $pdf->SetSubject("Customer Invoice"); $pdf->SetKeywords("Customer Invoice"); $pdf->SetCreator("roomista.com"); $pdf->WriteHTML(utf8_encode($content)); $filename = "Reservation_client_invoice.pdf"; if ($_REQUEST['force'] == 'email') { $content = $pdf->Output('invoive.pdf', 'S'); $content = chunk_split(base64_encode($content)); $mail = new PHPMailer(); $body = "<table width='745' style='font-family: Arial, Helvetica, sans-serif'>\n <tr>\n <td width='745' style='text-align: center; font-size: 20pt;'>Congratulations</td>\n </tr>\n <tr>\n <td height='25' ></td>\n </tr>\n <tr>\n <td width='745' style='text-align: center; font-size: 14pt; '>Your reservation was successfully completed</td>\n </tr>\n <tr>\n <td height='10' ></td>\n </tr>\n <tr>\n <td width='745' style='text-align: left; font: 700 '>We have attached the customer invoice for your reference. Do have a copy of the same when checking in at the hotel.</td>\n </tr>\n <tr>\n <td width='745' style='text-align: left; font: 700 '>Wishing you a pleasant stay.</td>\n </tr>\n <tr>\n <td width='745' style='text-align: left; font: 700 '>\n <p>\n --<br/>\n Kind regards<br>\n System Administrator, <br>\n <strong><a href='roomista.com'>roomista.com</a></strong>\n </p>\n <br/><br/><br/>\n <hr/>\n <span style='color:#CCC; font-size:10px; font-family:Arial, Helvetica, sans-serif;'>This e-mail is confidential. It may also be legally privileged. If you are not the intended recipient or have received it in error, please delete it and all copies from your system and notify the sender immediately by return e-mail. Any unauthorized reading, reproducing, printing or further dissemination of this e-mail or its contents is strictly prohibited and may be unlawful. Internet communications cannot be guaranteed to be timely, secure, error or virus-free. The sender does not accept liability for any errors or omissions.</span>\n </td>\n </tr>\n </table>"; //Headers of PDF and e-mail $boundary = "XYZ-" . date("dmYis") . "-ZYX"; $header = "--{$boundary}\r\n"; $header .= "Content-Transfer-Encoding: 8bits\r\n";
/** * Save PHPExcel to file * * @param string $pFileName * @throws Exception */ public function save($pFilename = null) { // garbage collect $this->_phpExcel->garbageCollect(); $saveArrayReturnType = PHPExcel_Calculation::getArrayReturnType(); PHPExcel_Calculation::setArrayReturnType(PHPExcel_Calculation::RETURN_ARRAY_AS_VALUE); // Open file $fileHandle = fopen($pFilename, 'w'); if ($fileHandle === false) { throw new Exception("Could not open file $pFilename for writing."); } // Set PDF $this->_isPdf = true; // Build CSS $this->buildCSS(true); if(!$this->_printParamsSetted) { // Default PDF paper size $paperSize = 'A4'; // Check for paper size and page orientation if (is_null($this->getSheetIndex())) { $orientation = ($this->_phpExcel->getSheet(0)->getPageSetup()->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; $printPaperSize = $this->_phpExcel->getSheet(0)->getPageSetup()->getPaperSize(); $printMargins = $this->_phpExcel->getSheet(0)->getPageMargins(); } else { $orientation = ($this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; $printPaperSize = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize(); $printMargins = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageMargins(); } $this->setOrientation($orientation); // Override Page Orientation if (!is_null($this->getOrientation())) { $orientation = ($this->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT) ? PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT : $this->getOrientation(); } $orientation = strtoupper($orientation); // Override Paper Size if (!is_null($this->getPaperSize())) { $printPaperSize = $this->getPaperSize(); } if (isset(self::$_paperSizes[$printPaperSize])) { $paperSize = self::$_paperSizes[$printPaperSize]; } if(is_string($paperSize)){ $paperSize = strtoupper($paperSize.(substr($orientation,0,1) == 'L' ? '-L' : '')); } if($printMargins) { //$printMargins是英寸制,要转换成毫米 $tmargin = 25.4 * $printMargins->getTop(); $bmargin = 25.4 * $printMargins->getBottom(); $lmargin = 25.4 * $printMargins->getLeft(); $rmargin = 25.4 * $printMargins->getRight(); $hmargin = 25.4 * $printMargins->getHeader(); $fmargin = 25.4 * $printMargins->getFooter(); } } else { $paperSize = $this->_printPaperSize; $orientation = $this->_printOrientation; $tmargin = $this->_printTmargin; $bmargin = $this->_printBmargin; $lmargin = $this->_printLmargin; $rmargin = $this->_printRmargin; $hmargin = $this->_printHmargin; $fmargin = $this->_printFmargin; } error_reporting(E_ALL ^ E_NOTICE); //当前的版本很多notice警告,屏蔽掉 // Create PDF $pdf = new mpdf(); $pdf->useAdobeCJK = true; // Default setting in config.php $pdf->SetAutoFont(AUTOFONT_ALL); // AUTOFONT_CJK | AUTOFONT_THAIVIET | AUTOFONT_RTL | AUTOFONT_INDIC // AUTOFONT_ALL // Log::write("\ndefault pdf:\nT:".$pdf->tMargin."\nB:".$pdf->bMargin."\nL:".$pdf->DeflMargin."\nR:".$pdf->DefrMargin."\nH:".$pdf->margin_header."\nF:".$pdf->margin_footer."\n\n"); $pdf->_setPageSize($paperSize, $orientation); $pdf->DefOrientation = $orientation; if(!empty($this->_printFooterO)) { $pdf->SetHTMLFooter($this->_printFooterO); } if(!empty($this->_printHeaderO)) { $pdf->SetHTMLHeader($this->_printHeaderO, 'O'); } if(!empty($this->_printFooterE)) { $pdf->SetHTMLFooter($this->_printFooterE, 'E'); } if(!empty($this->_printHeaderE)) { $pdf->SetHTMLHeader($this->_printHeaderE, 'E'); } if(!empty($tmargin)) { $pdf->tMargin = $tmargin; } if(!empty($bmargin)) { $pdf->bMargin = $bmargin; } if(!empty($lmargin)) { $pdf->DeflMargin = $lmargin; } if(!empty($rmargin)) { $pdf->DefrMargin = $rmargin; } if(!empty($hmargin)) { $pdf->margin_header = $hmargin; } if(!empty($fmargin)) { $pdf->margin_footer = $fmargin; } $pdf->mirrorMargins = $this->_mirrorMargins; if(!empty($this->_script)) { $pdf->SetJS($this->_script); } // Document info $pdf->SetTitle($this->_phpExcel->getProperties()->getTitle()); $pdf->SetAuthor($this->_phpExcel->getProperties()->getCreator()); $pdf->SetSubject($this->_phpExcel->getProperties()->getSubject()); $pdf->SetKeywords($this->_phpExcel->getProperties()->getKeywords()); $pdf->SetCreator($this->_phpExcel->getProperties()->getCreator()); $pdf->WriteHTML( $this->generateHTMLHeader(false) . $this->generateSheetData() . $this->generateHTMLFooter() ); // Write to file fwrite($fileHandle, $pdf->Output('','S')); // Close file fclose($fileHandle); PHPExcel_Calculation::setArrayReturnType($saveArrayReturnType); }