我在三件事上需要html2pdf的帮助:
UTF-8
标头,但不适用于法语字符,它显示InSuit SÀRL
>而不是> InSuit SÀRL
我已经尝试了很多选择,但似乎没有任何作用。
我将在此处附加我的代码,如果有人可以帮助我,我非常感谢您的帮助。
<?php
require __DIR__.'/vendor/autoload.php';
use Spipu\Html2Pdf\Html2Pdf;
////////////***** LOGO IMAGE ******\\\\\\\\\\\\
$logo = $inv_info['logo'];
$output = "image.jpg";
base64_to_jpeg($logo,$output);
$logo = $output;
//function to convert images
function base64_to_jpeg($base64_string, $output_file) {
// open the output file for writing
$ifp = fopen( $output_file, 'wb' );
// split the string on commas
// $data[ 0 ] == "data:image/png;base64"
// $data[ 1 ] == <actual base64 string>
$data = explode( ',', $base64_string );
// we could add validation here with ensuring count( $data ) > 1
fwrite( $ifp, base64_decode( $data[ 1 ] ) );
// clean up the file resource
fclose( $ifp );
return $output_file;
}
////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\
//$html2pdf = new Html2Pdf();
$html2pdf = new \Spipu\Html2Pdf\Html2Pdf('P', 'A4', 'fr',true,'UTF-8',array(0,0,0,0));
//setting the default font
//$html2pdf->setDefaultFont('Arial');
$html2pdf->writeHTML('
<div class="logo_container" style="position:absolute,'.$add_margins.',margin-left:10px; ">
<img src="'.$logo.'" style="width:100px;height:100px;margin-bottom:-50px;margin-top:50px;margin-left:40px;border-radius:100px !important" />
</div>
<div flex style="margin-top:20px;,'.$add_margins.'">
<h1 style="'.$align_right.';"> <strong>'.strtoupper($invoice_title).'</strong></h1>
</div>');
$html2pdf->writeHTML('<div style="'.$align_right.','.$add_margins.'; font-size:14px;margin-top:-10px;">
<label># '.$invoice_nr.'</label> </div>');
//company name
$html2pdf->writeHTML('<table style="'.$add_margins.'">
<tr>
<td><br /></td>
</tr>
<tr style="padding-top:50px">
<td style="width:350px;"><strong>'.$cp_name.'</strong></td>
<td '.$header_right_align.'><strong>IBAN:</strong></td>
<td >'.$iban.'</td>
</tr>
<tr>
<td>'.$cp_address.'</td>
<td '.$header_right_align.'> <strong>CCP:</strong> </td>
<td style="">'.$ccp.'</td>
</tr>
<tr>
<td >'.$cp_zip_city.'</td>
<td '.$header_right_align.'><strong>SWIFT/BIC:</strong></td>
<td>'.$swift.'</td>
</tr>
</table>');
//client's name
$html2pdf->writeHTML(
'<table style="'.$add_margins.'; margin-top:80px !important;">
<tr>
<td style="width:300px; color:rgb(150, 150, 150)" colspan="3"> À l\'attention de:</td>
</tr>
<tr>
<td style="width:350px;" rowspan="2">
<div ><strong>'.$client_name.'</strong></div>
<div >'.$client_address.' </div>
<div >'.$zip_city.'</div>
</td>
<td '.$header_right_align.'><strong>Date:</strong></td>
<td>'.date("d/m/Y" ,strtotime($bill_date)).'</td>
</tr>
<tr>
<td '.$header_right_align.'><strong>Date d\'expiration:</strong></td>
<td>'.date("d/m/Y" ,strtotime($due_date)).'</td>
</tr>
<tr>
<td coslpan="2" ></td>
<td '.$header_right_align.'>Montant en notre faveur:</td>
<td> '.$currency.' '.number_format($ttc,2).'</td>
</tr>
</table>');
$html2pdf->writeHTML('
<table style="margin-top:20px;'.$add_margins.'; background:rgb(46, 46, 46); color:#FFF;padding:2px;">
<tr>
<td style="width:200px;">Libellé</td> <td style="width:50px;">Qtté</td>
<td style="width:100px;">Base</td>
<td style="width:50px;">TVA</td>
<td style="width:100px;">Montant TVA</td>
<td style="width:150px;">Montant Total</td>
</tr>
</table>');
foreach ($json['inv_items'] as $inv_items) {
// code...
$libelle = str_replace("\n","<br />",$inv_items['description']);
$qtty = $inv_items['quantity'];
$base = $inv_items['rate'];
$baseXqtty = $qtty*$base;
$vat = $inv_items['tva'];
$vat_amount = $baseXqtty-($baseXqtty*$vat/100);
$vat_amount=$baseXqtty-$vat_amount;
$total_amount = ($qtty*$base)+$vat_amount;
$subtotal += $baseXqtty-($baseXqtty*$discount/100);
$totalBrut += $baseXqtty;
if($discount>0){
$tvaNoDiscount = $totalTVA+$vat_amount;
$totalTVA = $tvaNoDiscount - ($vat_amount*$discount/100);
}
else{
$totalTVA +=$vat_amount;
}
$html2pdf->writeHTML('<table style="'.$add_margins.';font-size:12px;">
<tr>
<td style="width:200px;">'.$libelle.'</td>
<td style="width:50px;" align="right">'.$qtty.'</td>
<td style="width:100px;" align="right">'.$base.' '.$currency.'</td>
<td style="width:50px;" align="right">'.$vat.'%</td>
<td style="width:100px;" align="right">'.number_format((float)$vat_amount, 2, '.', '').' '.$currency.'</td>
<td style="width:150px;" align="right">'.number_format((float)$baseXqtty, 2, '.', '').' '.$currency.'</td>
</tr>
</table>');
}
//$ttc = $totalBrut+$totalTVA;
$implodedTTC = wordwrap($ttc,1,'<span style="width:3px;color:#FFFF;background:#FFFF"> </span>',true);
$totalTTC = str_replace(".","<label style='color:#FFF;font-size:16px;'>__</label>",$implodedTTC);
// numero iban & dates
$html2pdf->writeHTML('
<table style="'.$add_margins.';position:absolute; bottom:500;margin-left:100px;">
<tr>
<td style="width:500px;text-align:right;"><strong>Total Brut HT:</strong></td>
<td>'.$currency.'</td>
<td style="width:100px; text-align:right">'.number_format($totalBrut,2).'</td>
</tr>
<tr>
<td style="width:500px;text-align:right;"><strong>Rabais:</strong></td>
<td>%</td>
<td style="width:100px; text-align:right">'.number_format($discount).'</td>
</tr>
<tr>
<td style="width:500px;text-align:right;"><strong>Soustotal:</strong></td>
<td>'.$currency.'</td>
<td style="width:100px; text-align:right">'.number_format($subtotal,2).'</td>
</tr>
<tr>
<td style="width:500px;text-align:right;"><strong>TVA:</strong></td>
<td>'.$currency.'</td>
<td style="width:100px; text-align:right;padding-bottom:8px;">'.number_format($totalTVA,2).'</td>
</tr>
<tr>
<td style="padding-top:20px; width:500px;text-align:right;"><strong>Total TTC:</strong></td>
<td style="padding-top:20px;">'.$currency.'</td>
<td style="padding-top:12px; width:100px; text-align:right;border-top:1px solid #0000;">'.number_format($ttc,2).'</td>
</tr>
</table>');
//here we have to change fonts
//$html2pdf->setDefaultFont('OCR-B 10 BT');
//BV FORM *******************************************
$html2pdf->writeHTML('<page_footer style="">
<table style="margin-top:-360px;margin-left:10px;font-size:12px;">
<tr>
<td style="width:220px;">'.$cp_name.'</td>
<td style="width:240px;">'.$cp_name.'</td>
<td> Facture #InS064</td>
</tr>
<tr>
<td>'.$cp_zip_city.'</td>
<td>'.$cp_zip_city.'</td>
<td></td>
</tr>
<tr>
<td style="padding-top:10px;">'.$iban.'</td>
<td style="padding-top:10px;">'.$iban.'</td>
<td></td>
</tr>
<tr>
<td style="padding-top:70px;text-align:right;padding-right:25px;">'.$ccp.'</td>
<td style="padding-top:70px;text-align:right;padding-right:28px">'.$ccp.'</td>
<td></td>
</tr>
<tr>
<td style="padding-top:12px;font-size:20px;width:80px; text-align:right;padding-right:25px;">'.$totalTTC.'</td>
<td style="margin-top:1px;padding-top:-10px; font-size:20px;text-align:right;padding-right:32px;">'.$totalTTC.'</td>
<td style="padding-top:-6px;padding-left:-5px;">'.$client_name.'</td>
</tr>
<tr>
<td style="padding-top:25px;">'.$client_name.'</td>
<td></td>
<td style="padding-top:-44px;padding-left:-5px;">'.$zip_city.'</td>
</tr>
<tr>
<td style="padding-top:10px;">'.$zip_city.'</td>
<td></td>
<td></td>
</tr>
</table>
</page_footer>');
if($terms!=NULL || sizeof($terms)>0){
$html2pdf->writeHTML("<page>
<page_header>
<table style='".$add_margins.";'>
<tr>
<td style='width:500px;color:rgb(170, 170, 170)'><h3>".$invoice_title."<br />#".$invoice_nr."</h3></td>
<td style='width:200px' align='right'>".$cp_city.", le ".$bill_date."</td>
</tr>
</table>
</page_header>
<div style='margin-top:100px;".$add_margins."'>
<h2 style='color:rgb(98, 98, 98)'>Termes & Conditions Générales</h2><p>".$terms."</p>
</div></page>");
}
//outputing the file
$html2pdf->output();
?>