0

How do I get a coordinate (x,y) of an image from the PDF file using PHP?

For example, I have a PDF document page, I know the size of the page, there I have one image, I know its size too (because I've extracted it using the pdfimages tool). However, I need to know where was this image situated on the page.

I've read that it maybe could be done using FPDF but I couldn't understand how.

halfer
  • 19,824
  • 17
  • 99
  • 186
Pigalev Pavel
  • 1,155
  • 1
  • 15
  • 29
  • To get the coordinates of an item, I think you might have to parse the document at quite a low level. See this answer for ideas: http://stackoverflow.com/questions/1251956/is-there-a-pdf-parser-for-php – halfer Jan 15 '13 at 12:20

2 Answers2

1

To get PDF images with their coordinates, ImageData and size informations, you have to get PDFlib You can get the PECL free version here and TET (Text Extraction Toolkit) here.

After configuring PDFlib and TET and linking both of them to your php's extension on the php.ini (extension=pdf.so and extension=php_tet.so), you will have a bunch of examples in the directory where you installed PDFlib (where you typed ./configure && make && make install or where you get the "php_tet.so"). Open them to see how to use the functions. This lib is object oriented.

With it you can get all the images (coordinates, size and create a jpeg file) and texts (size, font and coordinates) of each pages of a PDF.

I'm at your service if you have other questions or if a point is not clear to you ;)

P.S Sorry my english is not very good

Pierrick Martellière
  • 1,554
  • 3
  • 21
  • 42
  • Thank you for your answer but you are a bit late :) But anyway I will keep it in mind. Thank you! – Pigalev Pavel Nov 19 '14 at 08:17
  • Haha np, but this solution is more optimized and with it you can create jpeg images from the PDF ;) It's very useful to extract images and text from a pdf and replace them on a webpage or an object ;) – Pierrick Martellière Nov 19 '14 at 14:05
0

An option would be to convert your pdf to an image (there are scripts available to do so, didn't try it but this might do the job)

Then you can use the code I posted on your other question to locate an image inside another image.

Community
  • 1
  • 1
emartel
  • 7,712
  • 1
  • 30
  • 58