Print command in EPPlus? - c#

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.

Related

MVC Excel Interop

I have an MVC app that uploads an XLS file and imports it. Ther main issue is that these will often be password protected.
Unfortunately we can't have Office on the server so interop is not an option server side.
I was thinking that when the user browses to the file via their browser and clicks import that I could some how transform the file into plain old CSV before it actually gets to the server at which point I could do the main import. It's an intranet app so the clients will have Office.
So the question is, is there anypoint between the users selecting the file annd clicking upload where the file will be available for me to process on the browser side (where interop would be available) to transform the file?
No. You can't interact with programs on the clients machine (except with browser addons like ActiveX, don't go there). And you should definitely NOT use Interop on the server.
I would suggest to use EPPlus. It can read/write Excel files, without actually the need of interop. It only works with XLSX documents, so I hope it suits you. Else you might need a third-party library that is capable of reading XLS files.
As per Patricks answer you can't interact with a program on a client machine. An alternative to EPPlus is NPOI which is similar in that it removes the need for interop however it works with either XLS or XLSX documents.
Ended up using Syncfusion which does the job nicely.

How to convert PDF files to swf or HTML for viewing in C# MVC 4.5

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 :( **

Automated copy of selected text in pdf file loaded using web browser control in c#.net

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?

generate a pdf file an asp.net(ajax) c#

I have a web page in which user has to enter many details.
I want to fetch the records that are being entered by the user and generate a pdf file, and also preview it in a browser.
I also want to save the pdf into the database.
Can anyone help me to understand how this process should start?? I mean how should I proceed?
I am using Visual Studio 2008 and mysql. I have adobe reader installed on my system. What else do I need?
Can I get the tutorials or code samples which will help me.
thank you
Adobe Reader is just what it says, a Reader application, and will not help with generating a PDF. I recommend you to have a look at iTextSharp
You'll need a third party library for the pdf generation, such as Report.net or ITextSharp.
The problem I see with browser preview, is that I don't know of a good way of doing it. If you just want to show them the data that goes in to the PDF, then just displaying that on a web page is easy enough. The problem is previewing the actual PDF. That will require the user to have some sort of PDF reader installed, and it will also require that their browser opens the PDF automatically and doesn't try to save it instead. It also has the problem of how the user will "get back" to your website once they're done with the previewing.

ASP.NET: How to send file from database to printer?

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"?

Categories

Resources