我试图创建脚本,插入图像到现有的pdf文件。图像的位置必须是右下角。我找不到图像的坐标。我可以得到像素的图像大小和毫米的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');发布于 2015-04-23 00:49:08
这个公式看起来还可以,但是我的图片出现在了不好的页面上,因为有一些空白处。这有助于:
$pdf->SetAutoPageBreak(false);https://stackoverflow.com/questions/29755184
复制相似问题