0
我必須生成圖像的PDF。我曾嘗試下面的代碼Zend_Pdf:圖像路徑數組問題
public function getPdf($paths)
{
try {
$pdf = new Zend_Pdf();
for($i=0; $i<5; $i++)
{
$page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
$image = Zend_Pdf_Image::imageWithPath($paths[$i]);
$page->drawImage($image, 20, 20, 50, 46);
$pdf->pages[] = $page;
}
$pdf->save('document.pdf');
echo 'SUCCESS: Document saved!';
} catch (Zend_Pdf_Exception $e) {
die ('PDF error: ' . $e->getMessage());
} catch (Exception $e) {
die ('Application error: ' . $e->getMessage());
}
}
請注意,$路徑中包含像C正確的物理路徑的數組:/wamp/www/magento1.7/media/catalog/product/cache/1/small_image/ 9df78eab33525d08d6e5fb8d27136e95/p/o/portf1.jpg ....現在的問題是,它無法創建PDF並拋出異常說:「PDF錯誤:無法創建圖像資源。文件未找到」。任何人都可以幫助我,或只是指出這段代碼有什麼問題。
不,它生成PDF與圖像,當我給C:/wamp/www/magento1.7/media/catalog/product/cache/1/small_image/9df78eab33525d08d6e5fb8d27136e95 /p/o/portf1.jpg靜態地爲$ image = Zend_Pdf_Image :: imageWithPath(); ... – Nida
你可以請var_dump $ path變量,並用輸出更新答案。 –
它顯示如陣列 0 => string'C:/wamp/www/magento1.7/media/catalog/product/cache/1/small_image/9df78eab33525d08d6e5fb8d27136e95/p/o/portf1.jpg'(length = 112) 1 => string'C:/wamp/www/magento1.7/media/catalog/product/cache/1/small_image/9df78eab33525d08d6e5fb8d27136e95/l/a/landf1.jpg'(length = 112) array 0 =>字符串'C:/wamp/www/magento1.7/media/catalog/product/cache/1/small_image/9df78eab33525d08d6e5fb8d27136e95/p/o/portf1.jpg'(length = 112) 1 => string'C:/ wamp /www/magento1.7/media/catalog/product/cache/1/small_image/9df78eab33525d08d6e5fb8d27136e95/l/a/landf1.jpg'(length = 112) – Nida