Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing Entire Contents of WebView in Cocoa, Not Just Displayed

So I am currently trying to print a pdf that I have loaded into a WebView in a Cocoa application, which is sized to where if you want to see the whole thing you have to scroll. The problem is that whenever it prints, it only prints what is currently displayed in the WebView and not the entirety of the page, with code like this:

    [[[[WebView mainFrame] frameView] documentView] print:sender];

I'm not sure if I am just trying to print the wrong part of it, or just need to go about this in another way, and would greatly appreciate some help.

like image 945
Zoz Avatar asked Jul 08 '13 14:07

Zoz


1 Answers

I see that this is an old question, but since there aren't any answers yet, I thought I would provide this for anyone searching.

NSPrintInfo *printInfo = [NSPrintInfo sharedPrintInfo];

// This is your chance to modify printInfo if you need to change 
// the page orientation, margins, etc
[printInfo setOrientation:NSLandscapeOrientation];

NSPrintOperation *printOperation = [yourWebView.mainFrame.frameView 
                                    printOperationWithPrintInfo:printInfo];

// Open the print dialog
[printOperation runOperation];

// If you want your print window to appear as a sheet instead of a popup,
// use this method instead of -[runOperation]
[printOperation runOperationModalForWindow:yourWindow
                                  delegate:self 
                            didRunSelector:@selector(printDidRun)
                               contextInfo:nil];
like image 101
aapierce Avatar answered Sep 20 '22 15:09

aapierce