PDF Invoice Using PHP Within A Minute
This post all about generate PDF invoice using PHP. Its very simple and 2 mins of works. I have seen many of our PHP developers are facing problem converting html to pdf invoice generation, here I have given very simple example with code for invoice generation in pdf using core PHP.
We can Generate PDF Invoice in PHP with many ways, But I think html2pdf library is easy and good to present. More import features you will get here static footer section. here you can add some information about your company or organization.
Here is the below example.
Step-1: Download the pdf library. Click here
Step-2: After Download change the folder name as pdf. and upload it in your project root folder.
Step-3: Add this library and follow this HTML code Below.
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
<?php /** * HTML2PDF Librairy - example * * HTML => PDF convertor * distributed under the LGPL License * * @author Laurent MINGUET <webmaster@html2pdf.fr> * * isset($_GET['vuehtml']) is not mandatory * it allow to display the result in the HTML format */ // get the HTML ob_start(); session_start(); //include(dirname(__FILE__).'/res/exemple01.php'); ?> <page> <style> table { border-collapse:collapse; width:100%; font-size:14px;margin-top: 10px; } .left{ float: left; } td.w-10{ width: 10%; } td.w-40{ width: 40%; } td.w-100{ width: 100%; } td.w-33{ width: 33%; } table, td, th { border:2px solid #000; } th{ font-weight:normal; text-align:center; padding:5px 5px 0px 5px; background-repeat:repeat-x; height:25px;font-size: 16px;font-weight: bold; border:1px solid #000;} td {padding:16px 3px 3px 3px;border:1px solid #000; } @frame footer { -pdf-frame-content: footerContent; bottom: 2cm; margin-left: 1cm; margin-right: 1cm; border: none !important; } </style> <div class="row"> <div class="col-12 "> <img src="http://freeonlineprojects.com/wp-content/themes/freeonlineprojects/images/logo1.png" align="left" height="100" width="300" /> <h3 class="text-center po" align='center' style='text-transform: uppercase; font-weight: bolder; color:#887d7d; margin-top: 130px;clear: both;'>Tax Invoice</h3> <br> <div class="col-lg-8 col-md-8 "></div> <div class="col-lg-4 col-md-4"> <table style="width:100%;" align='right'> <tr> <td>Invoice No: </td> <td><span class="editcontent">123344</span></td> </tr> <tr> <td> Booking Date: </td> <td><span class="editcontent">12/12/20XX</span></td> </tr> </table> </div> </div> </div> <table class="table"> <thead > <tr> <th align="left" style=" border: 1px solid;">Customer Info </th> </tr> </thead> <tbody > <tr> <td>My Customer<br><br>New Bus stand,plot-23/2/2<br>Mobile:9090XXXXX,8978XXXXX</td> </tr> </tbody> </table> <table class="table table-bordered" style=" border: 1px solid;"> <thead> <tr style="text-align: center; border: 1px solid;"> <th style="text-align: center;"># </th> <th style="width: 25%" style="text-align: center;">Item# </th> <th style="text-align: center;">Qty </th> <th style="text-align: center;">No. Days </th> <th style="text-align: center;">Unit Price </th> <th style="text-align: center;">Total Price </th> </tr> </thead> <tbody> <tr style="text-align: center;"> <td>1</td> <td>2222222</td> <td>3</td> <td>1</td> <td>1000</td> <td>3000</td> </tr> <tr> <td></td> <td>***No item(s) exists after this line***</td> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td colspan="4"></td> <td >Sub Total</td> <td >3000</td> </tr> <tr> <td colspan="4"></td> <td >GST (18%)</td> <td >360</td> </tr> <tr> <td colspan="4"></td> <td >Total With GST</td> <td >3600</td> </tr> <tr> <td colspan="4"></td> <td >Advance Amount</td> <td >2000</td> </tr> <tr> <td colspan="4"></td> <td >Due Amount</td> <td >1360</td> </tr> </tbody> </table> <table class="table"> <thead > <tr> <th align="left" style="width: 50%">Company Details </th> <th align="left" style="width: 50%">Authorised Signatory </th> </tr> </thead> <tbody > <tr> <td>Free Online Projects <br/> HSDFC, XXXXXXXX<br/> Current A/c no : 5555XXXXXX<br/> IFSC CODE : HDFCXXXXXXX<br/> GST : SSSSXXXXXXX<br/> PAN : SSSCCCXXXXX :<br/> </td> <td>My Customer<br></td> </tr> </tbody> </table> <!-- <div class="row"> <div class="col-lg-12"> <h4>Terms & Conditions</h4> <ol> <li>Payment Terms: 30 days from delivery</li> <li>Enter this order in accordance with the prices, terms, delivery method, and specifications listed above.</li> <li>Please notify us immediately if you are unable to ship as specified.</li> </ol> </div> </div> --> <br> <br> <br> <!-- <table width="30%" style="float: left; text-align: center; border: none;" align="left"> <tbody width='30%' style="border: none;"> <tr> <td style="width: 33%; border: none;">Sales coordinator<br> Abdul mohsin</td> <td style="width: 33%;border: none;">country Manager<br>Khalid Akhter</td> <td style="width: 33%;border: none;">Finance Manager<br>Hafiz ahmed</td> </tr> </tbody> </table> --> <page_footer> <div class="page_footer" style="border: none"> <div> <div style="width: 100%; text-align: center; color:#758DA6"> freeonlineprojects, some address,pin-76XXXX, phone:9000000XXX </div> </div> </div> </page_footer> </page> <?php $content = ob_get_clean(); // convert in PDF require_once(dirname(__FILE__).'/pdf/html2pdf.class.php'); try { $html2pdf = new HTML2PDF('P', 'A4', 'fr'); $html2pdf->writeHTML($content); $html2pdf->Output('Invoice'.'.pdf'); } catch(HTML2PDF_exception $e) { echo $e; exit; } |
Thanks for reading this blog, if you have any doubt for generating invoice pdf in core PHP please comment below. I will try to solve your issues.