2

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

Community
  • 1
  • 1
linda
  • 51
  • 4

1 Answers1

2

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

Jonathan Mitchell
  • 1,339
  • 12
  • 17
  • Now the latest os10.12 operating system, PDF annotation can be displayed, but now I still have a problem, I recorded coordinate information in PDFView ->mouseDragged before, and then automatically will invoke the PDFView->drawPage function, this function I will draw the NSBezierPath curve to determine the dynamic annotation bounds. but now in the process of mouseDragged has not been call the drawPage:toContext function. I use the refresh method is still not invoke drawPage:toContext. would like to know how to call this function. Thank you very much for your help. – linda Sep 30 '16 at 06:17
  • I'm sorry. I don't use annotations, I just draw directly onto the view. Have you reviewed how [skim](https://sourceforge.net/projects/skim-app/) handles annotations? I know they had some issues on 10.12. – Jonathan Mitchell Sep 30 '16 at 11:45
  • I got this problem too. I found when I zoom in or zoom out, the annotation will show. But I don't know how to make it dynamic display. It seems the SetNeedsDisplay doesn't work. – SuperBerry Oct 02 '16 at 04:27
  • There is a new PDFAnnotation method `- (instancetype)initWithDictionary:(NSDictionary *)dictionary forPage:(PDFPage *)page;`. Might be worth checking out. – Jonathan Mitchell Oct 03 '16 at 10:36
  • Check out the updates above as well as http://www.cocoabuilder.com/archive/cocoa/178803-pdfmarkupannotations-not-showing-when-drawing-pdfpage.html – Jonathan Mitchell Oct 03 '16 at 11:43
  • @Jonathan Mitchell How to set the NSDictionary? What's that? Thanks – SuperBerry Oct 03 '16 at 14:15
  • See the header info in PDFKit/PDFAnnotation.h. I don't think it will resolve the issue. – Jonathan Mitchell Oct 03 '16 at 15:30
  • And I also found the PDFThumbnailView Outlets to the PDFView but the PDFThumbnailView doesn't show pages.... confused... – SuperBerry Oct 04 '16 at 00:32
  • @Jonathan Mitchell I have tried your modified answer but I cannot see the -drawWithBox:inContext: method in Xcode... – SuperBerry Oct 04 '16 at 00:34
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/124839/discussion-between-superberry-and-jonathan-mitchell). – SuperBerry Oct 04 '16 at 02:00