forked from mpdf/mpdf-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample41_MPDFI_template.php
51 lines (37 loc) · 960 Bytes
/
example41_MPDFI_template.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
$path = (getenv('MPDF_ROOT')) ? getenv('MPDF_ROOT') : __DIR__;
require_once $path . '/vendor/autoload.php';
class Pdf extends \Mpdf\Mpdf
{
public function clipRect($x, $y, $width, $heigth)
{
$this->pages[$this->page] .= $this->_setClippingPath($x, $y, $width, $heigth);
}
public function endClip()
{
$this->pages[$this->page] .= ' Q ';
}
}
$mpdf = new Pdf([
'margin_left' => 15,
'margin_right' => 15,
'margin_top' => 57,
'margin_bottom' => 16,
'margin_header' => 9,
'margin_footer' => 9
]);
$mpdf->SetDisplayMode('fullpage');
$mpdf->SetCompression(false);
// Add First page
$pagecount = $mpdf->SetSourceFile('pdf/sample_basic.pdf');
$crop_x = 50;
$crop_y = 50;
$crop_w = 100;
$crop_h = 100;
$tplIdx = $mpdf->ImportPage(2);
$mpdf->AddPage();
$mpdf->clipRect($crop_x, $crop_y, $crop_w, $crop_h);
$mpdf->useTemplate($tplIdx);
$mpdf->endClip();
$mpdf->Rect($crop_x, $crop_y, $crop_w, $crop_h);
$mpdf->Output('newpdf.pdf', 'I');