我正在尝试通过CodeIgniter中的视图创建PDF。它适用于纯 HTML,但是当我尝试在视图中添加参数时,它会给我此错误:preg_match_all() expects parameter 2 to be string, object given
这是我的控制器的内容:
$order_data = $this->BOE_Model->get_ordercomplete_items($id);
$view_data = array('order_data' => $order_data);
if($order_data[0]['is_forward_air'] == 1){
$this->load->library('Pdf');
ob_start();
$pdf = new Pdf(PDF_PAGE_ORIENTATION, 'mm', 'A4', true, 'UTF-8', false);
$pdf->setUserName('Forex AirDrop Label');
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetTitle('Forex AirDrop Label');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING, array(0,64,255), array(0,64,128));
$pdf->setFooterData(array(0,64,0), array(0,64,128));
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// set default font subsetting mode
$pdf->setFontSubsetting(true);
// Set font
// dejavusans is a UTF-8 Unicode font, if you only need to
// print standard ASCII chars, you can use core fonts like
// helvetica or times to reduce file size.
$pdf->SetFont('helvetica', '', 14, '', true);
// Add a page
// This method has several options, check the source code documentation for more information.
$pdf->AddPage('P', 'A4');
// set text shadow effect
$pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal'));
$pdf->SetFont('helvetica', '', 10, '', true);
$html = $this->load->view('partners/pdf/forward_air', $view_data);
$pdf->writeHTML($html, true, false, true, false, '');
$path_to_pdf = 'assets/pdf/airdrop-'.$id.'.pdf';
$pdf_name = 'airdrop-'.$id.'.pdf';
$pdfdoc = $pdf->Output($path_to_pdf, "FI");
ob_end_flush();
}
而我的观点内容:
<script type="text/javascript" src="<?php echo base_url('assets/js/jquery-3.2.1.js'); ?>" ></script>
<script type="text/javascript" src="<?php echo base_url('assets/js/partners/connectcode-javascript-code128auto.js?v='.VER_NO); ?>" ></script>
<?php
$counter = 0;
foreach($order_data AS $get_order):
$ctyloc = $get_order['City'].(strlen($get_order['Locality']) > 0? ', '.$get_order['Locality']:'');
$drs = $get_order['AddressLine'].' '.$ctyloc.', '.$get_order['State'].', '.$get_order['ZipCode'];
?>
<table style=" margin-bottom: 10px;" >
<tr>
<td style=" padding-left: 0px;" class="fx-content" >
<img alt="Forexcargo" src="http://forexcargo.us/wp-content/uploads/2016/12/Forex-Cargo-Website-Logo.png"><br>
<div style="margin-left: 10px; margin-top:10px; line-height: 110%;">
<label class=c_name><?php echo $get_order['buName']; ?></label> - <label class="lname"><?php echo $get_order['Name_Long']; ?></label><br>
<span class="address1"><?php echo $get_order['buAddress1']; ?></span><br><span class="address2"><?php echo $get_order['buAddress2']; ?></span><br>
<span class="email-phone"><?php echo $get_order['buEmail'].' '.$get_order['buPhone']; ?></span>
</div>
</td>
<td style="vertical-align: top;" class="rc-content" >
<div style="margin-left: 20px; margin-top:50px; line-height: 110%;">
<label class=c_name><?php echo $get_order['FirstName'].' '.$get_order['LastName']; ?></label><label class="lname"></label><br>
<span class="address1"><?php echo $drs; ?></span><br>
<span class="email-phone"><?php echo $get_order['Email'].' '.$get_order['Phone']; ?></span>
</div>
</td>
</tr>
</table>
<script>
if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1){
bcode = DrawHTMLBarcode_Code128Auto('<?php echo $get_order['BoxNumber']; ?>',"yes","in",0,5,0.75,"bottom","left","","black","white");
} else {
bcode = DrawHTMLBarcode_Code128Auto('<?php echo $get_order['BoxNumber']; ?>',"yes","in",0,4,0.75,"bottom","left","","black","white");
}
$('div.for_barcode_<?php echo $counter; ?>').html(bcode);
</script>
<div class="for_barcode_<?php echo $counter; ?>" style="width:5in;"></div>
<?php
$counter++;
endforeach;
?>
我尝试直接在控制器中执行内容,但我找不到包含javascript文件的方法,所以我决定坚持使用视图。我可能做错了什么?
通过观察,我发现您必须将布尔值 TRUE 作为第三个参数传递。 $html = $this->load->view('partners/pdf/forward_air', $view_data,TRUE(;