3

I have a PDF template file. It has a bunch of fields I need to write to using PHP. How can I easily determine the xy coordinates of a field in the file? Right now I am using xy locations but trial and error is very time consuming. Is there a better way to do this? Or even an easy way to get the xy coordinates of a point in a pdf file?

Byron Whitlock
  • 52,691
  • 28
  • 123
  • 168

3 Answers3

17

In order of my preference:

Mac: Skim - Select a Text Box. Look on the bottom right for X,Y, plus the box height & width.

Preview (included in OSX), Select a Text Box: Tools -> Show Inspector -> pick 4th tab that has a little ruler icon. This gives coordinates, but with an upper-left origin (web standard origin, but not the pdf convention)

Linux and Unix: don't know, but try... GSView xpdf evince gnome-gv

Windows: GSView is now my favorite: fast, convenient alway-on coordinate display, free

Foxit Reader, free for reading coordinates (see 'Properties' box), $100 if you want to save file revisions.

Foxit Phantom ($130) does not display coordinates.

PDF-Xchange will also do it for free, but the Y origin is upper-left, not lower-left, so you have to subtract every Y from your page height. And the coordinates have to be interpreted by reading an edge scale, which is hard to do accurately.

Adobe Acrobat - A sales and a tech support ticket I filed say that the $700 reader will do it. I haven't checked.

Randy J Parker
  • 461
  • 1
  • 4
  • 8
  • GSView (6.0 Beta but hasn't been update since 2015...) on windows had no option to see the coordinates – sgirardin Apr 27 '17 at 07:20
  • The Mac solution does not seem to work anymore (Preview Version 10.1) – normanius Jul 24 '20 at 19:25
  • 1
    I can confirm that it doesn't work on preview. The "selection" top/left remains empty at all time. – cglacet Nov 28 '20 at 11:33
  • On the other hand, now it says "crop" and selecting the crop tool allow you to draw crop boxes and get the crop-box coordinates. Which seems even better than using text box anyway. – cglacet Nov 28 '20 at 11:34
1

The form-filling part of your question seems related to this question. As for coords, I can't help with PHP but I have a good Perl solution for this. Here are two questions about computing X,Y coords of text. CAM::PDF has a fillformfields.pl utility that can help.

Community
  • 1
  • 1
Chris Dolan
  • 8,905
  • 2
  • 35
  • 73
1

I suppose it's better late than never to answer this:

Foxit PDF Editor (now incorporated into Foxit PhantomPDF Standard or Business) will display the coordinates of any object in a PDF file. The only problem you have to go through every object individually - manually click on the object and read off the coordinates. I haven't found an automatic way to extract the coordinates and pipe them into a PHP script.

Iain S
  • 2,643
  • 3
  • 23
  • 23