2

In my app I'm presenting a report of the app data. The report is a "self-generated" html file presented on an UIWebView.

I need to include in the report (in the html file) an image that is stored in the device. At this moment I'm able to get the path of the image. It's something like "/var/mobile/Applications/A10781A1-DE2B-4651-ADFB-7A6AD9B3645A/Documents/EE20AF92-215E-4DF5-8E33-0713557A34C9"

How can I include the image in the html file?

0

2 Answers 2

7

You can include the image using:

<img src="img.png">

and

NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[webView loadHTMLString:htmlString baseURL:baseURL];

You can copy your image img.png to documents directory for example and set the baseURL to be the Documents directory.

Update:

I found the source where I found out how to do it some time back. Maybe you can dig from there some more useful info: http://iphoneincubator.com/blog/windows-views/uiwebview-revisited

Sign up to request clarification or add additional context in comments.

1 Comment

You got it! Setting the baseURL and it found the image at the moment. Thanks a lot
0

Its not clear if your building the html on the fly from your question. But you can do something like this.

NSMutableString *htmlPage = [[[NSMutableString alloc] initWithCapacity:1000] autorelease];
... // Build the page string

[htmlPage appendStringWithFormat:@"<img src=\"%@\" alt=\"image\" height=\"100\" width=\"100\"/>",[[NSBundle mainBundle] pathForResource:@"myImage" ofType:@"png"];

Or some variant of this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.