有什么方法可以避免打印时在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];

最佳答案

您用于呈现Web视图的CSS中很可能存在此问题。只要确保您没有使用带有“ position:fixed”的任何容器div。

10-08 17:03