I have an ASP.NET 2.0 (C#) webpage with a link that pulls a blob from a MS SQL database and ouputs it in the appropriat file format, i.e., Word, WordPerfect, PDF.
My users would like to print these files with one click. Right now they have to click the link to open the file, then click the "Print" button within the application that they file opened.
In addition, I would like to send multiple documents to the printer, using one click, if possible.
Thanks.
Do you want to print to a Printer attached to the Server, or attached to the client?
If you want to print on the Client, you won't have much chance. For HTML Content, maybe some JavaScript or Flash could trigger the Print Dialog (not sure), but if it's a File that has to be opened in a third party application (i.e. PDF, DOC, XLS etc.), you're out of luck.
If it's an internal Network, you could possibly create a Desktop Application that is installed on every Client's PC that then triggers the Print.
If it is a Printer Attached to the Server, you can use the standard .net facilities for Printing, although you again may have to work around situations where you are trying to print PDF/DOC/XLS etc., because then you need to use Automation (either COM or something like SendKeys), which will cause you headaches on a Server.
So in Short: Not much you can do with only ASP.net at your disposal.
The closest I've gotten to this is using Javascript:
<body onload="window.print()">
...
</body>
which will pop-up the print dialog when the page loads (see this post for more). If you think about it, you probably won't be able to do much else unless you are on an internal network. How would you like your computer to start printing pop-ups "automatically"?
Related
I have hundreds of PDF files that i need to present to users. When presenting these files through my MVC web app i don't want the users to have the ability to download the files, e.g.. i don't want the Acrobat reader controls for print/save showing up. Reading this stackoverflow post it seems that it's not possible to disable those controls.
I know users can still take screen shots and print out the page, but that's not an issue in my case.
What is the best way to go about this. I've reasearched using SWFTOOLS which looks like it may be a good solution, but i dont want to save the swf files to my filesystem. The optimal solution is PDF.js, but another problem i have is users will be accessing the files through IE8 - so PDF.js is out of the question. Unless there is another similar library that will convert the files to HTML 4.
Basically I just need to display the PDF files, on the fly would be best, in a different format than PDF
Any suggestions?
I had a similar project a while back, where sensitive pdfs were needed to be displayed to specific users but they weren't allowed to download/print/save it.
Since it was a web app I ended up using pdf.js. It is Mozilla's PDF renderer for firefox. It renders the pdf on to a canvas and by default has all the bells and whistles. If you have firefox, open a pdf file to see it in action.
It was tough to get it running at first but I ended up using a demo I found online as the base of the project. After removing each functionality that was forbidden the finished product did exactly what was required. You will need to add a print css file to block printing or find a better solution. I ended up using the css approach since print preview by passed my javascript check for the print action. Also ensure you block ctrl + s which allows the user to save the pdf.
Another aspect to note is that it works better on later versions of IE and struggles on older versions as the file size increases. Firefox and chrome are not a problem and I believe its the same for opera although I haven't tested that.
I would convert it to an image file, you can find tools or write script to do it, I personally would do it by displaying them in browser first and then use browser plug-ins to take screenshot of the entire webpage.
(you can automate this)
then just display then converted pdfs
**this is probably not the best solution :( **
How to disable the pdf Toolbar because I don't want to give the download option to the pdf viewers.
I have used Iframe for showing Pdf File please find the following code
<iframe ID="iFrame2" runat="server" align="bottom" frameborder="2" name="iframe1" height="500" width="600" src="~/pdffiles/example.pdf"></iframe>
Please help me to disable the download option using c#.
Thanks
You cant. It is a browser feature which means you have no control over it.
You can use third party tools like Google Document Viewer or change the format of your document to an image.
Google Document Viewer
If you want to avoid that an end user saves a PDF document, you are asking something that is impossible. The only way to avoid that an end user doesn't have a copy of the PDF is by not sending him the PDF. A PDF can't be opened in Adobe Reader without having the actual bytes on the disk. Even if you would disable saving (for instance in the context of a web application), you'd always find the PDF somewhere in the temp files and people would be able to copy that file as many times as they want.
Trying to hide the toolbar (a viewer preference) doesn't make sense. Whether or not this viewer preference will be respected entirely depends on the PDF viewer. For instance: in Adobe Reader X and later, you have a special widget (HUD or Heads Up Display) that appears when you hover over the document. This widget allows users to save the document.
Let me quote Adobe:
the "Heads Up Display" (HUD) is not customizable. There are no APIs to
HUD. You can’t use JavaScript to enter Read Mode, exit Read Mode or
detect that the document is in Read Mode. Though it might seem like
it, this wasn’t an oversight. There are some very sound engineering
reasons why this is the case but I won’t go into those here.
Even with Adobe Reader 9, hiding the toolbar isn't sufficient: if the user chooses the appropriate menu item or hits the appropriate "hot key", the toolbar would appear and they could happily click the Save button. In addition, they could have right-clicked and chosen "Save" as well.
In short, you're asking the wrong question (and that probably explains the downvotes given by several people).
I'm using EPPLUS to allow users to download data to Excel.
However, I'd like to add a feature wherein they can just choose to print this data rather than download it. Can we issue a print command from EPPLus?
It is a web app
Ah, so there's the main problem... You know, even if EPPlus had a method for printing, it wouldn't help you, because it would try to trigger a printing dialog on the server-side, but you need to send the file to the client over the internet. So I'm afraid the answer is no, the client surely has to download the file either way to be able to print it.
Furthermore, xlsx can't be that easily opened in the web browser (compared to pdf for instance), so the solution to somehow trigger a printer dialog on the clients pc will be a tiny bit difficult. C# can't trigger anything over the internet with asp.net because of the security problems and I'm not really sure if javascript has enough permissions to open an application for Excel file and start the printing process..
Maybe your solution would be to create a PDF file instead of XLSX, send it to the client as a part of the website/response and use javascript to print the file. PDF can be opened in most browsers nowadays and we have a nice js function printWithDialog(). I believe this doesn't work for xls and it certainly doesn't fulfil your requirement "without download". The client has to have the access to the file before he can print it, you can't overcome this.
This is what I have done:
I have loaded a pdf file in web browser,
Now I want to select text from that file and paste into a text box.
Can anyone help me?
I'm pretty sure that this is going to be prohibitively difficult, if not impossible, to do.
The browser does not 'run' the PDF, it acts as a host for the PDF application, which ends up sharing it's main window. After that, control of the cursor etc passes to the PDF application and the browser is effectively no longer aware of what happens inside it. If the PDF application being used exposes COM interfaces for manipulating the cursor/text selection (doubtful), then it's possible to script against those interfaces from client script - but you won't be able to actually run any script in that window because the browser is showing a PDF, not a web page.
It might be possible if you hosted the web control on a windows forms application, but even so I wouldn't even know where to start on that one.
If your goal is to extract text from the PDF then you're probably better off pushing it through a .Net PDF library. A quick google on that one will yield you some suitable libraries.
if your pdf file has form elements then the file can be submitted to a url.
check this link.. it might help.
Can a PDF fillable form post itself to an HTTPS URL?
Suppose in .NET (don't care what language) I want to show a user a PDF, Word and Excel file together. I am trying to replicate a document process where a user might have a PDF file and he would like to attach a WORD file and an Excel file let's say to make a stack of documents (that I would save in some directory). Then he would like to click on a button and see a stack of these documents in 1 application of some sort.
How can I display the stack of documents WITHOUT first opening WORD, then openinig EXCEL and then openining ADOBE ACROBAT - this would be really annoying for the user. I would like one unified application or some idea to mimic one in .NET that can just show all 3 documents as if they were printed one after the other on paper. (I hope I am explaining this clearly)
The only thing I can think of to do this would be to leverage some sort of PDF conversion process to create one PDF file containing all three of these documents in "printed" (page-by-page) form, and then show that. The one application I can think of that could show all of these files is a web browser with appropriate Office and Acrobat viewer plugins, and you might find it difficult to leverage that, as browser preference and other user OS settings can cause various strategies for application launching to fail.
I would convert the documents in PDF and develop a pdf viewer inside your application.
I would use a ready made library for that, don't reinvent the wheel.
For example: http://www.quickpdflibrary.com/products/quickpdf/index.php