Versión 1 (Guillermo Zdanowicz, 24/03/2016 01:09)
1 | 1 | Guillermo Zdanowicz | h1. PDF |
---|---|---|---|
2 | 1 | Guillermo Zdanowicz | |
3 | 1 | Guillermo Zdanowicz | Referencia:http://www.bsourcecode.com/yiiframework2/create-pdf-files-using-mpdf-in-yiiframework-2-0/ |
4 | 1 | Guillermo Zdanowicz | |
5 | 1 | Guillermo Zdanowicz | |
6 | 1 | Guillermo Zdanowicz | <pre> |
7 | 1 | Guillermo Zdanowicz | "require": { |
8 | 1 | Guillermo Zdanowicz | "php": ">=5.4.0", |
9 | 1 | Guillermo Zdanowicz | "yiisoft/yii2": "*", |
10 | 1 | Guillermo Zdanowicz | "yiisoft/yii2-bootstrap": "*", |
11 | 1 | Guillermo Zdanowicz | "yiisoft/yii2-swiftmailer": "*", |
12 | 1 | Guillermo Zdanowicz | "mpdf/mpdf":"*" |
13 | 1 | Guillermo Zdanowicz | }, |
14 | 1 | Guillermo Zdanowicz | </pre> |
15 | 1 | Guillermo Zdanowicz | |
16 | 1 | Guillermo Zdanowicz | |
17 | 1 | Guillermo Zdanowicz | <pre> |
18 | 1 | Guillermo Zdanowicz | composer update |
19 | 1 | Guillermo Zdanowicz | |
20 | 1 | Guillermo Zdanowicz | </pre> |
21 | 1 | Guillermo Zdanowicz | |
22 | 1 | Guillermo Zdanowicz | Agregar en ‘vendor/composer/autoload_namespaces.php’ la linea en el arreglo |
23 | 1 | Guillermo Zdanowicz | |
24 | 1 | Guillermo Zdanowicz | <pre> |
25 | 1 | Guillermo Zdanowicz | 'mPDF' => array($vendorDir . '/mpdf/mpdf'), |
26 | 1 | Guillermo Zdanowicz | |
27 | 1 | Guillermo Zdanowicz | </pre> |
28 | 1 | Guillermo Zdanowicz | |
29 | 1 | Guillermo Zdanowicz | En el controlador SiteController.php |
30 | 1 | Guillermo Zdanowicz | |
31 | 1 | Guillermo Zdanowicz | <pre> |
32 | 1 | Guillermo Zdanowicz | ............... |
33 | 1 | Guillermo Zdanowicz | use app\models\ContactForm; |
34 | 1 | Guillermo Zdanowicz | use mPDF; |
35 | 1 | Guillermo Zdanowicz | class SiteController extends Controller |
36 | 1 | Guillermo Zdanowicz | { |
37 | 1 | Guillermo Zdanowicz | ............... |
38 | 1 | Guillermo Zdanowicz | public function actionCreateMPDF(){ |
39 | 1 | Guillermo Zdanowicz | $mpdf=new mPDF(); |
40 | 1 | Guillermo Zdanowicz | $mpdf->WriteHTML($this->renderPartial('mpdf')); |
41 | 1 | Guillermo Zdanowicz | $mpdf->Output(); |
42 | 1 | Guillermo Zdanowicz | exit; |
43 | 1 | Guillermo Zdanowicz | //return $this->renderPartial('mpdf'); |
44 | 1 | Guillermo Zdanowicz | } |
45 | 1 | Guillermo Zdanowicz | public function actionSamplePdf() { |
46 | 1 | Guillermo Zdanowicz | $mpdf = new mPDF; |
47 | 1 | Guillermo Zdanowicz | $mpdf->WriteHTML('Sample Text'); |
48 | 1 | Guillermo Zdanowicz | $mpdf->Output(); |
49 | 1 | Guillermo Zdanowicz | exit; |
50 | 1 | Guillermo Zdanowicz | } |
51 | 1 | Guillermo Zdanowicz | public function actionForceDownloadPdf(){ |
52 | 1 | Guillermo Zdanowicz | $mpdf=new mPDF(); |
53 | 1 | Guillermo Zdanowicz | $mpdf->WriteHTML($this->renderPartial('mpdf')); |
54 | 1 | Guillermo Zdanowicz | $mpdf->Output('MyPDF.pdf', 'D'); |
55 | 1 | Guillermo Zdanowicz | exit; |
56 | 1 | Guillermo Zdanowicz | } |
57 | 1 | Guillermo Zdanowicz | </pre> |