Yii2 custom size pdf
Generate custom size pdf in yii2.
The procedure to generate custom size pdf in yii2 framework can be done using yii2-mpdf extension. This comes handy when we generate different size invoices for billing.
In this example we will be generating different custom sizes pdf in the form of invoices i.e A5 (210 mm X 148mm),A6 (105mm X 148mm) ,Thermal Roll printer of width 80 mm.
Mpdf pdf output can be modified using following setting , Output will be A6 for below code:
$pdf = new Pdf([
'mode' => Pdf::MODE_UTF8,
// A6 paper format
'format' => [105, 148], // A6 custom size
// 'format' => [210, 148], // A5 custom size
// 'format' => [80, ], // Thermal roll printer
'marginLeft' => 2,
'marginRight' => false,
// if not required'marginTop' => 18,'marginBottom' => 9,'marginHeader' => false,'marginFooter' =>false ,
// portrait orientation'orientation' => Pdf::ORIENT_PORTRAIT,// stream to browser inline'destination' => Pdf::DEST_BROWSER,// your html content input'content' => $content,// format content from your own css file if needed or use the// enhanced bootstrap css built by Krajee for mPDF formatting'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',// any css to be embedded if required//'cssInline' => '.kv-heading-1{text-alogn:center ;font-size:18px}','cssInline' => 'body{font-size:11px}',// set mPDF properties on the fly'options' => ['title' => 'Print Report'],// call mPDF methods on the fly'methods' => ['SetHeader'=>false,//['Krajee Report Header'],'SetFooter'=>false,//['{PAGENO}'],] ]);view file : invoice.php
Shop Name
Address,Address Line,
Ernakulam,Kerala, Pin -66666
Ph:0484-2323232,7512121212
www.websitename.com
| Customer: UsersName ?> | Mobile: >UsersMobile ?> |
| Order: OrderReference ?> | Date: OrderDate))?> |
| Sl | Product Name | Qty | Rate | Amount |
';$serial++;}}?> | '.$serial.' | '.$item->orderLineProduct->ProductName .' | '.$item->OrderLineQty .' | '.$item->OrderLinePrice .' | '.$item->OrderLineNetAmount .' |
|
| Total | Rs OrderNetAmount ?> |
Thank you