开发者

Printing (Cocoa) WebView contents results in cut images

Is there any way to avoid the rendered HTML elements in a WebView from being cut when printing?

This is a sample of what I'm trying to avoid:

Printing (Cocoa) WebView contents results in cut images

I'm printing to PDF using the fol开发者_JAVA技巧lowing code:

// Copy the NSPrintInfo's sharedPrintInfo dictionary to start off with sensible defaults
NSDictionary* defaultValues = [[NSPrintInfo sharedPrintInfo] dictionary];
NSMutableDictionary* printInfoDictionary = [NSMutableDictionary dictionaryWithDictionary:defaultValues];

// Set the target destination for the file
[printInfoDictionary setObject:[savePanel URL] forKey:NSPrintJobSavingURL];

// Create the print NSPrintInfo instance and change a couple of values
NSPrintInfo* printInfo = [[[NSPrintInfo alloc] initWithDictionary: printInfoDictionary] autorelease];
[printInfo setJobDisposition:NSPrintSaveJob];
[printInfo setRightMargin:30.0];
[printInfo setLeftMargin:30.0];
[printInfo setTopMargin:70.0];
[printInfo setBottomMargin:70.0];
[printInfo setHorizontalPagination: NSFitPagination];
[printInfo setVerticalPagination: NSAutoPagination];
[printInfo setVerticallyCentered:NO];
[printInfo setHorizontallyCentered:NO];

// Create the print operation and fire it up, hiding both print and progress panels
NSPrintOperation* printOperation = [NSPrintOperation printOperationWithView:view printInfo:printInfo];
[printOperation setShowsPrintPanel:NO];
[printOperation setShowsProgressPanel:NO];
[printOperation runOperation];


It's highly likely that the problem there is in the CSS you're using to render the webview. Just make sure you're not using any container divs with "position: fixed".

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜