Control Printing in ASP.NET Page - c#

I need to create a web application that prints checks. Because of the nature of the program, it needs to be very secure, and each action needs to be logged. I need to be able to generate a check, print a check, allow reprints if needed, etc.
I've got the generation of the checks completed. I've decided to make a PDF (so that i don't get any browser header/footer garbage). What I'd like to do is not even save that PDF to a file but to instead send the data directly to a printer. Basically, I'd like for the user to enter the amount of the check, select which account it's going to be printed for, then click a button that sends the data for that check directly to the printer. I don't even want the user to be able to view the PDF of what's to be printed.
Has anyone done something similar to this in ASP.NET?
Thanks.
[EDIT]
The original question I asked was answered with ActiveX controls. I, however, decided to do it a different way. Instead of printing a PDF, I've decided to create an image of the background of the check. I will then use that image (.jpg), and manipulate it by placing the appropriate text (MICR line, amount, check date, etc.) on it using System.Drawing.Graphics and stored X,Y coordinates and font preferences in my DB. From there, I can use the System.Drawing.Printing namespace to send the new .jpg file to a network printer from the web server, eliminating the need for an activeX control and further tightening security because the new image of the finished check is never saved, and the user never has access to the overlay of the check.
Thanks for your help.

If you look at how postal services tackle this problem, you'll notice that a simple web application won't do. To have control over how and when items are sent to the printer, ActiveX compontents or Java software is used.
[Edit]
Small clarification: I ment that the software has to run on the client-side as opposed to your suggested server-side suggestion.
If you want to go the .NET route, you're down to an ActiveX in Managed C++ or a Click-Once application that is launched from the web (allows more of the .NET language, but can be decompiled and altered).

We have implemented this scenario in a couple of ways. First, we have the traditional PDF solution, where the server generates the PDF print image, returns it to the browser which is then displayed via the PDF plug-in and optionally printed.
Second, we wrote a client-side ActiveX component to handle the print. Pass the input values to a backend web service which uses FOP to format the print into PCL. The PCL is passed back to the ActiveX component who then sends the PCL directly to the users default printer. No PDF required here.
Either way works, but only the second option - which will require you to implement some client-side piece - meets all your requirements.

There isn't really a way to do this. You can only send a document to the user which the user can then send to the printer. There are ways to prompt the print dialogue to pop straight up, but the web would be pretty insecure if you were allowed to control how data was managed on the user's machine.
NKCSS is right that it would require software actually installed on the user's machine. You have done as much as you can by making it a PDF that the user is prompted to print.
If you had the cheque as html, you can used styles to show/hide content just for the printer as discussed in this post: here

There's no way to do this completely securely. Even if you force the PDF to print directly to the user's default printer, that itself could be a PostScript or PDF printer like PDFCreator. So they could still get a viewable PDF in the end.

Related

Picture Preview with input type "file" that works in all versions of IE (8 and up), using WebMatrix (C#) and/or JavaScript/jQuery

How can I get Picture Previews to work with IE 8 and up?
Can I get binary image data from an input type "file", with JavaScript/jQuery?
If I can just get the data (in the right format) back to the server, I should be able to work with it there, and then return it with AJAX (although, I am absolutely no AJAX expert).
There is, according to the research that I have done, NO WAY to get picture previews in all IE versions using only javascript (this is because getting the full file path is seen, by them, as a potential security risk). I could ask my users to add the site to the trusted sites, but you don't usually ask users to tamper with those kinds of low-level settings (not to mention the quickest way to make your site seem suspicious to users is to ask them to directly add your site to the trusted sites list. That's like sending an email and asking for a password. "Just trust me! I'm soooo safe!" :)
I have picture previews working in everything except IE and have no problem using conditional comments to separate an IE specific way of doing this from the way I am doing it with other browsers. In other words, the answer doesn't even have to be cross-browser, just cross-IE (8 and 9). I know I have seen IE sites use picture previews before (somehow), so I know there must be at least ONE way to do this...
So if you need to support IE lower than 10 you could upload the file to the server using some of the existing AJAX upload components (Uploadify, Plupload, Valums AJAX Upload, Bleuimp, ...), generate and store a thumbnail on the server and send the url to the saved image to the client using JSON so that it could display it using an tag. Actually since IE supports Data URI Scheme you don't need to store the uploaded file to the server in order to generate the preview. You could directly return the resulting thumbnail image from your Preview controller action formatted as Data URI Scheme so that you could show it on the client.
Another solution if you don't have the time and resources to implement this functionality is to simply tell your users that if they want to get a realtime preview of the image that they should consider using a different web browser because your site doesn't support IE for this.

How to create a File Upload with progress data?

I'm developing a web (using asp.net and c#) which has a FileUpload control from asp.net. The upload thing works perfect and as far as I know I can't show progress data (%, bytes transfered, upload speed, time elapsed, time left, progress bar) using the FileUpload control from asp.net because its not asyncrhonous.
I've searched a lot (really) on the internet and I didn't find what i'm looking for and too much info has become a big confusion since I'm not sure about what I have to use.
On my web page I have a file named "UploadFile.aspx" which has a FileUpload control and a button that handles the uploading. On code-behind (UploadFile.aspx.cs) I have all the server-side logic (Upload the file into specific folder, store info about that file into a database, etc. etc) and I don't want to change this.
What I need to know is how to show the progress data to the user while is uploading the file? I can't use 3rd party applications because this is for an important commercial site. It's not a problem for me if I have to learn javascript / jQuery / Whatever but really i'm a bit lost and I don't know how to start.
Thanks for your time and your help guys.
There's some pretty cool solutions out there. Granted, you can code your own, but I'd suggest using a jQuery plugin like Plupload. If you need help setting it up, you can read their documentation.
There are lots of lots of demo code are available on the net to show the progress bar with file upload control in c#, most of them work fine on Local system but never work on the live server, Because You CAN'T USE A FileUpload control for what you want to do. When a user POSTs a file, you have to think of it like a querystring parameter. It goes as one Http Request. If you want to do a progress bar you'll want to look into something that can interact with the server asynchronously.
If you don't want to use any 3rd party that relies on Flash / Html 5, please take a look at this article:
http://vanacosmin.ro/Articles/Read/AjaxFileUpload
This is possible (and if you're using .NET 4.5 GetBufferedInputStream will make your life easier), but it is not very easy, as you'll see.
Basically, if you want a file upload with progress bar that is fully compatible with every browser, you need to handle this server side and give an url where the client (the browser) can check periodically for the progress with ajax.

Upload items from user computer to a server asp.net

I don't really know how to explain what I want to do.
I will try to explain what I am doing. I built a website in ASP.NET 4 (WebForms) and I want that my brother will be able to click on a button, choose a file from his computer and it will be uploaded to my server.
I have no idea how to do it. It sounds very hard to do and I am really stuck with this for a few days now.
I don't care if it will be with JavaScript, HTML or C#, I just really need it to work.
There's an ASP.NET control made just for that, the FileUpload control. Here's a handy example.
Note that it's notoriously difficult to style if you want to apply CSS and make it elegant, but there are more advanced ways around that. Also, this won't give your web application access to the client's local files or anything like that, it's just a standard file open dialog box for the user to select a file and upload it.
I also highly recommend doing a lot of input checking when accepting files. File type, file size, etc. are all important.
you have 2 options really.. use a traditional fileupload control (from the toolbox) or use the Ajax AsyncFileupload control.
either way it will allow your brother to upload a file from his computer to your server.

Microsoft Office Word in a web browser

I want to have a Microsoft office word inside a web browser so that i can get the control to format the text and specify proper indentation. I don't want a client side to save the document.
It should be the same as http://www.asp.net/ajax/ajaxcontroltoolkit/samples/htmleditor/htmleditor.aspx but i want an additonal component i.e RULER to it.
Is there a way i can get that kind of control or a MSword control without save button.
Please Help
You won't be able to get a "Word Control" into a webpage (not least since that requires every user of your site to have a copy of Word installed), but you can look into something like CKEditor, which is a WYSIWYG editor written in Javascript/HTML. Getting a ruler in there may be difficult though.
What are you trying to do? I'm not sure what your question is, but what you are referring to is a WYSIWYG editor. There are many versions and options for embedding one in your web page. You mention one already. Here's some more:
TinyMCE
Markdown
YUI Editor
Yes, there is such a MS Office control called aceoffix. It works like calling MS Office from local machine and embeding it in web browser. Users can edit,view and save document online diretly. Developer can also customize these functions, such as disable the "save" button.

How can I make a pdf non-printable programmatically?

How can I make a PDF non-printable programmatically using .net?
Short answer. You can't. You can try to set a DRM parameter to prevent printing, but that all depends on the client's software for rendering the PDF and if it respects DRM or no.
Also, assuming you are able to view a PDF there is nothing preventing the user from taking screen captures of the contents presented in the PDF.
Sure you can prevent printing! Of course you cannot prevent a screen capture, but you can definitely prevent a casual user from printing a PDF in the Adobe Reader. I know in our ActiveReports product when we export PDF you can specify various security options that determine whether the user viewing the PDF can print or not. The developer can specify an admin password that can be used to enable only some users to print, while preventing those without the password from printing.
You can read more about this in the PdfSecurity enumeration documentation of ActiveReports. A code sample is in the documentation here. Follow some links on that page to see more information.
If you want to load an existing PDF and modify usually people suggest iTextSharp. Although I have not used it, other people recommend it highly and I think it will work for this read+modify scenario. I managed to find an example of how you can use iTextSharp to enable/disable the "AllowPrint" and other permissions here.
Sounds like you're really looking for a group policy object in Active Directory that prevents users from printing, perhaps?
update
What prevents said users from emailing the PDF to themselves and printing at home, other than another GPO that prevents attachments with given extensions or over certain sizes?
You've got a number of options depending on the full requirement details but the easiest would indeed be to set password encryption on the document. As some of the folks above mentioned, you can set an owner password and user password to encrypt the document. The owner password basically allows admin level access and fully opens up the document to all operations. The user password opens up the document but access is limited to what you specified at the time of encryption, e.g., if you turn turn off printing rights, then someone who supplies the user password won't be able to print the PDF.
We offer a solution that supports .NET and can easily encrypt and also decrypt PDFs. Here's a link to the API docs if you're interested in giving it a look:
http://www.pdfonline.com/easypdf/epsdk_manual/index.htm?page=reference%2Fpdfprocessorsdk%2Fpdfprocessor%2Fm_encrypt.htm
The idea would be to call the Encrypt() function above and pass a PrintingPerm argument of PRC_SEC_PRINT_PERM_NONE. You can also set other access permissions like modification, copy/paste, etc., if you like.
Hope this helps.

Categories