From 4fa6c2ceaf6aec326f8e7001af5a69955237406b Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Mon, 4 Jun 2012 21:34:16 +0000 Subject: [PATCH] Removed spurious final blank page from PDF Writer output git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@91328 2327b42d-5241-43d6-9e2a-de5ac946f064 --- Classes/PHPExcel/Writer/HTML.php | 18 +++++++++++------- Classes/PHPExcel/Writer/PDF/DomPDF.php | 25 +++++-------------------- Classes/PHPExcel/Writer/PDF/mPDF.php | 19 ++++++------------- Classes/PHPExcel/Writer/PDF/tcPDF.php | 16 +++++++--------- 4 files changed, 29 insertions(+), 49 deletions(-) diff --git a/Classes/PHPExcel/Writer/HTML.php b/Classes/PHPExcel/Writer/HTML.php index 08a2676d..ecc3883b 100644 --- a/Classes/PHPExcel/Writer/HTML.php +++ b/Classes/PHPExcel/Writer/HTML.php @@ -630,7 +630,9 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter { // table { } $css['table']['border-collapse'] = 'collapse'; - $css['table']['page-break-after'] = 'always'; + if (!$this->_isPdf) { + $css['table']['page-break-after'] = 'always'; + } // .gridlines td { } $css['.gridlines td']['border'] = '1px dotted black'; @@ -916,12 +918,14 @@ class PHPExcel_Writer_HTML implements PHPExcel_Writer_IWriter { $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($pSheet->getHighestColumn()) - 1; $i = -1; while($i++ < $highestColumnIndex) { - if (!$this->_useInlineCss) { - $html .= ' ' . PHP_EOL; - } else { - $style = isset($this->_cssStyles['table.sheet' . $sheetIndex . ' col.col' . $i]) ? - $this->_assembleCSS($this->_cssStyles['table.sheet' . $sheetIndex . ' col.col' . $i]) : ''; - $html .= ' ' . PHP_EOL; + if (!$this->_isPdf) { + if (!$this->_useInlineCss) { + $html .= ' ' . PHP_EOL; + } else { + $style = isset($this->_cssStyles['table.sheet' . $sheetIndex . ' col.col' . $i]) ? + $this->_assembleCSS($this->_cssStyles['table.sheet' . $sheetIndex . ' col.col' . $i]) : ''; + $html .= ' ' . PHP_EOL; + } } } diff --git a/Classes/PHPExcel/Writer/PDF/DomPDF.php b/Classes/PHPExcel/Writer/PDF/DomPDF.php index 38cf58b0..2784e149 100644 --- a/Classes/PHPExcel/Writer/PDF/DomPDF.php +++ b/Classes/PHPExcel/Writer/PDF/DomPDF.php @@ -67,17 +67,9 @@ class PHPExcel_Writer_PDF_DomPDF extends PHPExcel_Writer_PDF_Core implements PHP // Set PDF $this->_isPdf = true; - // Build CSS $this->buildCSS(true); - // Generate HTML - $html = ''; - $html .= $this->generateHTMLHeader(false); - $html .= $this->generateSheetData(); - $html .= $this->generateHTMLFooter(); - - // Default PDF paper size $paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.) @@ -102,26 +94,19 @@ class PHPExcel_Writer_PDF_DomPDF extends PHPExcel_Writer_PDF_Core implements PHP $printPaperSize = $this->getPaperSize(); } - if (isset(self::$_paperSizes[$printPaperSize])) { $paperSize = self::$_paperSizes[$printPaperSize]; } - // Create PDF $pdf = new DOMPDF(); $pdf->set_paper(strtolower($paperSize), strtolower($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()); - -// echo '
',htmlentities($html),'
'; - - $pdf->load_html($html); + $pdf->load_html( + $this->generateHTMLHeader(false) . + $this->generateSheetData() . + $this->generateHTMLFooter() + ); $pdf->render(); // Write to file diff --git a/Classes/PHPExcel/Writer/PDF/mPDF.php b/Classes/PHPExcel/Writer/PDF/mPDF.php index 4f1e6498..e8ff3201 100644 --- a/Classes/PHPExcel/Writer/PDF/mPDF.php +++ b/Classes/PHPExcel/Writer/PDF/mPDF.php @@ -67,17 +67,9 @@ class PHPExcel_Writer_PDF_mPDF extends PHPExcel_Writer_PDF_Core implements PHPEx // Set PDF $this->_isPdf = true; - // Build CSS $this->buildCSS(true); - // Generate HTML - $html = ''; - $html .= $this->generateHTMLHeader(false); - $html .= $this->generateSheetData(); - $html .= $this->generateHTMLFooter(); - - // Default PDF paper size $paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.) @@ -91,6 +83,7 @@ class PHPExcel_Writer_PDF_mPDF extends PHPExcel_Writer_PDF_Core implements PHPEx $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())) { @@ -102,12 +95,10 @@ class PHPExcel_Writer_PDF_mPDF extends PHPExcel_Writer_PDF_Core implements PHPEx $printPaperSize = $this->getPaperSize(); } - if (isset(self::$_paperSizes[$printPaperSize])) { $paperSize = self::$_paperSizes[$printPaperSize]; } - // Create PDF $pdf = new mpdf(); $pdf->_setPageSize(strtoupper($paperSize), strtolower($orientation)); @@ -119,9 +110,11 @@ class PHPExcel_Writer_PDF_mPDF extends PHPExcel_Writer_PDF_Core implements PHPEx $pdf->SetKeywords($this->_phpExcel->getProperties()->getKeywords()); $pdf->SetCreator($this->_phpExcel->getProperties()->getCreator()); -// echo '
',htmlentities($html),'
'; - - $pdf->WriteHTML($html); + $pdf->WriteHTML( + $this->generateHTMLHeader(false) . + $this->generateSheetData() . + $this->generateHTMLFooter() + ); // Write to file fwrite($fileHandle, $pdf->Output('','S')); diff --git a/Classes/PHPExcel/Writer/PDF/tcPDF.php b/Classes/PHPExcel/Writer/PDF/tcPDF.php index a69deef5..f342a654 100644 --- a/Classes/PHPExcel/Writer/PDF/tcPDF.php +++ b/Classes/PHPExcel/Writer/PDF/tcPDF.php @@ -68,16 +68,9 @@ class PHPExcel_Writer_PDF_tcPDF extends PHPExcel_Writer_PDF_Core implements PHPE // Set PDF $this->_isPdf = true; - // Build CSS $this->buildCSS(true); - // Generate HTML - $html = ''; - //$html .= $this->generateHTMLHeader(false); - $html .= $this->generateSheetData(); - //$html .= $this->generateHTMLFooter(); - // Default PDF paper size $paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.) @@ -94,7 +87,8 @@ class PHPExcel_Writer_PDF_tcPDF extends PHPExcel_Writer_PDF_Core implements PHPE // Override Page Orientation if (!is_null($this->getOrientation())) { - $orientation = ($this->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; + $orientation = ($this->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE) ? + 'L' : 'P'; } // Override Paper Size if (!is_null($this->getPaperSize())) { @@ -123,7 +117,11 @@ class PHPExcel_Writer_PDF_tcPDF extends PHPExcel_Writer_PDF_Core implements PHPE // Set the appropriate font $pdf->SetFont($this->getFont()); - $pdf->writeHTML($html); + $pdf->writeHTML( + $this->generateHTMLHeader(false) . + $this->generateSheetData() . + $this->generateHTMLFooter() + ); // Document info $pdf->SetTitle($this->_phpExcel->getProperties()->getTitle());