我正在尝试将数组输出到xml文件和pdf文件。我成功使用xml文件,但使用FPDF的pdf文件不成功。 pdf输出只是一个空白的pdf文件。
这是我的代码:
$invoice = array(
'invoice' => array(
'name' => $customerInfo['name'],
'lines' => $lineItem,
'optional' => array(
'orderNo' => $order_id,
'orderDate' => date('d.m.y'),
'recipientNo' => $order_id,
'address1' => $customerInfo['billingaddress1'],
'country' => $customerInfo['billcountry'],
'email' => $customerInfo['billemail'],
'shipment' => array(
'emailaddresses' => array(
'email' => $customerInfo['billemail']
),
)
)
)
);
include 'libs/helper.php';
$xmlData = MyxmlHelper::arrayToXml($invoice, new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><invoices/>'));
$wp_upload_dir = wp_upload_dir();
$xml_file = $wp_upload_dir['path'].'/invoice.xml';
file_put_contents($xml_file, $xmlData);
require 'libs/fpdf17/fpdf.php';
$pdf_file = $wp_upload_dir['path'].'/invoice.pdf';
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','',8);
$pdf->Write(5,$invoice);
$pdf->Output($pdf_file,'F');