0
出现这个问题从以前的问题如下操作: Problems creating a Webview for printing图形不是在网页视图
我使用的是网页视图打印地块使用核心情节框架创建。下面的代码被用于填充网页视图:
NSData *imageData = [[barChart imageOfLayer] TIFFRepresentation];
NSString *temporaryImagePath = NSTemporaryDirectory();
NSError *error = nil;
NSBitmapImageRep* imageRep = [NSBitmapImageRep imageRepWithData:imageData];
NSData* pngData;
pngData = [imageRep representationUsingType:NSJPEGFileType
properties:nil];
temporaryImagePath = [temporaryImagePath stringByAppendingPathComponent:@"jpegData.jpg" ];
[pngData writeToFile:temporaryImagePath
options:NSDataWritingAtomic
error:&error ];
WebView *printView;
printView =[[WebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 1000)
frameName:@"printFrame"
groupName:@"printGroup"];
NSString *theCSSString = [self theFileCodeForString:@"OutputFormat"
withExtension:@"CSS"
withContents:@"<style type=\"text/css\">#results {font-family:\"Trebuchet MS\", Arial, Helvetica, sans-serif;width:100%;border-collapse:collapse;} #results td, #results th {font-size:1em;border:1px solid #98bf21;padding:3px 7px 2px 7px;} #results th {font-size:1.1em;text-align:left;padding-top:5px;padding-bottom:4px;background-color:#A7C942;color:#ffffff;} #results tr.alt td {color:#000000;background-color:#EAF2D3;} </style>"];
NSMutableString *theURLString = [[NSMutableString alloc] initWithString:@"<html>"];
[theURLString appendString:@"<head>"];
[theURLString appendString:theCSSString];
[theURLString appendString:@"</head>"];
[theURLString appendString:@"<body>"];
NSURL *tempImageURL = [NSURL fileURLWithPath:temporaryImagePath];
[theURLString appendFormat:@"<img src=\"%@\"/>", [tempImageURL absoluteString]];
[theURLString appendString:@"</body></html>"];
[[printView mainFrame] loadHTMLString:theURLString
baseURL:[NSURL URLWithString:@"xxxx"]];
[[[[printView mainFrame] frameView] documentView] print:sender];
[printView release];
我的问题是图像不会出现无论是在打印的网页视图的版本,或者如果我在它实例化与网页视图窗口中的图像不出现。如果我采用代码生成的原始HTML,请将其粘贴到Coda中,然后预览它,图像显示没有问题。任何人都可以指出我如何解决这个问题的正确方向。这可能是一个相当基本的错误,因为我对图像和Webviews的工作相当陌生。
编辑
它看起来像这个问题涉及链接到图像的格式,因为当我更换生成的文件:/// ...链接与HTML:// ...与网络上的图像链接一切似乎工作正常。这并不能解释为什么它在Coda中工作,但不在Webview中。