So i'm trying to get image position in PDF with PHP and PDFlib pCos library.
I can list images and get image dimensions like:
$imgcount = $tet->pcos_get_number($doc, "length:pages[" . $page . "]/images");
for ($im = 0; $im < $imgcount; $im++) {
$width = $tet->pcos_get_number($doc, "pages[" . $page . "]/images[" . $im . "]/Width");
$height = $tet->pcos_get_number($doc, "pages[" . $page . "]/images[" . $im . "]/Height");
}
But how do i get image position?
Already tried paths like:
"pages[" . $page . "]/images[" . $im . "]/Box"
"pages[" . $page . "]/images[" . $im . "]/Box[0]"
"pages[" . $page . "]/images[" . $im . "]/Rect"
Nothing works.. and i have searched in web everywhere, checked also the PDF reference manual.. nothing there..
any suggestions?
To determine the position of an image you have to parse the page content. This is not possible with pCOS. For this, PDFlib offers an additional tool named TET: http://www.pdflib.com/products/tet/
Please see TET manual, chapter 8.5 "Geometry of Placed Images" for further details on this topic. But from your code fragment it looks like you already use the pCOS interface within TET. If so, simply check the related manual chapter.
A good starting point might be the TET 4.3 sample image_extractor.php, where you should simply add the positions to the following code fragment:
while ($ti = $tet->get_image_info($page) ) {
/* Report image geometry */
print("page " . $pageno . ": " .
(int) $ti->width . "x" .
(int) $ti->height . "pt [" .
(int) $ti->x . "x" .
(int) $ti->y . "], alpha=" .
$ti->alpha . ", beta=" .
$ti->beta . "\n");