Display Assembly Resources in Web Browser (problem with jpg/pdf)
-
Hello, I have 3 types of resources embeded in my executable : html, jpg and pdf. I also have a listbox, and I want whenever a user sleects a different item, to display it in a web browser. I have no problems doing that to HTML files, but with the other one, it's a different thing and I hope someone can help me do this. First, I want to say that I don't want to save the resources locally and after that load them in the browser, because I don't want users to see them. I am using this to view the html :
Assembly assembly = Assembly.GetExecutingAssembly(); webBrowser1.DocumentStream = assembly.GetManifestResourceStream("ebook.index.html");
If I try to do the same thing to the pdf or jpg, it simply shows me the binary data of the files, it does not display them in the browser. Is it possible to make the visible in the browser, directly from the assembly ? What are my options ? Thank you -
Hello, I have 3 types of resources embeded in my executable : html, jpg and pdf. I also have a listbox, and I want whenever a user sleects a different item, to display it in a web browser. I have no problems doing that to HTML files, but with the other one, it's a different thing and I hope someone can help me do this. First, I want to say that I don't want to save the resources locally and after that load them in the browser, because I don't want users to see them. I am using this to view the html :
Assembly assembly = Assembly.GetExecutingAssembly(); webBrowser1.DocumentStream = assembly.GetManifestResourceStream("ebook.index.html");
If I try to do the same thing to the pdf or jpg, it simply shows me the binary data of the files, it does not display them in the browser. Is it possible to make the visible in the browser, directly from the assembly ? What are my options ? Thank youHi, I haven't done this myself, but the way I understand it you must also set the WebBrowser.DocumentType (try "application/pdf"); that should allow you to view a PDF document (or any image) as a web page. You probably also want images inside web pages, so have a look at embedded images[^]. :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
Hi, I haven't done this myself, but the way I understand it you must also set the WebBrowser.DocumentType (try "application/pdf"); that should allow you to view a PDF document (or any image) as a web page. You probably also want images inside web pages, so have a look at embedded images[^]. :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
Hello, Thank you for the quick reply but unfortunatly the DocumentType is read only :( Any other ideeas ? Thanx
Yes, you are right. And the data scheme[^] is usable only for small amounts of data, hence small images only, no PDF documents. I guess the next logical approach is to come up with a simple HTTP server that can provide HTML and PDF; then embed that in the app, andmake the WebBrowser navigate to it. This seems to be a candidate: Sample HTTP Server Skeleton in C#[^] :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
Hello, Thank you for the quick reply but unfortunatly the DocumentType is read only :( Any other ideeas ? Thanx
Hi, I now have a simple embedded HTTP server working based on the article I provided a link to. It gets a PDF document somewhere (from a file!), then serves that to its client, which can be either a regular browser (e.g. FireFox) or a WebBrowser. It still needs a lot of clean-up though, but I wanted to confirm you can make it work. :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
Hi, I now have a simple embedded HTTP server working based on the article I provided a link to. It gets a PDF document somewhere (from a file!), then serves that to its client, which can be either a regular browser (e.g. FireFox) or a WebBrowser. It still needs a lot of clean-up though, but I wanted to confirm you can make it work. :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.