2014-07-09 46 views
0

感谢您花一点时间阅读本文。ZendPdf放置镜像效果的图像

我写上ZendPdf飞一个PDF文件,但在当下的图片添加到其显示镜像PDF:

这里是效果更好的理解: http://snag.gy/ZYbWp.jpg

原始图像很好。

有人能告诉我为什么图像是镜像的,我怎么能把它渲染成原始图像?

我在这里粘贴它生成pdf的整个操作。

public function createPdfAction() 
{ 
    $country = $this->params()->fromRoute('lang', null); 

    $pdf = new \ZendPdf\PdfDocument(); 
    // Add new page generated by ZendPdf\Pdf object 
    // (page is attached to the specified the document) 
    $pdf->pages[] = ($page1 = $pdf->newPage('A4')); 

    $width = $page1->getWidth(); 
    $height = $page1->getHeight(); 

    $imageFile = dirname(__FILE__) . '/../../../../../html/img/site/logo_peug_scooter.jpg'; 
    if (!isset($pdf->imageCache[$imageFile])) 
    { 
     try { 
      // Create new image object 
      //$stampImage = ZendPdf\Image::imageWithPath($imageFile); 
      $pdf->imageCache[$imageFile] = ZendPdf\Image::imageWithPath($imageFile); 
     } catch (ZendPdf\Exception $e) { 
      // Example of operating with image loading exceptions. 
      if ($e->getMessage() != 'Image extension is not installed.' && 
       $e->getMessage() != 'JPG support is not configured properly.') { 
       throw $e; 
      } 
      $pdf->imageCache[$imageFile] = null; 
     } 
    } 

    if (null != $pdf->imageCache[$imageFile]) { 
     $page1->drawImage($pdf->imageCache[$imageFile], 50, $height, 50 + 220, $height - 70); 
    } 



    // Create new font 
    $font = ZendPdf\Font::fontWithPath(dirname(__DIR__) . '/../../../../html/fonts/peugeot_style-webfont.ttf'); 
    // Apply font and draw text 
    $page1->setFont($font, 16) 
     ->setFillColor(ZendPdf\Color\Html::color('#0b2333')) 
     ->drawText('DJANGO', 50, $height - 18 - 18 - 50); 

    if ('uk' == $country) { 
     $locale = 'en_GB'; //. strtoupper($country); 
    } else { 
     $locale = $country . '_' . strtoupper($country); 
    } 
    setlocale(LC_MONETARY, $locale); 
    $price = money_format('%i', 2660); 
    $font = ZendPdf\Font::fontWithPath(dirname(__DIR__) . '/../../../../html/fonts/peugeot_normal-webfont.ttf'); 
    // Apply font and draw text 
    $page1->setFont($font, 16) 
      ->setFillColor(ZendPdf\Color\Html::color('#0b2333')) 
      ->drawText($price, 447, $height - 18 - 18 - 50); 


    $pdf->save('/tmp/pdfs/sample2.pdf'); 


    $this->layout('layout/empty'); 
    $viewModel = new ViewModel(); 
    $viewModel->setTerminal(true); 

    return $viewModel; 

} 

我会很感激任何指导。

谢谢。

回答

1

请注意,坐标系的原点位于左下角,并且还需要按照该顺序提供drawImage的4个坐标参数。从图像的左下角到右上角。

你从底部进行测量,但首先递给了顶部左上角:

$page1->drawImage($pdf->imageCache[$imageFile], 50, $height, 50 + 220, $height - 70); 

Zend的解释第二坐标值作为图像的底部。您将其设置为$height(页面顶部边缘),然后从底部测量图像顶部的位置为$height-70。 (在页面顶边以下70px) 因此,Zend的图像顶部低于图像底部。因此镜像的图像。 (我知道,很多顶部和底部..有疑问:洗牌的4值,直到你运气好。)它应该是:

$page1->drawImage($pdf->imageCache[$imageFile], 50, $height - 70, 50 + 220, $height); 
+0

谢谢,我已经知道了。 – manou

+0

我遇到了问题,我自己寻找答案。在我想通了之后,我将它发布给未来的访问者。没想到你会等7个月。 :-) –

+0

是的,谢谢你帮忙解决问题,因为它可能是。我忘了回来重玩自己。当我提出问题时,我会用我的所有研究发表评论。 – manou