Cette question fait suite à une question précédente: Problems creating a Webview for printingGraphics ne figurant pas dans un Webview
J'utilise un Webview pour imprimer des parcelles créées à l'aide du cadre du terrain de base. Le code suivant est utilisé pour alimenter le Webview:
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];
Mon problème est que l'image n'apparaît soit dans la version imprimée de la Webview ou si j'instancier une fenêtre avec WebView en elle l'image ne apparaître. Si je prends le code HTML brut généré par le code, collez-le dans Coda puis prévisualisez-le, l'image apparaît sans problème. Quelqu'un peut-il me diriger dans la bonne direction pour la façon de résoudre ce problème. C'est probablement une erreur assez basique car je suis assez nouveau pour travailler avec des images et des Webviews.
Modifier
Il semble que le problème est lié au format du lien vers l'image parce que quand je remplace le fichier généré: /// ... lien avec html: // ... lien avec une image sur le web tout semble bien fonctionner. Cela n'explique pas pourquoi cela fonctionne dans Coda mais pas dans le Webview.