1
1
<?php
2
2
3
+ use setasign \Fpdi \Fpdi ;
4
+
3
5
/**
4
6
* PDFMerger created by Jarrod Nettles December 2009
5
7
* jarrod@squarecrow.com
6
8
*
7
- * v1.0.2
9
+ * v1.0.5
8
10
*
9
11
* Class for easily merging PDFs (or specific pages of PDFs) together into one. Output to a file, browser, download, or return as a string.
10
12
* Unfortunately, this class does not preserve many of the enhancements your original PDF might contain. It treats
14
16
* If you put pages 12-14 before 1-5 then 12-15 will be placed first in the output.
15
17
*
16
18
*
17
- * Uses FPDI 1.3.1 from Setasign
18
- * Uses FPDF 1.6 by Olivier Plathey with FPDF_TPL extension 1.1.3 by Setasign
19
+ * Uses FPDI ^2.0 from Setasign
20
+ * Uses FPDF 1.82.1 by Fpdf
19
21
*
20
22
* Both of these packages are free and open source software, bundled with this class for ease of use.
21
23
* They are not modified in any way. PDFMerger has all the limitations of the FPDI package - essentially, it cannot import dynamic content
22
24
* such as form fields, links or page annotations (anything not a part of the page content stream).
25
+ *
26
+ * Updated by Andrey Grin January 2021
23
27
*
24
28
*/
25
29
class PDFMerger
@@ -32,12 +36,6 @@ class PDFMerger
32
36
*/
33
37
public function __construct ()
34
38
{
35
- if (!class_exists ("FPDF " )) {
36
- require_once ('fpdf/fpdf.php ' );
37
- }
38
- if (!class_exists ("FPDI " )) {
39
- require_once ('fpdi/fpdi.php ' );
40
- }
41
39
}
42
40
43
41
/**
@@ -73,7 +71,7 @@ public function merge($outputmode = 'browser', $outputpath = 'newfile.pdf')
73
71
{
74
72
if (!isset ($ this ->_files ) || !is_array ($ this ->_files )): throw new exception ("No PDFs to merge. " ); endif ;
75
73
76
- $ fpdi = new FPDI ;
74
+ $ fpdi = new Fpdi () ;
77
75
78
76
//merger operations
79
77
foreach ($ this ->_files as $ file ) {
@@ -87,18 +85,18 @@ public function merge($outputmode = 'browser', $outputpath = 'newfile.pdf')
87
85
for ($ i = 1 ; $ i <= $ count ; $ i ++) {
88
86
$ template = $ fpdi ->importPage ($ i );
89
87
$ size = $ fpdi ->getTemplateSize ($ template );
90
- $ orientation = ($ size ['h ' ] > $ size ['w ' ]) ? 'P ' : 'L ' ;
88
+ $ orientation = ($ size ['height ' ] > $ size ['width ' ]) ? 'P ' : 'L ' ;
91
89
92
- $ fpdi ->AddPage ($ orientation , array ($ size ['w ' ], $ size ['h ' ]));
90
+ $ fpdi ->AddPage ($ orientation , array ($ size ['width ' ], $ size ['height ' ]));
93
91
$ fpdi ->useTemplate ($ template );
94
92
}
95
93
} else {
96
94
foreach ($ filepages as $ page ) {
97
95
if (!$ template = $ fpdi ->importPage ($ page )): throw new exception ("Could not load page ' $ page' in PDF ' $ filename'. Check that the page exists. " ); endif ;
98
96
$ size = $ fpdi ->getTemplateSize ($ template );
99
- $ orientation = ($ size ['h ' ] > $ size ['w ' ]) ? 'P ' : 'L ' ;
97
+ $ orientation = ($ size ['height ' ] > $ size ['width ' ]) ? 'P ' : 'L ' ;
100
98
101
- $ fpdi ->AddPage ($ orientation , array ($ size ['w ' ], $ size ['h ' ]));
99
+ $ fpdi ->AddPage ($ orientation , array ($ size ['width ' ], $ size ['height ' ]));
102
100
$ fpdi ->useTemplate ($ template );
103
101
}
104
102
}
0 commit comments