我已经有一个.pdf
文件。我需要将用户上传的图像(然后转换为base64
)添加到PDF文件的第二页或其他任何页面,并按页面坐标放置图像。然后重新保存基本PDF文件。
我该怎么做?
我使用Mpdf
中的Yii2
。在前面-jquery
我自己找到了答案。
$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);