<?php
//include_once(_DIR_EXT.'/HTML/c_page_TXT.php') ;
class c_page_xls_pdf //extends c_page_TXT
{

 function show()
 {   set_include_path(_DIR_TO_ROOT.'/AddOns/PHPExcel/');
     require_once 'PHPExcel/IOFactory.php';
     require_once 'PHPExcel.php';
     //$rendererName = PHPExcel_Settings::PDF_RENDERER_DOMPDF;
     //$rendererLibrary = 'dompdf-master';

     $rendererName = PHPExcel_Settings::PDF_RENDERER_MPDF;
     $rendererLibrary = 'MPDF57';
     $rendererLibraryPath = _DIR_TO_ROOT.'/AddOns/'.$rendererLibrary;

     //  Here's the magic: you __tell__ PHPExcel what rendering engine to use
     //     and where the library is located in your filesystem
     if (!PHPExcel_Settings::setPdfRenderer($rendererName,$rendererLibraryPath))
     { die('NOTICE: Please set the $rendererName and $rendererLibraryPath values<br />at the top of this script as appropriate for your directory structure');}

     $objPHPExcel = new PHPExcel();
     $objReader = new PHPExcel_Reader_Excel5();
     //$objPHPExcel = $objReader->load(_DIR_TO_ROOT.'/test.xls');
     //$objPHPExcel = $objReader->load(_DIR_TO_ROOT.'/class/ext/aspmo_reports/pl_A5.xls');
     $objPHPExcel = $objReader->load(_DIR_TO_ROOT.'/putevoi-list.xls');
     $objPHPExcel->setActiveSheetIndex(0);
     $rowIterator = $objPHPExcel->getActiveSheet()->getRowIterator();
     $sheet = $objPHPExcel->getActiveSheet();
     //$sheet->setCellValue('B1', 'B');
     //$sheet->setCellValue('C1', 'C');
     $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF');

     //сохранить на диск
     //$objWriter->save('document.pdf');

     // отдача в браузер
     $name='test1.pdf' ;
     header('Content-Type: application/pdf');
     //echo header('Content-Disposition: attachment; filename=filename="'.$name.'"' ); // для сохранения в папке загрузов
	 header('Content-disposition: inline; filename="'.$name.'"');          // для вывода в браузер
	 header('Cache-Control: public, must-revalidate, max-age=0');
	 header('Pragma: public');
	 header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
	 header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
     $objWriter->save('php://output');



















     return ;
     global $orders_system ;
     //ob_start() ;
     //list($recs,$stats)=ESMO()->get_mo_recs(array('limit'=>3)) ;
     //include_once(_DIR_EXT.'/aspmo/list_mo_sessions.php') ;
     //list_mo_sessions($recs,array('id'=>'panel_last_mo')) ;
     /*?><img src="/class/ext/aspmo_reports/put_list.jpg"/><?*/
     //$html=ob_get_clean() ;
     //$this->put_to_pdf('TEST',$html) ;

     /*
    //$html = '<table border="1"><tr><td>Пример 1</td><td>Пример 2</td><td>Пример 3</td><td>Пример 4</td></tr>
    <tr><td>Пример 5</td><td>Пример 6</td><td>Пример 7</td><td><a href="http://mpdf.bpm1.com/" title="mPDF">mPDF</a></td></tr></table>';
        */


     //include_once _DIR_TO_ROOT.'/AddOns/PHPExcel/PHPExcel.php';
     /** PHPExcel_IOFactory */
     require_once (_DIR_TO_ROOT.'/AddOns/PHPExcel/PHPExcel/IOFactory.php');
     //include_once (_DIR_TO_ROOT.'/AddOns/PHPExcel/PHPExcel/Writer/Excel2007.php');
     //include_once (_DIR_TO_ROOT.'/AddOns/PHPExcel/PHPExcel/Writer/Excel5.php');
     include_once (_DIR_TO_ROOT.'/AddOns/PHPExcel/PHPExcel/Writer/PDF.php');


     set_include_path(_DIR_TO_ROOT.'/AddOns/PHPExcel/:'._DIR_TO_ROOT.'/AddOns/MPDF57/');
     //set_include_path(_DIR_TO_ROOT.'/AddOns/MPDF57/');
     include_once 'PHPExcel/IOFactory.php';
     $objPHPExcel = PHPExcel_IOFactory::load(_DIR_TO_ROOT.'/class/ext/aspmo_reports/pl_A5.xls');
     $objPHPExcel->setActiveSheetIndex(0);


     //include_once (_DIR_TO_ROOT.'/AddOns/PHPExcel/PHPExcel/Writer/PDF/DomPDF.php');

     //$objPHPexcel = PHPExcel_IOFactory::load(_DIR_TO_ROOT.'/class/ext/aspmo_reports/pl_A5.xls');
     //$objPHPexcel = PHPExcel_IOFactory::load(_DIR_TO_ROOT.'/2.xls');
     //var_dump($objPHPexcel) ;

     //$objPHPExcel->setActiveSheetIndex(0);
     //$aSheet = $objPHPExcel->getActiveSheet();


     //require_once 'PHPExcel.php';
     //$objPHPExcel = new PHPExcel();
     // устанавливаем метаданные
     /*
     $objPHPExcel->getProperties()->setCreator("PHP")
                     ->setLastModifiedBy("Алексей")
                     ->setTitle("Office 2007 XLSX Тестируем")
                     ->setSubject("Office 2007 XLSX Тестируем")
                     ->setDescription("Тестовый файл Office 2007 XLSX, сгенерированный PHPExcel.")
                     ->setKeywords("office 2007 openxml php")
                     ->setCategory("Тестовый файл");
     $objPHPExcel->getActiveSheet()->setTitle('Демо');
     */

     $objPHPExcel->setActiveSheetIndex(0)
                 ->setCellValue('A1', 'Привет')
                 ->setCellValue('B1', 'Мир!');


     $rendererName = PHPExcel_Settings::PDF_RENDERER_DOMPDF;
     //$rendererLibrary = 'dompdf';
     $rendererLibrary = 'mPDF5.7';
     //$rendererLibrary = 'tcPDF5.9';
     //$rendererLibrary = 'domPDF0.6.0beta3';

     //$rendererLibraryPath = ini_get('include_path') . $rendererLibrary;
     $rendererLibraryPath = ini_get('include_path') . $rendererLibrary;

     //require_once 'PHPExcel/IOFactory.php';
     //$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
     // Если вы хотите, то можете сохранить в другом формате, например, PDF:
     $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF');
     $objWriter->writeAllSheets();

     echo header("Content-Type: application/pdf");
     echo header("Content-Disposition: attachment; filename=test.pdf" );
     echo header('Cache-Control: max-age=0');


     $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF');
     $objWriter->save('php://output');
     //$objWriter->save('test.pdf');
     return ;

     //отдаем пользователю в браузер
     //include("PHPExcel/Writer/Excel5.php");
     $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
     header('Content-Type: application/vnd.ms-excel;name="export.xls"');
     header('Content-Disposition: attachment;filename="export.xls"');
     header('Cache-Control: max-age=0');




     $objWriter->save('php://output');

     //$objWriter->save('MyExcel.xslx');

      return ;




     //Prepare the 1st Excel worksheet (named as Sheet1) in the workbook for editing
    //$objWorksheet = $objPHPexcel->setActiveSheetIndex(0);

    //Change the content of Cell A1 in Sheet1
    //$objWorksheet->getCell(‘A1′)->setValue(‘Jack and Jill went up the hill to fetch a pail of water.’);


     //$rendererName = PHPExcel_Settings::PDF_RENDERER_DOMPDF;
     //$rendererLibrary = 'tcPDF5.9';
     //$rendererLibrary = 'mPDF5.4';
     //$rendererLibrary = 'domPDF0.6.0beta3';
     //$rendererLibraryPath = '/' . $rendererLibrary;
     //$objPHPExcel->getActiveSheet()->setTitle('Orari');
     $objWriter = PHPExcel_IOFactory::createWriter($objPHPexcel, 'PDF');
     //$objWriter->setSheetIndex(0);
     $objWriter->writeAllSheets();
     $objWriter->save('test.pdf');




 }

 function put_to_pdf($name,$html)
 {
     include(_DIR_TO_ROOT."/AddOns/MPDF57/mpdf.php");
     $mpdf = new mPDF('utf-8', 'A5', '8', '', 10, 10, 7, 7, 10, 10); /*задаем формат, отступы и.т.д.*/
     $mpdf->charset_in = 'UTF-8'; /*не забываем про русский*/

     $stylesheet = file_get_contents(_DIR_TO_CLASS.'/style.css'); /*подключаем css*/
     $stylesheet = file_get_contents(_DIR_TO_ROOT.'/style_pdf.css'); /*подключаем css*/
     $mpdf->WriteHTML($stylesheet, 1);

     $mpdf->list_indent_first_level = 0;
     //$mpdf->WriteHTML($html, 2); /*формируем pdf*/

    //$mpdf->WriteHTML('<p>This should print on an A4 (portrait) sheet</p>');
    //$mpdf->WriteHTML('<tocpagebreak sheet-size="A4-L" toc-sheet-size="A5" toc-preHTML="This ToC should print on an A5 sheet" />');
    $mpdf->WriteHTML('<img src="/class/ext/aspmo_reports/put_list-n1.jpg"/>');
    $mpdf->WriteHTML('<img src="/class/ext/aspmo_reports/put_list-n2.jpg"/>');
    //$mpdf->WriteHTML('<tocentry content="A4 landscape" /><p>This page appears just after the ToC and should print on an A4 (landscape) sheet</p>');
    //$mpdf->WriteHTML('<tocentry content="A4 landscape" /><p>This page appears just after the ToC and should print on an A4 (landscape) sheet</p>');
    //$mpdf->WriteHTML('<pagebreak sheet-size="A5-L" />');
    //$mpdf->WriteHTML($html);

     $mpdf->Output($name.'.pdf', 'I');

     return ;
    $hhtml = '
    <htmlpageheader name="myHTMLHeaderOdd" style="display:none">
    <div style="background-color:#BBEEFF" align="center"><b>&nbsp;{PAGENO}&nbsp;</b></div>
    </htmlpageheader>
    <htmlpagefooter name="myHTMLFooterOdd" style="display:none">
    <div style="background-color:#CFFFFC" align="center"><b>&nbsp;{PAGENO}&nbsp;</b></div>
    </htmlpagefooter>
    <sethtmlpageheader name="myHTMLHeaderOdd" page="O" value="on" show-this-page="1" />
    <sethtmlpagefooter name="myHTMLFooterOdd" page="O" value="on" show-this-page="1" />
    ';
    //==============================================================
    $html = '
    <h1>mPDF Page Sizes</h1>
    <h3>Changing page (sheet) sizes within the document</h3>
    ';
    //==============================================================
    //==============================================================
     include(_DIR_TO_ROOT."/AddOns/MPDF57/mpdf.php");
    $mpdf=new mPDF('c','A4');
    $mpdf->WriteHTML($hhtml);
    $mpdf->WriteHTML($html);
    $mpdf->WriteHTML('<p>This should print on an A4 (portrait) sheet</p>');
    $mpdf->WriteHTML('<tocpagebreak sheet-size="A4-L" toc-sheet-size="A5" toc-preHTML="This ToC should print on an A5 sheet" />');
    $mpdf->WriteHTML($html);
    $mpdf->WriteHTML('<tocentry content="A4 landscape" /><p>This page appears just after the ToC and should print on an A4 (landscape) sheet</p>');
    $mpdf->WriteHTML('<pagebreak sheet-size="A5-L" />');
    $mpdf->WriteHTML($html);
    $mpdf->WriteHTML('<tocentry content="A5 landscape" /><p>This should print on an A5 (landscape) sheet</p>');
    $mpdf->WriteHTML('<pagebreak sheet-size="Letter" />');
    $mpdf->WriteHTML($html);
    $mpdf->WriteHTML('<tocentry content="Letter portrait" /><p>This should print on an Letter sheet</p>');
    $mpdf->WriteHTML('<pagebreak sheet-size="150mm 150mm" />');
    $mpdf->WriteHTML($html);
    $mpdf->WriteHTML('<tocentry content="150mm square" /><p>This should print on a sheet 150mm x 150mm</p>');
    $mpdf->WriteHTML('<pagebreak sheet-size="11.69in 8.27in" />');
    $mpdf->WriteHTML($html);
    $mpdf->WriteHTML('<tocentry content="A4 landscape (ins)" /><p>This should print on a sheet 11.69in x 8.27in = A4 landscape</p>');
    $mpdf->Output();
 }

}
?>