2011-06-09 84 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。