html - 打印 (Cocoa) WebView 内容会生成剪切图像

标签 html cocoa image webview

有没有办法避免打印时 WebView 中渲染的 HTML 元素被剪切?

这是我试图避免的示例:

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];

最佳答案

问题很可能出在您用来渲染 webview 的 CSS 中。只需确保您没有使用任何带有“position:fixed”的容器 div。

关于html - 打印 (Cocoa) WebView 内容会生成剪切图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6297744/

相关文章:

html - 调整视口(viewport)大小时显示 : table; with fixed width cell leaves 1px space

javascript - 每 2 秒的 iframe 高度 [动态]

javascript - 转换(剪切)可拖动的 div

html - 如何配置html日期输入的默认值

cocoa-touch - Wifi与核心资料库样式同步

objective-c - 如何将文本字段绑定(bind)到包含一行的一个核心数据实体的属性?

macos - 动画自动调整 NSTableView 行高

html - svg 图像在浏览器中的位置

c# - 如何在图像中的对象周围得到矩形?

javascript - addEventListener 更改从一个类中选择的 id 的 CSS 样式