【问题标题】:Yii2 mpdf, add image to second page of PDF fileYii2 mpdf,将图像添加到PDF文件的第二页
【发布时间】:2019-10-15 10:07:00
【问题描述】:

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

我该怎么做?

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

【问题讨论】:

标签: yii2 mpdf


【解决方案1】:

我自己找到了答案。

        $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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-19
    • 2014-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多