Currently, I'm printing the contents of a WPF WebBrowser like so:
mshtml.IHTMLDocument2 doc = WebBrowser.Document as mshtml.IHTMLDocument2;
doc.execCommand("Print", true, null);
My HTML content has tables with background colors. Currently, when I print the content, the background colors do not print -- everything is solid white. Is there a way to tell the WebBrowser to print the background colors as well?
Also, this still causes a print dialog to pop up. Does anyone know what the command is to print the contents dialog-less?
Thanks a lot!
Assuming you're using 'SHDocVw.WebBrowser', you can use the ExecWB command. To print without the dialog, use the OLECMDEXECOPT_PROMPTUSER (1) constant. You can also pass an IE print template (just an HTML file) for more control over how the page is displayed.
It's something like this (taken from this MSDN question)
browser.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT,
SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER,
"print_template.html", ref nullObject);
As for the background, it appears to be one of the options you can specify in the print template's LayoutRect. All print dialog settings are stored in the registry, but a print template is preferable because it won't change system-wide settings.
Related
I have used WebBrowser control in xaml like below.
<WebBrowser x:Name="pdfviewer"/>
Also refer below for back end code
this.pdfviewer.Source = new Uri(#"C:\Users\VMH8COB\Desktop\UpdateRequestFormV2.pdf");
To hide the toobar I have used below code.
this.pdfviewer.Source = new Uri(#"C:\Users\VMH8COB\Desktop\UpdateRequestFormV2.pdf#toolbar=0");
It is working but if the escape key is pressed then adobe default side tool par will display. I want to disable print and save button else hide tool bar in all case.
I have searched for solution more than one week, but still I didn't get it.
Kindly help me on this.
Thanks.
I am building a mobile site and the footer has an background.
I want to check if the browser supports css property, background-image, if true display background with specific html, else display a different set of html.
I am using the following :
HttpBrowserCapabilities bc = new HttpBrowserCapabilities();
I can't seem to get a check for backgrounds.
The reason why I want to check for BG-image support is coz I have to switch between 2 sets of html. 1 with html text and bg image, and the other with the text on the image - sliced for each word/link...to give the same effect.
to get information by HttpBrowserCapabilities, you have to use Request.Browser property.
HttpBrowserCapabilities browerCapabilities = Request.Browser;
I think Asp.net will automatically check the type of the browser and render the page accordingly. So if the the browser don't support background images it will not come.
Another idea to solve the issue is getting the browser type by using code, then you can show or hide the background images based on the type.
I have a WPF application where I use a document viewer. I also start printing programmatically with documentviewer.Print(); However, when that is pressed it brings up the screen with the Windows printers and makes the user have to click "OK" again on that screen to start. Is there a way to avoid the confirmation and make documentviewer.Print(); immediately start the print job on the default Windows printer?
All you need is the default print queue, which you can get via
var pq = LocalPrintServer.GetDefaultPrintQueue()
From this, you can create an XpsDocumentWriter:
var writer = PrintQueue.CreateXpsDocumentWriter(pq);
Now, you can get the DocumentPaginator from your DocumentViewer via the Document property, which returns an IDocumentPaginatorSource that has a DocumentPaginator property:
var paginator = documentviewer.Document.DocumentPaginator;
and you can send that right to the XpsDocumentWriter's Write method:
writer.Write(paginator);
Simple, isn't it?
how can I print quickly without show print dialog just click on button and print in default printer ?
For WinForms, use the PrintDocument class and do not specify a printer, then it will print to the default printer.
I have not printed in WPF, but I found the following (maybe it will help?):
http://www.switchonthecode.com/tutorials/printing-in-wpf
Is there any way to convert normal window to modal window?
I have a grid with a image column.
As I click the image a window is appearing with the image.(using javascript window.open(...) )
But, as I click a different image in the grid a second window is appearing with respective image.
I dont want the user to be able to do anything else before closing the current window.
You can use
window.showModalDialog
Creates and displays a modal dialog
box containing a specified HTML
document.
Syntax
returnVal = window.showModalDialog(uri[, arguments][, options]);
returnVal is a variant, indicating the
returnValue property as set by the
window of the document specified by
uri.
uri is the URI of the document to
display in the dialog box.
arguments is an optional variant that
contains values that should be passed
to the dialog box
options an optional string that
specifies window ornamentation for the
dialog box, using one or more
semicolon delimited values
Because it's pretty complicated to achieve that behavior to work cross-browser, I'd go for a JavaScript code that generates a similar behavior with div elements.
You can use 3rd party components for that (like DevExpress' AspxPopupControl) or free open-source components like JQuery UI dialog.