开发者

Create a document with embedded images

开发者 https://www.devze.com 2023-03-13 03:37 出处:网络
I\'m trying to create a document (i.e. .doc,.html) with embedded images with objective-c. The images are stored locally on the iPhone.

I'm trying to create a document (i.e. .doc,.html) with embedded images with objective-c.

The images are stored locally on the iPhone.

For example, I've created an html using img tag and the file uri scheme. Then I saved the html code on a .doc file. But the images are not displayed.

The same thing happens if I save the html code as an .html file.

[body appendString:@"<img src='"];
[body appendFormat:@"file:/%@", absolutePa开发者_StackOverflowth];
[body appendString:@"' />"];

where absolutePath is the path of the image on the device (I printed it and it's right).

Any suggestion?


Unfortunately you can't link to local files in HTML directly. There is a trick however: using a local substitution cache that redirects the download of the image and returns a local image instead. If the code creating the document and the cache both agree on what URL points to which image, you can get local images to appear in your HTML.

Refer to this excellent blog post to learn about how to implement such a substitution cache: http://cocoawithlove.com/2010/09/substituting-local-data-for-remote.html

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号