Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento PDF发票内容布局问题_Magento - Fatal编程技术网

Magento PDF发票内容布局问题

Magento PDF发票内容布局问题,magento,Magento,我对PDF一点也不擅长。我在下面添加了两个注释,称为“发票注释和订单注释”。我遇到的问题是,我不能把这两个部分放在一个好的单元中。当我尝试像$pdf->Cell之类的东西时,我只会看到可怕的白色屏幕。出于某种原因,似乎只有drawText可以渲染文本。此外,评论也延伸到了PDF页面之外。我尝试过换行,但没有成功。我猜是b/c注释是数组。任何帮助都会很好 class Inchoo_Invoice_Model_Order_Pdf_Invoice extends Mage_Sales_Model_Or

我对PDF一点也不擅长。我在下面添加了两个注释,称为“发票注释和订单注释”。我遇到的问题是,我不能把这两个部分放在一个好的单元中。当我尝试像
$pdf->Cell
之类的东西时,我只会看到可怕的白色屏幕。出于某种原因,似乎只有
drawText
可以渲染文本。此外,评论也延伸到了PDF页面之外。我尝试过换行,但没有成功。我猜是b/c注释是数组。任何帮助都会很好

class Inchoo_Invoice_Model_Order_Pdf_Invoice extends Mage_Sales_Model_Order_Pdf_Invoice
{
    protected function insertImage($image, $x1, $y1, $x2, $y2, $width, $height, &$page)
    {
        if (!is_null($image)) {
            try{
                $width = (int) $width;
                $height = (int) $height;

                //Get product image and resize it
                $imagePath = Mage::helper('catalog/image')->init($image, 'image')
                    ->keepAspectRatio(true)
                    ->keepFrame(false)
                    ->resize($width, $height)
                    ->__toString();

                $imageLocation = substr($imagePath,strlen(Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB)));
                $image = Zend_Pdf_Image::imageWithPath($imageLocation);
                //Draw image to PDF
                $page->drawImage($image, $x1, $y1, $x2, $y2);
            }
            catch (Exception $e) {
                return false;
            }
        }
    }



    public function getPdf($invoices = array())
    {
        $width = 1000;
        $height = 1000;
        $this->_beforeGetPdf();
        $this->_initRenderer('invoice');

        $pdf = new Zend_Pdf();
        $this->_setPdf($pdf);
        $style = new Zend_Pdf_Style();
        $this->_setFontBold($style, 10);



        foreach ($invoices as $invoice) {
            if ($invoice->getStoreId()) {
                Mage::app()->getLocale()->emulate($invoice->getStoreId());
            }
            $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
            $pdf->pages[] = $page;

            $order = $invoice->getOrder();

            /* Add image */
            $this->insertLogo($page, $invoice->getStore());


            /* Add address */
            $this->insertAddress($page, $invoice->getStore());

            /* Add head */
                        $page->drawText(Mage::helper('sales')->__('Invoice # ') . $invoice->getIncrementId(), 487, 780, 'UTF-8');
            $this->insertOrder($page, $order, Mage::getStoreConfigFlag(self::XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID, $order->getStoreId()));

            $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
            $this->_setFontRegular($page);


            /* Add table */
            $page->setFillColor(new Zend_Pdf_Color_RGB(0.93, 0.92, 0.92));
            $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
            $page->setLineWidth(0.5);

            $page->drawRectangle(25, $this->y, 570, $this->y -15);
            $this->y -=10;

            /* Add table head */
            $page->setFillColor(new Zend_Pdf_Color_RGB(0.4, 0.4, 0.4));
            $page->drawText(Mage::helper('sales')->__('Products'), 35, $this->y, 'UTF-8');
            //Added for product image
            $page->drawText(Mage::helper('sales')->__('Product Image'), 279, $this->y, 'UTF-8');
            $page->drawText(Mage::helper('sales')->__('SKU'), 125, $this->y, 'UTF-8');
            $page->drawText(Mage::helper('sales')->__('Price'), 380, $this->y, 'UTF-8');
            $page->drawText(Mage::helper('sales')->__('Qty'), 430, $this->y, 'UTF-8');
            $page->drawText(Mage::helper('sales')->__('Tax'), 480, $this->y, 'UTF-8');
            $page->drawText(Mage::helper('sales')->__('Subtotal'), 535, $this->y, 'UTF-8');

            $this->y -=15;

            $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));

            /* Add body */
            foreach ($invoice->getAllItems() as $item){
                if ($item->getOrderItem()->getParentItem()) {
                    continue;
                }

                if ($this->y < 15) {
                    $page = $this->newPage(array('table_header' => true));
                }

                /* Draw item */
                $page = $this->_drawItem($item, $page, $order);

                /* Draw product image */
                $productId = $item->getOrderItem()->getProductId();
                $image = Mage::getModel('catalog/product')->load($productId);
                $this->insertImage($image, 345, (int)($this->y + 0), 275, (int)($this->y+65), $width, $height, $page);
            }

            /* Add totals */
            $page = $this->insertTotals($page, $invoice);








/*************************** This Is The Invoice Comments ***********************************/
$_tempY = $this->y;
$this->y += 10;

$commentsCollection = $invoice->getCommentsCollection(true);

$internalcomments = "Internal Invoice Comments";    
$page->drawText($internalcomments, 35, $this->y, 'UTF-8'); 

            foreach($commentsCollection as $comm)
            {
                $page->drawText($comm->getData('comment'), 235, $this->y, 'UTF-8');
                $this->y -= 10;

            } 

/*************************** End Invoice Comments ***********************************/







            if ($invoice->getStoreId()) {
                Mage::app()->getLocale()->revert();
            }
        }





/************************* This Is The Order Comments *******************************/

$_tempY = $this->y;
$this->y -= 80;

$statusHistoryCollection = $order->getStatusHistoryCollection();
$customersection = "Order Customer Comments";
   $page->drawText($customersection, 35, $this->y, 'UTF-8'); 
foreach ($statusHistoryCollection as $statushistory) {  
   $page->drawText($statushistory->getComment(), 35, $this->y, 'UTF-8');
   $this->y -= 10;
}

$this->y = $_tempY;

/************************* End Order Comments *******************************/



        $this->_afterGetPdf();

        return $pdf;
    }



}
class Inchoo\u发票\u模型\u订单\u Pdf\u发票扩展了Mage\u销售\u模型\u订单\u Pdf\u发票
{
受保护的函数插入图像($image、$x1、$y1、$x2、$y2、$width、$height、$page)
{
如果(!为null($image)){
试一试{
$width=(int)$width;
$height=(int)$height;
//获取产品图像并调整其大小
$imagePath=Mage::helper('catalog/image')->init($image,'image'))
->keepAspectRatio(真)
->keepFrame(假)
->调整大小($width,$height)
->__toString();
$imageLocation=substr($imagePath,strlen(Mage::getBaseUrl(Mage\u Core\u Model\u Store::URL\u TYPE\u WEB));
$image=Zend\u Pdf\u image::imageWithPath($imageLocation);
//将图像绘制为PDF格式
$page->drawImage($image,$x1,$y1,$x2,$y2);
}
捕获(例外$e){
返回false;
}
}
}
公共函数getPdf($invoices=array())
{
$width=1000;
$height=1000;
$this->_beforeGetPdf();
$this->(发票);
$pdf=new Zend_pdf();
$this->\u setPdf($pdf);
$style=new Zend_Pdf_style();
$this->_setFontBold($style,10);
foreach($发票作为$发票){
如果($invoice->getStoreId()){
Mage::app()->getLocale()->仿真($invoice->getStoreId());
}
$page=$pdf->newPage(Zend\u pdf\u page::SIZE\u A4);
$pdf->pages[]=$pages;
$order=$invoice->getOrder();
/*添加图像*/
$this->insertLogo($page,$invoice->getStore());
/*添加地址*/
$this->insertAddress($page,$invoice->getStore());
/*加头*/
$page->drawText(Mage::helper('sales')->(Invoice('Invoice#')。$Invoice->getIncrementId(),487780,'UTF-8');
$this->insertOrder($page,$order,Mage::getStoreConfigFlag(self::XML\u PATH\u SALES\u PDF\u INVOICE\u PUT\u order\u ID,$order->getStoreId());
$page->setFillColor(新Zend_Pdf_Color_GrayScale(1));
$this->_setFontRegular($page);
/*添加表*/
$page->setFillColor(新的Zend_Pdf_Color_RGB(0.93,0.92,0.92));
$page->setLineColor(新Zend_Pdf_Color_灰度(0.5));
$page->setLineWidth(0.5);
$page->drawRectangle(25,$this->y,570,$this->y-15);
$this->y-=10;
/*加桌头*/
$page->setFillColor(新的Zend_Pdf_Color_RGB(0.4,0.4,0.4));
$page->drawText(Mage::helper('sales')->\uuu('Products'),35,$this->y,'UTF-8');
//为产品形象添加
$page->drawText(Mage::helper('sales')->\uuu('Product Image'),279,$this->y,'UTF-8');
$page->drawText(Mage::helper('sales')->\uuuu('SKU'),125,$this->y,'UTF-8');
$page->drawText(Mage::helper('sales')->\uuu('Price'),380,$this->y,'UTF-8');
$page->drawText(Mage::helper('sales')->\uuu('Qty'),430,$this->y,'UTF-8');
$page->drawText(Mage::helper('sales')->480,$this->y,'UTF-8');
$page->drawText(Mage::helper('sales')->\uuuu('Subtotal'),535,$this->y,'UTF-8');
$this->y-=15;
$page->setFillColor(新的Zend_Pdf_Color_灰度(0));
/*添加正文*/
foreach($invoice->getAllItems()作为$item){
如果($item->getOrderItem()->getParentItem()){
继续;
}
如果($this->y<15){
$page=$this->newPage(数组('table_header'=>true));
}
/*抽签项目*/
$page=$this->\u drawItem($item,$page,$order);
/*绘制产品图片*/
$productId=$item->getOrderItem()->getProductId();
$image=Mage::getModel('catalog/product')->load($productId);
$this->insertImage($image,345,(int)($this->y+0),275,(int)($this->y+65),$width,$height,$page);
}
/*加总*/
$page=$this->insertTotals($page,$invoice);
/***************************这是发票备注***********************************/
$\u tempY=$this->y;
$this->y+=10;
$commentsCollection=$invoice->getCommentsCollection(true);
$internalcomments=“内部发票注释”;
$page->drawText($internalcomments,35,$this->y,'UTF-8');
foreach($commentsCollection作为$comm)
{
$page->drawText($comm->getData('comment'),235,$this->y,'UTF-8');
$this->y-=10;
} 
/***************************结束发票注释***********************************/
如果($invoice->getStoreId()){
Mage::app()->getLocale()->revert();
}
}
/*************************这是订单评论*******************************/
$\u tempY=$this->y;
$this->y-=80;
$statusHistoryCollection=$order->getStatusHistoryCollection();
$customersection=“订单客户评论”;
$page->drawText($customersection,35,$this->y,'UTF-8');
foreach($statusHistoryCollection作为$statushistory){
$page->drawText($statushistory->getComment(),35,$this->y,'UTF-8');
$this->y-=10;
}
$this->y=$\u tempY;
/*************************** This Is The Invoice Comments ***********************************/

    $this->_setFontRegular($page, 10);

    // Begin table header
    $page->setFillColor(new Zend_Pdf_Color_RGB(0.93, 0.92, 0.92));
    $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
    $page->setLineWidth(0.5);
    $page->drawRectangle(25, $this->y, 570, $this->y -15);
    $this->y -= 10;
    $page->setFillColor(new Zend_Pdf_Color_RGB(0, 0, 0));
    // end table header


    $_tempY = $this->y;

    $commentsCollection = $invoice->getCommentsCollection(true);

    $internalcomments = "Internal Invoice Comments";
    $page->drawText($internalcomments, 35, $this->y, 'UTF-8');

    $this->y -= 15;

    foreach($commentsCollection as $comm)
    {
            $textChunk = wordwrap($comm->getData('comment'), 120, "\n");
            foreach(explode("\n", $textChunk) as $textLine){
                    if ($textLine!=='') {
                            $page->drawText(strip_tags(ltrim($textLine)), 35, $this->y, 'UTF-8');
                            $this->y -= 15;
                    }
            }

     }

/*************************** End Invoice Comments ***********************************/