【发布时间】:2015-06-27 14:37:26
【问题描述】:
我正在尝试创建将图像插入现有 pdf 文件的脚本。图像的位置必须在右下角。我无法弄清楚图像的坐标。我可以获得以像素为单位的图像大小和以 mm 为单位的 pdf 大小。 问题是我的图像 $x 和 $y 位置计算错误,图像被插入到下一页。
代码示例:
include_once('/tcpdf/tcpdf.php');
include_once('/tcpdf/tcpdi.php');
// Create new PDF document.
$pdf = new TCPDI(PDF_PAGE_ORIENTATION, 'mm', PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->setSourceFile('1_6.pdf');
$tpl = $pdf->importPage(1);
$size = $pdf->getTemplateSize($tpl);
$orientation = $size['h'] > $size['w'] ? 'P' : 'L';
$pdf->addPage($orientation);
$pdf->useTemplate($tpl, null, null, 0, 0, TRUE);
$imageSize = getimagesize('watermarkL.png');
//Put the watermark
$convert = 0.0393700787;
$imageWidthInMm = $imageSize[0] / $convert / 72; //?? this is bad, what here?
$imageHeightInMm = $imageSize[1] / $convert / 72;
$xxx = $size['w'] - $imageWidthInMm;
$yyy = $size['h'] - $imageHeightInMm;
$pdf->Image('watermarkL.png', $xxx, $yyy, 0, 0, 'png');
$pdf->Output('/new_file.pdf','F');
【问题讨论】: