【问题标题】:TCPDI Image watermarkTCPDI 图像水印
【发布时间】: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');

【问题讨论】:

    标签: php image pdf


    【解决方案1】:

    似乎公式没问题,但我的图像由于一些边距而出现在错误的页面上。 这有帮助:

    $pdf->SetAutoPageBreak(false);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多