Printing from the web at client side - c#

How can we print using print document so that we can control the printer paper size?
It must be controlled after web
hosting is done without the print
dialog popup or javascript popup.
It should print on the client's printer
after webhosting without the print
dialog option and setting the paper
size.
It should be done in C# .net

As a user I don't want that when I enter a site someone to change my printer's settings or to take control over my printer.
For security reasons I hope this is not possible.

Your best option is to generate PDF-files with the appropriate siez in it. A printer should choose the correct page-size based on that unless the user manually changes it in the print-dialog.
Cirrcumventing the print-dialog is a security-restriction, ActiveX or a firefox-extension is your only alternative then, which might be okay on an intranet-based webapplication.

The only way that I've been able to have this amount of control over the printer client side is to create an ActiveX component that would handling the printing interface and go from there. It's not cross-broswer not the cleanest solution; however, it's the only way that I've been able to manage paper size. I looked into a CSS #print options but was not able to find one that could truly control the size.
The only other possibility is to look to see what printing capabilities something like Flash or Silverlight have. I'm not familiar enough to say if they do or don't have what you're looking for; however, it may be another option.

I believe a Java applet has the ability to set paper size if you grant it the proper privileges. I think your users will almost certainly have to jump through hoops for this to work...

Maybe too late but I'm adding for future reference; you could use a kind of download/print manager utility. Imagine the torrent magnet links, you click a link and a .torrent file opened by torrent client, it reads the necessary info and do the rest at client site.
So you have to write a little utility which one recognizes these 'print jobs' from your web site. You click a [Print Invoice] link and browser downloads a unique .print file and the utility captures it.
The .print file has two parts: 1. Header and 2. The file (pdf/jpg/any). Header contains predefined printer/paper size/orientation/etc or just asks for user input. And then prints the file from 2. part/body.
You may also queue the print jobs and manage them as well.
You have to install that utility; define a protocol like http:// or ftp:// to capture print links from the utility. And set printers/papers/etc for specific jobs like invoices/color printings/etc.
These will be what I'll do when I port our winforms app to web. Plus If you are on a LAN environment then you would print the things from the web server to network printers.

I have looked into this before, and the only way to force things like portrait/landscape etc, is to get the user to install an ActiveX control (or similar).
Javascript or CSS alone cannot do it.

Related

How can I launch a windows application from a webpage?

We have a company intranet and the powers that be think it would be nice to have a collection of icons/links representing the applications that most reps use (Outlook, Excel, few other apps).
The idea would be that if the application is installed, clicking the link/icon would launch the application on the client machine.
Anyone ever had a requirement like that and been successful implementing it?
Wanted to reach out to everyone before I go back and say no. Thanks in advance for any replies.
Make each button be a link to download a company template file for the given application. For example, the "Excel" button would download and the user should be prompted to open it with Excel.
For instance, try clicking one of the links here:
http://www.google.com/#sclient=psy&hl=en&q=template+filetype:xls
Linking to static files on the web server should be sufficient, so long as your server sends the correct MIME-Type or Content-Type.
You will probably have to adjust browsers' security settings to allow them to follow the links, but you should be able to use URLs of the form file:///C:\\Program Files\\Notepad.exe (You might prefer to use normal slashes / instead, as you don't have to watch out for how many copies of \ are needed to get past quoted string interpretation in whatever you're using to design the web page(s).
Using IE on a local intranet we have implemented this in an ActiveX control. Josh Pearce's solution works for those types of apps with MIME types, but not all apps you may wish to open would work this way.

Programmatically changing the destination printer for a WinForms WebBrowser control

I'm trying to use an invisible WebBrowser control to print a very simple HTML document. Our application requires that we be able to print several documents this way, and that they all can be sent to different printers. Unfortunately, I haven't been very successful in making the output go to the right printer.
The way it works right now is that before printing a document, the application determines which printer is to receive it, and sets the default printer accordingly. To do this it uses SetDefaultPrinter() imported from WinSpool.drv. If I step the code in debug mode I can clearly see that the default printer changes (and this change is reflected in the control panel UI), but the WebBrowser still insists on using the original default printer.
The MSDN documentation, from what I've seen, doesn't really provide a solution for this scenario. I would greatly appreciate some input on how I can accomplish this programmatically.
Given what you've said, perhaps if you restart the process which contains the web browser control (or the process which is the web browser control), after you change the default printer? That's the kind of thing I see happening here, for example.
I suppose it would be possible to fork off a background process that does the actual printing, but I'm really hoping for a simpler solution.
Forking was my first thought towards a probably-simplest solution.
Some other alternatives are as follows.
1). IE, which the webbrowser control is wrapping, exposes APIs via ActiveX. One of its/those APIs might let you specify the destination printer.
2). Some executables (I don't know about IE) have printto entries in the registry. For example, Acrobat Reader has an entry whose value is as follows:
""C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe"" /t "%1" "%2" "%3" "%4"
That's used for specifying the syntax of the command-line which you can use to print and specify a (non-default) printer. You can also Google for printto, see e.g. PrintTo command in the ShellExecute.
3). I have implemented an HTML control for .NET of my own, which doesn't depend on IE. You say that your HTML (and CSS I presume) are simple, so perhaps I can render it, either out of the box or with only a little extra development effort. I don't support printing, but printing is quite easy for a user control to implement. Getting me to implement that for you would cost you several hundred but, who knows, maybe it's worth it to you. It would be quite a light-weight solution, and perhaps well supported. You could email me if you want to discuss that further.
4). You might also find other controls, similar to mine, more or less famous/expensive; or other applications, e.g. OpenOffice etc etc.
5). You could consider converting the HTML (somehow) to another format (e.g. PDF) for which you have an application which gives you better support for printing.
I've had the exact same problem, and incorporated this control instead of the standard .NET WebBrowser to work around it.
This works on .NET 3.5, if not before
this.webBrowser1.ShowPrintDialog();

How to disable the folder navigation in FileUpload control

How to disable the folder navigation in the browse file popup window that appears when browse button is clicked in FileUpload control.
Currently, the browse file popup window shows specific folder which contain subfolders and files; I want to limit the user; user should not be able to browse/navigate through the upper level folders.
The asp.net server control is really just a wrapped html input type=file . The problem you're experiencing isn't limited to ASP.net and unfortunately, there's no way to affect the browser's behavior on that from your app.
You can't do this with an input type=file but you may be able to if you can use a flash-based file upload control instead.
The standard controls don't allow much flexibility. Possibly a more specialized component can help...
You'd likely have to download a component or plugin to the user's browser that the user allows to install so you can access their local file system and custom traverse it. This used to be done with IE/ActiveX in the Windows world, but there were/are a lot of security issues with it and it's platform restrictive.
A .NET-based component is Silverlight File Uploader.
I think Telerik's File Upload control is somewhat flexible, and there are many similar 3rd-party components out there.
Possibly use Flash like Gmail's email attachment upload component, concept shown this ASP.NET sample on CodeProject.
Also you might consider a Java applet on the client like facebook's Image Uploader; for a similar developer component you might start looking into something like Java Uploader,
All these client solutions are open or make source code available to help with ideas, except Telerik. All solutions are ubiquitous enough to support multiple browsers. Each component allows traversal of the local hard drives using a different UI/technology. I assume custom traversal or configuration is afforded by each to a degree.
Expect the component to be secure first and secondly flexible for the programmer.

IE automation and SQL reporting services c#

I'm working on a project for work that has me running a SQL reporting services report all day long. I would like to automate this process and have gotten pretty far in the process. I can navigate to the page, search for what I want, select the output of the file and click export. The problem I run into is the File Download dialog box that pops regardless of file type or mime settings. I am able to get around it now by using an AutoIt function but its flaky at best. I really want to just download the file to a specific location. My question.. Is there a way to intercept whatever clicking the export button does and get some sort of link to the file? Or is there a way to run the function that link does in asp programmaticly and grabbing the file that way? (Sorry if terminology is off not real familiar with ASP).
Edit... I know there are better ways of doing this with reporting services such as subscriptions etc (thanks for the responses btw :)... But this is what I'm stuck with until I can get the admin to fix a few things. In the company I'm at that involves getting about 20 different departments involved and it will most likely not get fixed. But ultimately my question is whether it is possible to do what im asking in C#. Can I intercept where the code is sending me when I click export and grab the file? Is that even possible?
Check if you can use URL Access directly against the Reporting Services server: http://msdn.microsoft.com/en-us/library/ms153586.aspx.
If you can modify the web application, try changing the value of ReportViewer.ExportContentDisposition (http://msdn.microsoft.com/en-us/library/microsoft.reporting.webforms.reportviewer.exportcontentdisposition.aspx) to "AlwaysInline". Alternatively, you can use the Render method (http://msdn.microsoft.com/en-us/library/ms252199.aspx) of ReportViewer.ServerReport or ReportViewer.LocalReport to render into a Response OutputStream.
Otherwise, you need to peek into the JavaScript in the ReportViewer's IFRAME using IE Developer Tools (F12 in IE8). It needs to perform an additional callback to the server to have it render the report in the selected format. Adapt the actions this script performs.
Why not just use the report scheduling feature to automate it? You can enter subscriptions for the report and it can be delivered on a schedule. There are two delivery methods with SSRS out of the box - email and file share. You can even write your own custom delivery extension.
How much access do you have to SSRS? If you can get pretty much carte blanche, you could setup SSRS to export the report at intervals to a specific location. If SSRS can't hit that location, you could set up SSRS to email the report--from there it is an easy jump to making email dump to location. Either way, there are better angles than "auto click OK" screen-scraping UI automation.
I'd look into the web services. If they can't get scheduling right, they probably didn't get around to turning those off either. Setup a command line app to suck the reports off the services and life will be grand.
It sounds as if you need to treat the reporting service as if it is completely external. Perhaps WinBatch would help you script interaction with the windows? http://www.windowware.com/

WebBrowser control: How to overwrite URL property

This is a bit special:
I'm loading some HTML in string form into the WebBrowser control via the DocumentText property.
Now when I print the page with a PDF printer (Bullzip PDF Printer in my case) it always takes the URL as document name which is "about:blank".
Is there any way to change this to another value by either changing the URL property (it's read-only) or by changing the print behaviour to use another text rather than the URL as filename?
There are a couple of options that I am aware of though my knowledge on this subject is a bit dated.
The first is to change the computer settings in Internet Options. Regardless of whether this is done by hand or through a registry change script, it is simple for the developer, but obviously not the best approach from the deployment or compatibility angles.
The next approach is to develop a custom print template. This is not fun, but is probably the most professional approach. As much as I would love to include all of the information needed on this approach in this post, it is too much to cover. Here is a good overview and good luck Googling from there.
My experience with this involved printing from the MS WebControl component used in a .NET 1.1 Winforms application to the Web Super Goo PDF converter component. Your mileage may vary.
You can change the header and footer such that the URL property is not printed.
Try to Navigate to a URL, then cancel that via DWebBrowserEvents::BeforeNavigate

Categories

Resources