开发者

Printing with multiple WebViews

开发者 https://www.devze.com 2023-03-14 09:54 出处:网络
I am trying to implement a print view for use with an NSPrintOperation which uses many WebViews for rendering content. Think of keynote-like slides, where each slide i开发者_JAVA百科s a WebView.

I am trying to implement a print view for use with an NSPrintOperation which uses many WebViews for rendering content. Think of keynote-like slides, where each slide i开发者_JAVA百科s a WebView.

To do this efficiently, I am trying to just add the WebViews that are needed for the current page.

I have tried adding the WebViews directly as subviews of the main print view, but the WebView does not layout properly, even if I delay returning from the printing method to give it a chance to finish.

I then tried using cacheDisplayInRect:toBitmapImageRep: on the WebViews, and using the result in an NSImageView instead of adding the WebViews directly to the print view. This works, but the print quality of a bitmap is not as good as I would like.

Lastly, I thought I could instead generate a PDF, and use that. But the dataWithPDFInsideRect: method suffers from the original problem, where the layout is messed up.

How could I get the WebViews to layout properly when subviews of the printing view, or generate a PDF along the lines of cacheDisplayInRect:toBitmapImageRep: which could be used with NSImageView?


Seems I found a solution to this myself. If I use the method displayRectIgnoringOpacity:inContext: to draw each WebView, rather than adding them as a subview to the printing view, the layout is fine. Doing this is probably what cacheDisplayInRect:... is doing behind the scenes.

0

精彩评论

暂无评论...
验证码 换一张
取 消