Yii2 mpdf,将图像添加到PDF文件的第二页

问题描述 投票:0回答:1

我已经有一个.pdf文件。我需要将用户上传的图像(然后转换为base64)添加到PDF文件的第二页或其他任何页面,并按页面坐标放置图像。然后重新保存基本PDF文件。

我该怎么做?

我使用Mpdf中的Yii2。在前面-jquery

yii2 mpdf
1个回答
0
投票

我自己找到了答案。

        $pdf = new Mpdf();

        $pageCount = $pdf->setSourceFile(_PATH_FOR_PDF_FILE_);
        //Here I get array with images params (You can see this params in mPDF doc) - THIS IS MY CUSTOM FUNCTION!!!
        $images = $document->getImagesForPdf();

        for ($i = 1; $i <= ($pageCount); $i++) {
            $pdf->AddPage();
            $import_page = $pdf->ImportPage($i);
            $pdf->UseTemplate($import_page);

            $size = $pdf->getTemplateSize($import_page);

            //Here I create an image with the parameters that I received above on current page
            $pdf->Image($images[$i]);
        }

        $output = $pdf->Output($name, $destination);
© www.soinside.com 2019 - 2024. All rights reserved.