Skip to content

Commit

Permalink
Merge pull request #16 from tarfin-labs/margin-header-and-footer-methods
Browse files Browse the repository at this point in the history
add header and footer methods
  • Loading branch information
frkcn authored Feb 22, 2023
2 parents c1c69d6 + c715889 commit af5c9a7
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 1 deletion.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ All notable changes to `easy-pdf` will be documented in this file.

## [Unreleased]

## 2.7.0 - 2023-02-22
- Add `setMargins()` method.
- Add `setHeaderData()` method.
- Add `setHeaderMargin()` method.
- Add `setFooterData()` method.
- Add `setFooterMargin()` method.
- Add `setFooterFontSize()` method.
- Add `imagePath` constructor parameter to set `K_PATH_IMAGES` constant.

## 2.6.0 - 2023-02-16
- Add laravel 10 support.

## 2.5.1 - 2022-15-11
- Add `setPrintHeader(false)` and `setPrintFooter(false)` to delete unnecessary line in header and footer.

Expand Down
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,45 @@ You can set active page using `setPage()` method.
$pdf->setPage(1);
```

You can set margins using `setMargins()` method.
```php
// This will set margin as 10 for left, 15 for top, 20 for right
// and overwrite the default margins.
$pdf->setMargins(10, 15, 20, true);
```

You can add image to page header using `setHeaderData()` method.
```php
// $textColor and $lineColor must be RGB as array format. '[255, 255, 255]'
$pdf->setHeaderData($image, $width, $textColor, $lineColor);
```

You can set header margin using `setHeaderMargin()` method.
```php
// This will set the minimum distance between header and top page margin.
$pdf->setHeaderMargin(10);
```

You can set test and line colors of footer using `setFooterData()` method.
```php
// The first parameter is text color and the last one is line color.
$pdf->setFooterData([0, 64, 255], [0, 64, 128]);
```

You can set footer margin using `setFooterMargin()` method.
```php
// This will set the minimum distance between footer and bottom page margin.
$pdf->setFooterMargin(10);
```

You can set footer font using `setFooterFontSize()` method.
```php
// This will set the footer font size to 10.
$pdf->setFooterFontSize(10);
```

You can add

### Parsing pdf

You can parse the pdf and get the page you want.
Expand Down
91 changes: 90 additions & 1 deletion src/EasyPdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ class EasyPdf
/**
* EasyPdf constructor.
*/
public function __construct()
public function __construct(?string $imagePath = null)
{
if ($imagePath !== null) {
define('K_PATH_IMAGES', $imagePath);
}

$this->pdf = new TCPDF();
$this->pdf->setPrintHeader($this->header);
$this->pdf->setPrintFooter($this->footer);
Expand Down Expand Up @@ -150,6 +154,91 @@ public function setFont(string $font, int $size = null)
return $this;
}

/**
* Set page margins.
*
* @param float|int $left
* @param float|int $top
* @param float|int $right
* @param bool $keepMargins
* @return $this
*/
public function setMargins($left, $top, $right = null, bool $keepMargins = false)
{
$this->pdf->setMargins($left, $top, $right, $keepMargins);

return $this;
}

/**
* Add image to header.
*
* @param string $image
* @param int $width
* @param array $textColor
* @param array $lineColor
* @return $this
*/
public function setHeaderData(string $image, int $width, array $textColor = [], array $lineColor = [])
{
$this->pdf->setHeaderData($image, $width, '', '', $textColor, $lineColor);

return $this;
}

/**
* Set header margin.
*
* @param int $margin
* @return $this
*/
public function setHeaderMargin(int $margin)
{
$this->pdf->setHeaderMargin($margin);

return $this;
}

/**
* Set footer text and line colors.
*
* @param array $textColor
* @param array $lineColor
* @return $this
*/
public function setFooterData(array $textColor = [], array $lineColor = [])
{
$this->pdf->setFooterData($textColor, $lineColor);

return $this;
}

/**
* Set footer margin.
*
* @param int $margin
* @return $this
*/
public function setFooterMargin(int $margin)
{
$this->pdf->setFooterMargin($margin);

return $this;
}

/**
* Set footer font size.
*
* @param int|null $size
* @return $this
*/
public function setFooterFontSize(?int $size = null)
{
$this->pdf->setFooterFont([PDF_FONT_NAME_DATA, '', $size ?? PDF_FONT_SIZE_DATA]);

return $this;
}

/**
* Write html content.
*
Expand Down

0 comments on commit af5c9a7

Please sign in to comment.