2011-06-09 85 views
1

有什么办法避免WebView中呈现的HTML元素在打印时被剪切?打印(可可)WebView内容导致剪切图像

这是我想要避免样品:

WebView image rendered in webview, cut when printed

我用下面的代码打印到PDF:

// 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]; 
+1

我记得在CSS中有一些东西可以(至少在理论上,如果它是在相关版本的WebKit中实现的)影响渲染器来解决这个问题,但我不记得写了一个完整答案。抱歉。 – 2011-06-10 08:49:09

+1

有'page-break-before','page-break-inside'和'page-break-after',但很遗憾,只有Opera支持'-inside',而Safari支持'-before'和'-after',它不支持“避免”它们的值。 – biasedbit 2011-06-10 17:52:51

回答

1

这是极有可能的问题您正在使用的CSS呈现web视图。只要确保你没有使用任何带有“position:fixed”的容器div。