Search code examples
macospdfquartz-2d

MacOS X 10.9 - Link application to previous version of (Apple) PDFKit framework


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?


Solution

  • 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.