Skip to content

Commit

Permalink
Support page margin in mPDF
Browse files Browse the repository at this point in the history
  • Loading branch information
Bird87ZA authored and guillaume-ro-fr committed Jun 12, 2019
1 parent c2840c2 commit 7e12307
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
- Fix print area parser for XLSX reader - [#734](https://github.com/PHPOffice/PhpSpreadsheet/pull/734)
- Support overriding `DefaultValueBinder::dataTypeForValue()` without overriding `DefaultValueBinder::bindValue()` - [#735](https://github.com/PHPOffice/PhpSpreadsheet/pull/735)
- Mpdf export can exceed pcre.backtrack_limit - [#637](https://github.com/PHPOffice/PhpSpreadsheet/issues/637)
- Support page margin in mPDF - [#750](https://github.com/PHPOffice/PhpSpreadsheet/issues/750)

## [1.5.0] - 2018-10-21

Expand Down
20 changes: 19 additions & 1 deletion src/PhpSpreadsheet/Writer/Pdf/Mpdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ public function save($pFilename)
$ortmp = $orientation;
$pdf->_setPageSize(strtoupper($paperSize), $ortmp);
$pdf->DefOrientation = $orientation;
$pdf->AddPage($orientation);
$pdf->AddPageByArray([
'orientation' => $orientation,
'margin-left' => $this->inchesToMm($this->spreadsheet->getActiveSheet()->getPageMargins()->getLeft()),
'margin-right' => $this->inchesToMm($this->spreadsheet->getActiveSheet()->getPageMargins()->getRight()),
'margin-top' => $this->inchesToMm($this->spreadsheet->getActiveSheet()->getPageMargins()->getTop()),
'margin-bottom' => $this->inchesToMm($this->spreadsheet->getActiveSheet()->getPageMargins()->getBottom()),
]);

// Document info
$pdf->SetTitle($this->spreadsheet->getProperties()->getTitle());
Expand All @@ -91,4 +97,16 @@ public function save($pFilename)

parent::restoreStateAfterSave($fileHandle);
}

/**
* Convert inches to mm.
*
* @param float $inches
*
* @return float
*/
private function inchesToMm($inches)
{
return $inches * 25.4;
}
}

0 comments on commit 7e12307

Please sign in to comment.