PDF decode and find useful data in it
I'm trying to decode a PDF file to useful data but I've got some coordinate system problems.
First, the data I'm using: http://pastebin.com/h4MFiSbd (I've already decoded it)
I'm trying to get the coordinates of the gray squares.
My problem is I've found the coordinates of the text:
0 1.00057 -1 0 65.1595 353.15 Tm
[(2)5.81146(.)2.90771(4)5.81146( )2.90771(t)2.90771(i)222]TJ
65.1595 = y
353.15 = x
But the problem is the coordinate of the squares. I've found the color of the squares plus coordinates:
0.753906 0.753906 0.753906 rg
3039 200.914 817.996 1329 re
In the PDF reference it says re
uses x,y,width,height
, but as you can see, 3039 is far bigger than 353.15. I've also seen Tm uses a matrix thing [[a,b,0],[c开发者_开发百科,d,0],[e,f,1]]
The other problem are that those rectangles are wrong somehow:
470.996 2934.91 1674 1329 re ---> beveilig.tech.pr
1327 1567.91 2102 1329 re ---> beveilig.tech.th
1327 4301.91 817.996 1329 re ---> bbc ti
2183 4301.91 817.996 1329 re ---> b&o practicum
3039 200.914 817.996 1329 re ---> b&o theorie
I've collected all the coordinates from the 0.753906 0.753906 0.753906 colored squares, with the name of the text beneath it. As you can see these coordinates suggest all the blocks have a equal height.
Can someone please help me?
The reason is in the first line - "0.12 0 0 0.12 0 0 cm". This operation sets transformation matrix and (simplified) scales x,y coordinates in all following operations by 0.12. So 3039 is really = 3039*0.12 = 364.68.
You really need to track the values as you parse because you can also get relative moves (td) and you need to factor in lots of other values to get the correct outline rectangle for the text.
The values can also be popped on and off the stack with the Q q commands.
精彩评论