Displaying pdf files using the PDFKit interface

2019-07-18 23:34发布

问题:

I am working on a Mac OS 10.12, and have an application to display pdf files using the PDFKit interface. But I encountered the following issues

Set pdf document to PDFView, in original OS,e.g. OS10.11 , there will invoke PDFView->drawPage() function, but in OS10.12,the function is not invoked;

PDFView can't draw pdf annotation in OS10.12;

Solution to the above will be appreciated

回答1:

I reckon this is either a straight out bug or an as yet undocumented API change. I logged this as a bug (27666426) and can see now that it is being flagged as an open duplicate (27668895).

Note that of 10.12 Beta 6 -drawWithBox:toContext: gets called in place of the now deprecated -drawWithBox:. Note that it is also necessary to use the passed in context for all drawing.

UPDATE:

However things do not seem that simple with the 10.12 now that it is released. I find that my PDF view printing, which is driven off of -drawWithBox: on 10.11 and -drawWithBox:toContext: on 10.12+ is broken.

Stepping through the assembler I can see that 10.12, when printing, now calls -drawWithBox:inContext: not -drawWithBox:toContext: or -drawWithBox: (as was the case on 10.11). It would seem that the inContext: selector has been around a while.

It would seem that the only solution that works on 10.9 - 10.12 for both screen and print renders is to use the undocumented -drawWithBox:inContext:.