Permalink
Browse files

add `$marginTop` parameter on the `createIndex` method - issue #333

  • Loading branch information...
spipu committed Jul 31, 2018
1 parent bbac29f commit 34c712261327d6f053dbfcf5dc068dde311a6ffe
Showing with 26 additions and 5 deletions.
  1. +1 −0 CHANGELOG.md
  2. +3 −2 doc/bookmark.md
  3. +1 −1 examples/about.php
  4. +21 −2 src/Html2Pdf.php
@@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file.
* change all the svg tag from internal methods to new external tags
* add the extension `Core\SvgExtension`
* add locale fi - thanks to @RWAP
* add `$marginTop` parameter on the `createIndex` method - issue #333
* fix locale pt - thanks to @marcoshenzel
* fix issue on testing the filename when asking for string output
* fix issue - clean locale before PDF generation - thanks to @quimcalpe
@@ -22,7 +22,7 @@ level | 0 | Level of the bookmark, must be a positive integer. Level 0 is the ma
You can insert an index (summary) of all bookmarks automatically, using the following function :
```php
$html2pdf->createIndex($titre, $sizeTitle, $sizeBookmark, $bookmarkTitle, $displayPage, $onPage, $fontName);
$html2pdf->createIndex($titre, $sizeTitle, $sizeBookmark, $bookmarkTitle, $displayPage, $onPage, $fontName, $marginTop);
```
### parameters
@@ -35,7 +35,8 @@ $sizeBookmark | 15 | font size of the index, in mm
$bookmarkTitle | true | add a bookmark for the index, at his beginning
$displayPage | true | display the page numbers
$onPage | null | if null : at the end of the document on a new page, else on the $onPage page
$fontName | helvetica | font name to use
$fontName | null | font name to use. If null, use helvetica
$marginTop | null | margin top to use on the index page
**IMPORTANT**:
If you want the summary index on a specific page (using $onPage) you must have anticipated this page during the creation of HTML (see example below).
@@ -24,7 +24,7 @@
$content = ob_get_clean();
$html2pdf->writeHTML($content);
$html2pdf->createIndex('Sommaire', 30, 12, false, true, 2);
$html2pdf->createIndex('Sommaire', 30, 12, false, true, 2, null, '10mm');
$html2pdf->output('about.pdf');
} catch (Html2PdfException $e) {
$html2pdf->clean();
@@ -477,11 +477,30 @@ public function addFont($family, $style = '', $file = '')
* @param boolean $displayPage display the page numbers
* @param int $onPage if null : at the end of the document on a new page, else on the $onPage page
* @param string $fontName font name to use
* @param string $marginTop margin top to use on the index page
* @return null
*/
public function createIndex($titre = 'Index', $sizeTitle = 20, $sizeBookmark = 15, $bookmarkTitle = true, $displayPage = true, $onPage = null, $fontName = 'helvetica')
{
public function createIndex(
$titre = 'Index',
$sizeTitle = 20,
$sizeBookmark = 15,
$bookmarkTitle = true,
$displayPage = true,
$onPage = null,
$fontName = null,
$marginTop = null
) {
if ($fontName === null) {
$fontName = 'helvetica';
}
$oldPage = $this->_INDEX_NewPage($onPage);
if ($marginTop !== null) {
$marginTop = $this->cssConverter->convertToMM($marginTop);
$this->pdf->SetY($this->pdf->GetY() + $marginTop);
}
$this->pdf->createIndex($this, $titre, $sizeTitle, $sizeBookmark, $bookmarkTitle, $displayPage, $onPage, $fontName);
if ($oldPage) {
$this->pdf->setPage($oldPage);

0 comments on commit 34c7122

Please sign in to comment.