Zend framework2 ZendPdf放置具有镜像效果的图像

Zend framework2 ZendPdf放置具有镜像效果的图像,zend-framework2,zend-pdf,Zend Framework2,Zend Pdf,感谢您花时间阅读这篇文章 我正在使用ZendPdf动态编写一个PDF文件,但在向PDF添加图片时,它显示为: 以下是更好理解的效果: 原始图像很好 有人能告诉我为什么镜像图像,我如何将其渲染为原始图像 我在这里粘贴整个动作,它是在pdf中生成的 public function createPdfAction() { $country = $this->params()->fromRoute('lang', null); $pdf = new \ZendPdf\Pd

感谢您花时间阅读这篇文章

我正在使用ZendPdf动态编写一个PDF文件,但在向PDF添加图片时,它显示为:

以下是更好理解的效果:

原始图像很好

有人能告诉我为什么镜像图像,我如何将其渲染为原始图像

我在这里粘贴整个动作,它是在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;

}
我将感谢任何指导


谢谢。

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

您从底部开始测量,但首先将顶部左角交给:

$page1->drawImage( $pdf->imageCache[$imageFile], 50, $height, 50 + 220, $height - 70 );
Zend将第二个坐标值解释为图像的底部。将其设置为
$height
(页面的上边缘),然后图像的顶部位于从底部测量的
$height-70
。(页面上边缘下方70像素) 因此Zend的图像顶部在图像底部的下方。因此,镜像图像。(我知道,有很多顶部和底部..有疑问:洗牌4个值,直到你走运。)它应该是:

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

我偶然发现这个问题,自己也在寻找答案。在我弄明白之后,我把它贴在了未来的访客面前。没想到你会等7个月。:-)是的,谢谢你帮助解决这个问题。我忘了自己回来重播。当我提出问题时,我经常评论我所有的研究。