如何使用UIMarkupTextPrintFormatter打印带有本地图像的本地html? [英] how do I use UIMarkupTextPrintFormatter to print a local html with local images?
问题描述
以下是我要打印的字符串:
Here is the string I want to print:
<p><img src="/Users/Max/Library/Application Support/iPhone Simulator/4.3/Applications/5FCCB847-52D9-48F4-A900-459C6A77A5A6/Documents/18/logo18_lg.jpg" alt="" height="72" /></p>
这是我在我的应用程序中生成的较大HTML页面的一小部分,我正在路过像这样打印:
This is a small fragment of a larger HTML page I have generated in my application, and I am passing to this to the print like so:
UIMarkupTextPrintFormatter *html = [[UIMarkupTextPrintFormatter alloc] initWithMarkupText:printContents];
其中打印内容包含我需要打印的所有html,包括上面的图像片段。对于不打印的图像,打印效果非常好。
Where print contents contains all of the html I need to print including the image snippet above. The printing works great EXCEPT for the images not printing.
推荐答案
我喜欢被反驳,但我不认为你可以得到你正在寻找的方法。解决方法是将图像嵌入HTML本身。以下说明了原理(改编自 2005年论坛帖子。您可以创建一个字符串来动态表示您的图像。一个好的起点可能是这个 stackoverflow问题。
I'd love to be contradicted, but I don't think you can get the approach you're looking at to work. A work around is to embed the image into the HTML itself. The following illustrates the principle (adapted from this forum post from 2005). You can create a string to represent your image on the fly. A good place to start might be this stackoverflow question.
- (void) buttonTapped;
{
NSString* printContents = @"This is a work around <IMG SRC=\"data:image/gif;base64,R0lGODdhMAAwAPAAAAAAAP///ywAAAAAMAAwAAAC8IyPqcvt3wCcDkiLc7C0qwyGHhSWpjQu5yqmCYsapyuvUU lvONmOZtfzgFzByTB10QgxOR0TqBQejhRNzOfkVJ+5YiUqrXF5Y5lKh/DeuNcP5yLWGsEbtLiOSpa/TPg7JpJHxyendzWTBfX0cxOnKPjgBzi4diinWGdkF8kjdfnycQ ZXZeYGejmJlZeGl9i2icVqaNVailT6F5iJ90m6mvuTS4OK05M0vDk0Q4XUtwv KOzrcd3iq9uisF81M1OIcR7lEewwcLp7tuNNkM3uNna3F2JQFo97Vriy/Xl4/f1cf5VWzXyym7PHhhx4dbgYKAAA7\">";
UIMarkupTextPrintFormatter *html = [[UIMarkupTextPrintFormatter alloc] initWithMarkupText:printContents];
UIPrintInteractionController* printController = [UIPrintInteractionController sharedPrintController];
[printController setPrintFormatter:html];
[printController presentAnimated:YES completionHandler:^(UIPrintInteractionController *printInteractionController, BOOL completed, NSError *error) {
//
}];
}
这篇关于如何使用UIMarkupTextPrintFormatter打印带有本地图像的本地html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!