有没有办法避免在打印时剪切WebView
中呈现的HTML元素?
这是我试图避免的一个例子:
我使用以下代码打印到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];
答案 0 :(得分:1)
你用来渲染webview的CSS很可能存在问题。只要确保你没有使用任何带有“position:fixed”的容器div。