I am trying to create script that inserts image to an existing pdf file. The position of the image has to be right bottom. I can't figure out the coordinates of the image. I can get image size in pixels and size of pdf in mm. The problem is that my $x and $y position of image is bad calculated and the image is inserted on the next page.
Sample of code:
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');
It seems that the formula is ok, but my image was on bad page beacause of some margins. This helps:
$pdf->SetAutoPageBreak(false);