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.
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
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.
Related
I am currently using ghostscript, via exec() from PHP, to create a PNG image that is saved to a file.
And then I use imagecreatefrompng() to load it into PHP. I am wondering if there is a way to directly connect these without first saving it to a file and then reading it from a file. Does this work with the expect:// wrappers? If so could somebody provide an example? I am not sure about the syntax.
Another solution may perhaps be with imagecreatefromstring() if one can get the image file as a string from ghostscript. I am looking for an example of how to do this. The image files I create are not that large, typically 600 x 150 pixels.
I want to create auto Thumbnail if i upload my PDF, then i will save that path
i build my website with yii framework
i want to try capture with ImageMagick
Any Body Help..
Thx
I am also using Yii framework to generate the image file. It is pretty simple and straight forward. I am using window XP/apache and php 5.4
Download and install the imagemagick http://www.imagemagick.org/script/download.php
Download and install php extension for imagemagic http://pecl.php.net/package/imagick
Download and install the ghostscript because image magic use the ghost script to convert the pdf to images http://www.ghostscript.com/download/
Write a method in your model class to handle conversion
use command : command format OR
use library : php manual
Call the method after your form submission.
check if the image is saved at the desired location. I hope that help. Let me know if you face any issue.
I know you asked about ImageMagick but maybe you could use GD instead to accomplish such simple operation.
It's available virtually on every hosting.
Examples in comments below docs.
http://php.net/manual/en/book.image.php
When users upload certain files to my site (such as .doc, .xls, .pdf, etc) I'd like to be able to generate a preview thumbnail (of the first page of the document). I'm working with PHP in a LAMP stack but would be happy with any library or command-line tool that can do the job (Linux highly preferred).
It's not easy to convert certain document formats to image. php alone cannot do this.
The 'proper' way to do this is to first of all have the program installed on your server that can open the document in that format.
For example, for .doc documents you can use OpenOffice
it also can open most other document formats
You then need to setup your open office to work in 'headless' mode, sending the output to virtual display (XVFB is what you going to need on Linux)
You php script will then call OpenOffice, passing the path to uploaded doc. OpenOffice will actually open that doc. Then you need to create an image from the screen buffer. You can use ImageMagick for that
Then once you have the capture of your screen you can resize it to a thumbnail.
Look at this link for more details
http://www.mysql-apache-php.com/website_screenshot.htm
The best way is to have all your documents converted to PDF
after that you can make preview thumbnail
& this is how simply explained
How do I convert a PDF document to a preview image in PHP?
These are the steps I am trying to achieve:
1) Upload a PDF document on the server.
2) Convert the PDF document to a set of images, and saving them.
Any ideas for doing #2 using php??
If you have the ImageMagick extension compiled into PHP, it should be able to read in PDFs and convert them to any common image format. I don't believe the GD extension (which is more common) has PDF capabilities, sadly.
I need to include pdf files in some webpages, and I'm gettin' in troubles.
The app is a simple newspaper's archive, in which i can read right on page or download as pdf files, one file per page. What my customer can provide me is one pdf file for each page; what my customer wants from me is to navigate them in indexes (with page thumbnail) and have a read from a choosen one direcly in page; I'm using php/mysql.
I started trying out to use the <object> tag with type="application/pdf", but i found it's deprecate 'cause it's not crossplatform at all (there's no support on linux's browsers, but even my windows' firefox 3.5 couldn't show me anything).
I guessed I could transform that pdf in something different (html or simply images are good enough), but the only thing i found is ImageMagick, that I cannot use as I must install on server and I can't, as I'm not admin of that machine.
So, I'm finally looking for suggestions
Thanks
Display the pdf inline using an IFRAME. The thumbnail you can generate with imageMagik. You should be able to use the command line version of ImageMagik to resize and convert to jpg.
edit
Your best bet is to talk to the server admin and have them install php support for ImageMagik then you can use it as a class.
If you can't get support to install on the server, you will have to use the command line version.
You might be able to Google around for a library that wraps the command line, but it would be trivial to write it yourself.
With this in place you can create a large readable black and white png for each page. It should click through to the pdf.