Cocoa osx PDFView NSPrintOperation PrintPanel not showing page preview

后端 未结 2 1939
不知归路
不知归路 2021-01-21 03:13

In my app for Mac I have a webview that shows some html content. I create a PDFDocument from that webview and then I want to print that document. So I create a PDFView from the

2条回答
  •  日久生厌
    2021-01-21 03:26

    At a guess, since PDFView is a subclass of NSView, whose designated initializer is -initWithFrame:, not -init, your call to PDFView *pdfView = [[PDFView alloc] init] may not be allowing the PDFView to set up its initial state, though subsequent calls to its machinery may be magically resolving this state for you but NSView and subclasses tend to behave strangely (particularly with respect to drawing) when you don't use the proper designated initializer (which means its frame and bounds are equal to NSZeroRect).

    Try using -initWithFrame: with some reasonable, non-zero rectangle.

    Update

    Alright, just a wild shot in the dark, but the documentation for NSPrintOperation says that -runOperation blocks the main thread and recommends using -runOperationModalForWindow:delegate:didRunSelector:contextInfo: to avoid blocking the main thread entirely. Is it possible that by blocking the main thread something else is being prevented from doing its initial work (I'd call this either undocumented behavior or an API bug, but...)? Try implementing the modal version instead and see if that helps. If not, I'd actually file a bug report with Apple.

提交回复
热议问题