Your company
Your address
Your Site' ;
$recipient = 'Name
Address
Zip' ;
$Invoices_footer = "We ask for a settlement of the bill within 4 days after receipt. Please transfer the full amount to::
name: name
IBAN: 132 165 4651 6464
BIC: CA56464" ;
$invoice = array (
array ( "Pruduct 1" , 1 , 40.50 ) ,
array ( "Pruduct 2" , 5 , 5.20 ) ,
array ( "Pruduct 3" , 3 , 10.00 ) ) ;
$value_added_tax = 0.0 ;
$pdfName = "Invoice_" . $bill_number . ".pdf" ;
$html = '
' . nl2br ( trim ( $invoice_header ) ) . ' |
Bill number ' . $bill_number . '
Invoice date: ' . $invoice_date . '
Delivery date: ' . $delivery_date . '
|
invoice
|
' . nl2br ( trim ( $recipient ) ) . ' |
description |
amount |
Price |
price |
' ;
$total_price = 0 ;
foreach ( $invoice as $entry ) {
$amount = $entry [ 1 ] ;
$single_price = $entry [ 2 ] ;
$price = $amount * $single_price ;
$total_price += $price ;
$html . = '
' . $entry [ 0 ] . ' |
' . $entry [ 1 ] . ' |
' . number_format ( $entry [ 2 ] , 2 , ',' , '' ) . ' Euro |
' . number_format ( $price , 2 , ',' , '' ) . ' Euro |
' ;
}
$html . = "
" ;
$html . = '
' ;
if ( $value_added_tax > 0 ) {
$erm = $total_price / ( 1 + $value_added_tax ) ;
$value_added_tax_amount = $total_price - $erm ;
$html . = '
Subtotal |
' . number_format ( $erm , 2 , ',' , '' ) . ' Euro |
value_added_tax (' . intval ( $value_added_tax * 100 ) . '%) |
' . number_format ( $value_added_tax_amount , 2 , ',' , '' ) . ' Euro |
' ;
}
$html . = '
Total: |
' . number_format ( $total_price , 2 , ',' , '' ) . ' Euro |
' ;
if ( $value_added_tax == 0 ) {
$html . = 'according to ......
' ;
}
$html . = nl2br ( $invoice_footer ) ;
// TCPDF Library load
require_once ( 'tcpdf/tcpdf.php' ) ;
$pdf = new TCPDF ( PDF_PAGE_ORIENTATION , PDF_UNIT , PDF_PAGE_FORMAT , true , 'UTF-8' , false ) ;
$pdf -> SetCreator ( PDF_CREATOR ) ;
$pdf -> SetAuthor ( $pdfAuthor ) ;
$pdf -> SetTitle ( 'Invoice ' . $bill_number ) ;
$pdf -> SetSubject ( 'Invoice ' . $bill_number ) ;
$pdf -> setHeaderFont ( Array ( PDF_FONT_NAME_MAIN , '' , PDF_FONT_SIZE_MAIN ) ) ;
$pdf -> setFooterFont ( Array ( PDF_FONT_NAME_DATA , '' , PDF_FONT_SIZE_DATA ) ) ;
$pdf -> SetDefaultMonospacedFont ( PDF_FONT_MONOSPACED ) ;
$pdf -> SetMargins ( PDF_MARGIN_LEFT , PDF_MARGIN_TOP , PDF_MARGIN_RIGHT ) ;
$pdf -> SetHeaderMargin ( PDF_MARGIN_HEADER ) ;
$pdf -> SetFooterMargin ( PDF_MARGIN_FOOTER ) ;
$pdf -> SetAutoPageBreak ( TRUE , PDF_MARGIN_BOTTOM ) ;
$pdf -> setImageScale ( PDF_IMAGE_SCALE_RATIO ) ;
$pdf -> SetFont ( 'dejavusans' , '' , 10 ) ;
$pdf -> AddPage ( ) ;
$pdf -> writeHTML ( $html , true , false , true , false , '' ) ;
$pdf -> Output ( $pdfName , 'I' ) ;
//Option 2: Save PDF in the directory:
//$pdf->Output(dirname(__FILE__).'/'.$pdfName, 'F');
//echo 'Download PDF: '.$pdfName.'';
?>