TCPDI图像水印

时间:2015-04-20 18:05:02

标签: php image pdf

我正在尝试创建将图像插入现有pdf文件的脚本。图像的位置必须在右下角。我无法弄清楚图像的坐标。我可以获得像素大小和pdf大小(mm)。 问题是我的$ 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');

1 个答案:

答案 0 :(得分:0)

似乎公式还可以,但由于有些边缘,我的图片在坏页面上。 这有助于:

$pdf->SetAutoPageBreak(false);