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
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.
This is my first posting and my programmer status is keen amateur.
I have created a c# Form RichTextBoxPrintCtrl editor with print capability via a printDialog and printDocument control. Before I print I want to determine the page size (based on the number of characters) per print page. The code which calls the RichTextBoxPrintCtrl dll to get this info is:
checkPrint = richTextBoxPrintCtrl1.Print(checkPrint, textEnd, e);
with e being the printDocument PrintPageEventArgs.
The only way I can see to do this appears to be to actually print the document.
Is there a way to capture the printDocument PrintPageEventArgs and use them in the above code without actually printing?
The reason I want to do this is to have the ability to use the page from and page to facility within the printDialog. Any help would be appreciated.
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?
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.
There are some things that I didn't find how to do using geckofx:
Get the URL of a clicked link.
Display print preview window.
Does this functionality exist in geckofx? If not, what's the best way
to achieve it in a C# project that uses GeckoWebBrowser to display html pages?
Thanks
To get url of clicked link you can use:
void domClicked(object sender, GeckoDomMouseEventArgs e)
{
if(geckoWebBrowser1.StatusText.StartsWith("http"))
{
MessageBox.Show(geckoWebBrowser1.StatusText);//forward status text string somewhere
}
}
To show print dialog box you can use:
geckoWebBrowser1.Navigate("javascript:print()");
OnNaviagted event should give you the link, and look for the print interfaces nsIPrintingPromptService::ShowPrintDialog in Geckofx.
geckoWebBrowser.url
That will give you the url at any point I believe where geckoWebBrowser is the name of the control, however as pointed out you'll be able to get it from the document completed and navigated events using e.url .
For printing, see this forum thread. Make sure to read it all before starting. Essentially you'll have to patch and recompile GeckoFX.