I have HTML generated on a form. If you click a button, the HTML is generated and is currently placed in a ASP Textbox with just the text
<!doctype html><html>....</html>
and I want to automatically print this HTML (including the styling that is only for the generated body).
How can I do this?
To print your code you need to do several things
Tell the browser what to print, here's a few ideas, or create a new window with only the stuff to print.
Find a way to show the plain code, like using <pre> tags or the mentioned CodeMirror
Launch the print dialog, a simple javascript basically something like window.print()
There will be no automatic printing (unless you target IE with some black magic) as that would be insane to allow on the web.
I hope I understand your question correctly. CodeMirror is the one you might want to try. It displays and formats HTML text with colors.
http://codemirror.net/mode/htmlmixed/index.html
You will need to trigger the print request using Javascript, but you can set this off using C# (look at the ClientScriptManager for usage).
The window.print() function is what you need.
You will presumably want to restrict what you print, take a look at this SO post for ideas.
Related
I am working on a website & it required to show a counter on home page.So I used an asp label as a counter that counts & display the DB records (i.e. 180000).It is working perfectly alright.
Now problem is that.I want to make it embed able
I want to embed that label to other websites.
e.g : <EMBED SRC="http://www.XXXX.com/graphics/sounds/18.mid" HEIGHT=60 WIDTH=144>
It should be dynamic (Counter Changes on home page should reflect where this counter has been embedded i.e. on blogs or on forums ) .
How can I do this?
Also what would be the best approach,a simple embed code, a iframe or through Java Script?
Thanks
There are lots of ways to do this. Without more information, it's hard to recommend an exact method. If all you want to do is display a number in html, then you can simply create an aspx page that writes the number and then let people iframe to it.
If you want to get more dynamic, you can create a generic ashx handler, or set up a web service that displays that information for you.
I have the following code in my C# windows app which places the data from my webbrowser control into the clipboard. However when I come to pasting this into MSWord it pastes the HTML markup rather than the contents of the page.
Clipboard.SetDataObject(WebBrowser.DocumentText, true);
Any Idea how I can get around this?
OK this feels like a dirty hack, but it solves my problem:
WebBrowser1.Document.ExecCommand("SelectAll", false, null);
WebBrowser1.Document.ExecCommand("Copy", false, null);`
Another option would be to capture an image of the page, rather than the html and paste that into the document. I don't think the WebBrowser control can handle this, but Watin can. Watin's (http://watin.sourceforge.net/) capturewebpagetofile() function works well for this functionality. I have had to use this instead of capturing HTML because outlook cannot format HTML well at all.
string allText = WebBrowser1.DocumentText;
will return you all currently laoded document markup. Is it what are you lookin for?
I guess that happens because what the webbrowser actually contains is the markup, not all the images etc.
You might be best to use the webbrowser to save the full page to disk, and then use word to open that. That way it'll all be available locally for IE to use. Just means you have to clean up afterwards though.
The link below has some stuff about saving using the webbrowser in c#
http://www.c-sharpcorner.com/UploadFile/mahesh/WebBrowserInCS12072005232330PM/WebBrowserInCS.aspx
I have a print function using JavaScript that prints just the contents of the iFrame and not the page the iFrame is in. What I want to do is have a DIV or something in the page being access through the iFrame that will go visible when you print and have a legend on it and then it will go back to invisible once the page is printed? Any help on how to do this? I am not the most adept at using JavaScript but will try it.
Thanks,
Forget the JavaScript. Trying to fiddle the page around a print from script is complicated, fragile and pointless. This is what a print stylesheet is for!
Add a stylesheet with media="print" which contains display: rules to hide all the parts of the part you don't want printed, and cause normally-hidden parts of the page to appear when being viewed on a printer. You don't even need a scripted print button, the normal web browser Print function will pick up the differences.
The IFrame Javascript element has a document property, which works identically to the normal page's document property.
That being said, if your IFrame's framed page is on a different domain from your framing page, you are probably out of luck. Browsers limit what one site can do to another site to prevent cross-site scripting attacks, and these limits will prevent you from accessing the framed page's document (unless it's on the same domain or you setup a cross-site file on the framed page's server).
I'm hoping people have some ideas to help solve this problem.
I am developing a C# ASP.NET website and the client requires an online form that users will fill in and submit. OK, so far so good.....
Imagine, say, a form that you fill in on paper - they normally have a distinctive look specific to the company and will be filed, quite possibly as a legally binding document.
I need to have an online form that when submitted emails the client with something they can print out and will look exactly like their printed forms.
As this is web based, I think the option of capturing a screenshot are out the question, so I'm wondering how best to approach this?
Even if I just had a form that captures the data presented how I want, how could I translate this data into the view they want?
Any ideas and suggestions greatly appreciated.
You'll need to take the raw data that was submitted and import it into a standard document (likely PDF). You can use Crystal or another reporting solution, or direct to PDF using one of the many PDF .NET solutions that are out there.
I don't think you'd even want to deal with making the document physically match the screen - much easier to make the web look like the web, and make the printed doc look like a printed doc.
Print a page (this one) from a Browser, notice all the headers and footers?
If you want serious control over how it is going to look, you will need to generate a PDF (or maybe XPS).
Couldn't you just use a sepparate page with a CSS that gives the desired look & feel?
I am making a prompt in C# that instructs the user how to use the program before they can access it.
What is the best way to display multiple lines of static text? Using a bunch labels doesn't seem like it would be the proper way... xD
Use a text input box marked as read-only and multi-line.
If you're using WinForms, you might want to consider adding a WebBrowser control to your form - you can then point the browser to an html file you send with the program. This allows you to use all of html to instruct your users, as well as point them to, say, your web site for more help or information.
One label can contain multiple lines of text if the text has newlines in it.