Question

After Mac OS X 10.7.5 there is a consistent (and undocumented) behaviour change in Quartz-PDFKit's method

characterBoundsAtIndex

of the PDFPage class.

As you get the text of your pdfPage as an NSString with

text = [pdfPage string];

and retrieve the unicode character at position idx with

unichr = [text characterAtIndex: idx]; // (1)

You expect to retrieve its bounds (position and size) on the page with

bounds = [pdfPage characterBoundsAtIndex: idx]; // (2)

Using the same index value.

WRONG

After 10.7.5 there is no more a 1-1 corrispondence with the index value at (1) and the index value at (2) and, what's worse, no public method is provided to translate from the first to the latter.

If your application needs to retrieve the position of each character on the page (and -of course- know what is that character) is in trouble and if it relied on the "up to 10.7.5" assumpiont then breaks.

As PDFKit up to OS X 10.7 worked fine my question is:

is there any way to embed OS X 10.7's PDFKit in my application and link to it?

Is this kind of transplant going to work or there are drawbacks?

Was it helpful?

Solution 2

As Steven Troughton-Smith suggested it's possible to point the executable to a different dynamic library.

Unfortunately PDFKit and its functionalitity is not self contained in that single library. PDFKit is mostly a frontend interface that relies upon many other frameworks, some of them private; among the others CorePDF, CoreGraphics... just try

otool -L /System/Library/Frameworks/Quartz.framework/Versions/A/Frameworks/PDFKit.framework/Versions/A/PDFKit

I wrote a program that recursively extracted and copied locally every referenced framework from a 10.7.5 installation and pointed every one of them to the 10.7.5 version.

At the end the executable was pointing to the 10.7.5 version of PDFKit and Foundation and those, and all their dependencies, were pointing to 10.7.5 versions of the frameworks.

I ran the executable and it ended quickly in a segmentation fault.

So practically is not possible to use 10.7.5 PDFKit on a 10.9.2 system as its functionality is buried too deep in the system architecture.

OTHER TIPS

Yes it is indeed technically possible.*

The install_name_tool binary, part of Xcode, will let you point your binary at an embedded copy of a framework (using @executable_path/../Frameworks/ or some variation thereof).


However, if the underlying frameworks and libraries this version of the framework relies on have changed in significant ways, there's no way to guarantee everything will work. Considering you're talking about 10.7 -> 10.9, it's very likely everything will break. This, of course, is a framework that Quartz itself relies on.

As an aside: this even works on iOS - I've used it in the past in an attempt to get the iOS 5 Google-based version of Maps running on iOS 6+.


*Of course, actually shipping something like this would be copyright infringement (at the least), and/or could cause cascading bugs of other kinds in your app. I didn't say it was safe, I said it's possible.

You are much better off patching or working around the broken method dynamically.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top