@@ -170,6 +170,12 @@ class Pdf extends Component
170
170
*/
171
171
protected $ _css ;
172
172
173
+ /**
174
+ *
175
+ * @var array Array of file-pathes that should be attached to the generated PDF
176
+ */
177
+ protected $ _pdfAttachements ;
178
+
173
179
/**
174
180
* @inherit doc
175
181
*/
@@ -280,7 +286,21 @@ public function getCss()
280
286
$ css .= $ this ->cssInline ;
281
287
return $ css ;
282
288
}
283
-
289
+
290
+ /**
291
+ * @return array Array of attachements
292
+ */
293
+ public function getPdfAttachements (){
294
+ return $ this ->_pdfAttachements ;
295
+ }
296
+
297
+ /**
298
+ * add an PDF to attach to the generated PDF
299
+ * @param string $filePath
300
+ */
301
+ public function addPdfAttachement ($ filePath ){
302
+ $ this ->_pdfAttachements [] = $ filePath ;
303
+ }
284
304
/**
285
305
* Configures mPDF options
286
306
* @param array the mPDF configuration options entered as a `$key => value`
@@ -331,15 +351,40 @@ public function output($content = '', $file = '', $dest = self::DEST_BROWSER)
331
351
{
332
352
$ api = $ this ->api ;
333
353
$ css = $ this ->css ;
354
+ $ pdfAttachements = $ this ->getPdfAttachements ();
334
355
if (!empty ($ css )) {
335
356
$ api ->WriteHTML ($ css , 1 );
336
357
$ api ->WriteHTML ($ content , 2 );
337
358
} else {
338
359
$ api ->WriteHTML ($ content );
360
+ }
361
+
362
+ if ($ pdfAttachements ){
363
+ $ api ->SetImportUse ();
364
+ $ api ->SetHeader (null );
365
+ $ api ->SetFooter (null );
366
+ foreach ($ pdfAttachements as $ attachement ){
367
+ $ this ->writePdfAttachement ($ api , $ attachement );
368
+ }
339
369
}
370
+
340
371
return $ api ->Output ($ file , $ dest );
341
372
}
342
-
373
+
374
+ /**
375
+ * appends the given attachement to the generated PDF
376
+ * @param mPDF $api
377
+ * @param String $attachement
378
+ */
379
+ private function writePdfAttachement ($ api , $ attachement ){
380
+ $ pageCount = $ api ->SetSourceFile ($ attachement );
381
+ for ($ i =1 ; $ i <=$ pageCount ; $ i ++){
382
+ $ api ->AddPage ();
383
+ $ templateId = $ api ->ImportPage ($ i );
384
+ $ api ->UseTemplate ($ templateId );
385
+ }
386
+ }
387
+
343
388
/**
344
389
* Parse the format automatically based on the orientation
345
390
*/
0 commit comments