phpexcel 匯出pdf檔案亂碼
代碼過程是,讀模數板檔案template.xls。寫入對應內容,匯出pdf檔案。template.xls檔案內容帶有表格和日文。 個人認為是沒有字型的原因,但是如何對應,望大蝦告知!!!
require_once 'excel/PHPExcel.php';
$objPHPExcel = PHPExcel_IOFactory::load( "template.xls" );
$objPHPExcel->setActiveSheetIndex(0);
$objWorksheet = $objPHPExcel->getActiveSheet();
//寫內容
$objWorksheet->getCell("C1")->setValue("test");
//假片
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('stamp');
$objDrawing->setDescription("aaaa");
$objDrawing->setPath("images/p1.jpg");
$objDrawing->setCoordinates('M1');
$objDrawing->setOffsetX(25);
$objDrawing->setRotation(36);
$objDrawing->setHeight(73);
$objDrawing->getShadow()->setVisible(true);
$objDrawing->getShadow()->setDirection(45);
$objDrawing->setWorksheet($objWorksheet);
$objWorksheet->setTitle('Simple');
ob_end_clean();
header('Content-Type: application/pdf');
header('Content-Disposition: attachment;filename="detail.pdf"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF');
$objWriter->save('php://output');
exit;
------解決思路----------------------
確定內容文字是UTF-8編碼嗎?如果不是就要用iconv轉換編碼。
------解決思路----------------------
phpexcel產生pdf有一個重大的缺陷:excel中如果有圖片,產生的pdf裡不會保留,所以你用這個來產生pdf檔案不是最好的方案!