views:

165

answers:

6

I need to display reports and things in HTML using Microsoft's HTMLDocument object.

Unfortunately, you can give the document HTML markup, but you cannot give it images. It is only able to display images you get from a URL, e.g.:

  • http://
  • file://
  • res://

As a workaround I figured I could construct an image using HTML markup, pixel-by-colored pixel.

Has there been any work in this area? Should it be absolutely positioned 1x1 colored spans? A 350x200 table, with rows and columns both one-pixel in size?

+1  A: 

People have, much to the horror of all, done some solid work in this area. The solution I link to uses tables with RLE compression, which seems smart enough to me.

chaos
This is interesting. I actually never thought of something like this...probably because it's really not useful, but still cool.
"URI-encoded images have made table-encoded images obsolete (except for Internet Explorer)"
Ian Boyd
+5  A: 

The simplest way, in my opinion, is to use a base64 encoded image. It's efficient enough, and there are tools to automate generation: http://www.greywyvern.com/code/php/binary2base64.

FWH
+1 because I can't imagine why this merits a -1.
chaos
+1 this thing is just great .. thanks
Xinus
A: 

I wrote a PHP class a few years ago to do this, but I wouldnt recommend using this in the real world as it takes a long time for a browser to render a table big enough for an image.

Unless I'm not understanding your question correctly, why can't you refer to the image using a full URL:

http://somewhere.com/myimage.jpg

Jacob Wyke
Because there is no static image that exists as any resource anywhere. Imagine an a report in HTML that shows a graph constructed in memory.
Ian Boyd
+2  A: 

First, a word of caution: this is an awful, terrible thing you are planning to do.

Now that we've got that out of the way, I happen to have done a good deal of this terrible thing. I can tell you that you're best bet is to use tables, not divs or spans. Even so, it's terribly inefficient and takes forever to load, as you can see from the samples I linked to. Just don't do it, other than as a perverse joke.

Pesto
You just had to include a picture of me in your answer, didn't you?
Welbog
@Welbog: I did?! Which pony are you?
Pesto
@Pesto: The prettiest one.
Welbog
I didn't know ponies could have afros!
Geoffrey Chetwood
+6  A: 

Can you just use the Data URI scheme?

IE8 supports this (as do most newer browsers); your images would look like this:

<img src="data:image/png;base64,A0123...==">

where the A0123... stuff is a base64 representation of an image file. Depending on the language you're using, you may be able to take advantage of Convert.ToBase64String() to do much of the work for you.

Daniel LeCheminant
When i first started trying to use mshtml for reports, IE5, there was no such thing. This is probably the answer going forward.
Ian Boyd
A: 

"reports and things"... could be a bit clearer here...

If what you ultimately want to do is display a report which happens to be dynamically generated, chances are you can automatically generate an image of the report. 'Export to PDF' is probably available in the report tool. Crude, but simpler and more efficient than where you seem to be headed now.

mickeyf
"Export to PDF" option is not available in the report tool. Also the report tool is buggy, and will usually cause a crash - which is why i want to move away from it. And all other reporting tools require you to ship external code (dll, etc) to create reports - not an option.
Ian Boyd
Printing to PDF with something that emulates a printer, such as cutePDF? That would require you to at least ship a freeware PDF printer emulator, so if shipping any external code is ruled out that won't help. Still sound like less work than the proposed alternative, but if you have business or 'political' constraints I guess you're stuck. "the report tool is buggy" - this sounds like a new and different problem.
mickeyf