Juggling balls

Nov 01, 2010 10:17

Christ, Adobe Acrobat is a pain in the arse.

I'm trying to work with it using Javascript. It has a built-in Javascript engine, with a bunch of objects for interacting with documents and menus. The API is horrible, and the console for interacting with it is also rancid.

Consider this snippet from the Acrobat API reference:

if ( ckWord == "Acrobat")
{
var q = this.getPageNthWordQuads(p, i);
// Convert quads in default user space to rotated
// User space used by Links.
m = (new Matrix2D).fromRotated(this,p);
mInv = m.invert()
r = mInv.transform(q)
r=r.toString()
r = r.split(",");
l = addLink(p, [r[4], r[5], r[2], r[3]]);
...
}

Most of PDFs are based on coordinates, rather than streams of text in paragraphs or anything like that. (It's this that lets PDFs be much more precise than, say, HTML.)

So, finding a word on a page doesn't actually give you the coordinates you want. It gives yuo a different set. Adding a link requires you to convert them by the magic of creating a matrix, inverting it, transforming it, and then turning it into a string and splitting on a bloody comma. Then you miss out two entries in the array, and the order of entries is weird anyway. In the 4, 5, 2, 3 entry, the order is: top-left X, top-left Y, bottom-right X, bottom-right Y. That's sensible enough, but the order in the r[] array? Dude, what?

Urgh.

work, arse biscuits

Previous post Next post
Up