Question

I have a WebView that I want to save as a WebArchive. I just want to save the HTML part and not the referenced images. When I do the following, it appears to be creating a WebArchive with the images embedded as well.

[[[[[sourceSignatureWebView mainFrame] dataSource] webArchive] data]
  writeToFile:@"MyWebarchive.webarchive" atomically:YES];

Besides the fact that I don't want to embed the images, Safari seems to have trouble displaying the file and is showing a lot of binary gibberish wrapped around the HTML part I want. I know I can use textutil to create the file, but if possible would like to do it all inside Cocoa.

Does anyone know if this is doable? Any ideas would be much appreciated. Thanks!

Was it helpful?

Solution

How about something like this:

WebDataSource *dataSource = [[sourceSignatureWebView mainFrame] dataSource];

WebArchive *archive = [[WebArchive alloc]
                       initWithMainResource:[dataSource mainResource]
                       subresources:nil
                       subframeArchives:nil];

[[archive data] writeToURL…

Or are you actually after an HTML file rather than web archive?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top