Direct Print RDLC report on client PC in ASP.NET - javascript

I have read many articles and answers here regarding this but nothing can solve my issue. That's why I am asking this question again.
I develop a Invoice App in Asp.net. I can't print invoice directly on client PC. It always ask printer preview that irritate client. I have successfully develop a code for directly printing but it only execute on local host only.
Please help me and suggest me what to do as soon as possible.
In Javascript or ASP.NET or something else that can help me.

We use SSRS and generate the report in pdf format on the server. Sending it to the client, we send it with a mime-type:application/x-xyz-printpdf - you also have to set the content-disposition: with filename and I can't recall if inline or attachment value, so that the browser will behave and not simply download and save the file, but will kick off the associated program
the client has a slightly modified version of SumatraPDF, which is associated with application/x-xyz-printpdf in the registry (windows clients only - there's ways to do this in other OS's but all our clients run Windows, so we've never bothered)
This modified sumatraPDF never displays the document, all it does is display a print dialog with the previously selected printer for the report selected. This is so, invoices will default to one printer, other reports to a different printer, it's more of a convenience (and emulates our old non-web-based application)
I am in the process of rewriting the report printing subsystem, using a substantially modified version of PDFjs and blobs, but that's in early development so I can't tell you anything about that, except that it looks like it'll work well, without the need for an external program.

Related

Printing using Nodejs

I am having a really hard time figuring out how I am going to handle printing in my Nodejs application. I have a website where there is a bunch of purchase numbers. I want the users to print this numbers in a click of a button. These numbers are dynamically generated after querying the database.
I started using this npm library to print the purchase number. When I am developing in my local computer this library is working fine. I made it so that each time the user presses a button in the front end, I make a post request to my Nodejs Server which prints to the printer that I configured locally.
The problem is that I want to eventually deploy my website to Heroku. Website will be used by a group of people sharing the same network and printer. I do not know of a way to set heroku to communicate with the printer using this package.
I also thought that printing directly from the front end might be a better idea, but I have to open google on kiosk mode and then do the same for all the users that are going to use this website. Also, most of the users will be using a tablet device so configuring printer in those devices will be difficult as well.
I did not find anything online that I can use as a reference. Any advice or suggestion will be greatly appreciated.
As for nodeJs printing I have no experience. It seems that you can use certain packages to print a pdf as given in the example answer here: Node.js : How to add print job to printer.
As for generating from html to PDF, that should be easy to find, less easy to style correctly though.
I would recommend doing it from HTML (you could still do the PDF conversion for more stable printing results)
From HTML
As stated, the API is rather limited, you can use window.print to request a print action.
Note though that you have some options to make your life better when calling window.print().
You can create the page in a separate window to get rid of bloat, like navigation etc, or you could actually hide that with css.
You might already be aware of css being included for certain targets e.g. for your website you probably want to use the screen target, but you can create a separate stylesheet for printing.
More info at mozilla
https://developer.mozilla.org/en-US/docs/Web/Guide/Printing

Bulk print in javascript/php?

Is there any way to implement bulk/mass print in javascript/php? I searched on web and most of the answers found are for .net and java. I need to queue around 600 documents at a time. I found PECL printer library but the doc says it is only available under Windows 9.x, ME, NT4 and 2000. Does PECL library work under linux server? is it good to go with PECL library or there are any other alternatives?
Controlling the Printer in Windows is not big task as we have many win32api available or entry points can be created to do printing dynamically. As PHP is the server side and JavaScript is Client side scripting language.
Bulk Printing/Printing on Client Side without permission/notification is not possible according to me. Thus, user must authorize the printing job.
Developers have less experience for Printing under Linux. Even me don't know much but I know a way to do it. I have never tried or done it yet. Under PHP doesn't have any inbuilt function of printing/controlling things. There is no extension as such available under PHP to do so also. But under Linux there is command know as LPR (Line printer daemon protocol) which can be used under PHP to do printing, if shell_exec is authorized under PHP to execute shell commands. Command follows a:
shell_exec("lpr -P 'printer' -r 'filename.txt');
You have to go through RFC Protocol for LPR. You have to create the abstraction layer for Daemon for controlling and sending Printing Commands. A Good example for creating daemon is available here.
After going through these things, you would be able to Print documents under Linux through PHP.
Additional Question
Want to do Client Side Printing through Website/localhost
Small Answer
No, you can't control the Client Printer Directly without permission of user and that too depends on every session. So, if you want to get the access is another session you have to get the permission of user again.
Long Answer
Yes, it can be controlled with many tweaks and under certain conditions. As most of the users use windows as providing answer accordingly. But to understand the working of that you have to understand the Print Dialog internals.
Print Dialog is divided into two parts. One is Windows API and other is Printer Drivers. Windows API is the set of common code that is held by various DLL (Dynamic Link Library) that are the part Windows OS. Windows API provide a common interference allowing all Program can use that allowing all programs access to the same set of printer drivers rather than printer manufacturers having to create driver software.
Printer Drivers are created in different languages and they control the different parts of the hardware to send the instructions to printer. The main Printer Driver that control the flow are PCL5 and PostScript etc., Printer Driver changes the custom markup language that the specific printer understands.
So, basically we need the direct access to DLL and through Modern Browsers (Chrome, Firefox etc.) it is not possible but One Browser can Provide the access i.e. Internet Explore which is Part of Windows OS itself.
So, the First Condition is the User must use Internet Explorer and access through other is not known to me. Next thing to get the direct access to the API that can be done through ActiveX Control. In principle it is not dependent on Microsoft Windows, but in practice, most ActiveX controls require either Microsoft Windows or a Windows emulator. Most also require the client to be running on Intel x86 hardware, because they contain compiled code.
So, the ActiveX Controls are accessed through user prompt only. Thus, use have to manually change the control or again user has to provide the access to the web page. If the settings are changed then there is great danger to the computer as it provide access to computer hardware and other components. The computer can be hacked easily. Thus, you have to use it under great cautions. Thus, Third condition is to have a direct access to ActiveX Control.
I have used ScriptX, free version lets you set some basic parameters, see the example below:
<!-- MeadCo ScriptX -->
<object id=factory style="display:none"
classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"
codebase="http://[your path here]/smsx.cab#Version=7.0.0.8 ">
</object>
<script>
function printWindow() {
factory.printing.header = "This is MeadCo";
factory.printing.footer = "Printing by ScriptX";
factory.printing.portrait = false;
factory.printing.leftMargin = 1.0;
factory.printing.topMargin = 1.0;
factory.printing.rightMargin = 1.0;
factory.printing.bottomMargin = 1.0;
factory.printing.Print(false);
}
</script>
I have provided the way to do it and rest you have to do according to your requirements. Once again I would tell you that kindly not change the settings of ActiveX to enable which caused great threat to user. Machine can be easily hacked and great threat to information available in computer.
The PECL printer library is for server-side printing. You have to have the printer connected to the server the script is running on.
If your clients need to do the printing, you cannot use it. You cannot do the "printer queueing" with JS alone. If you are restricted to using the browser only, best way to go about this would be loading out all the pages you want to print in one HTML page with proper CSS page breaks. But beware, there might be browser performance issues depending on the size of that one page.
Another thing you could do is convert that HTML internally to a PDF and then allow clients to print it. This doesn't allow queueing, but serves the purpose.
why don't you use css page-break-before to tell the browser that the content should be in a new page and clone the element as many time as you want
for example
.page
{
page-break-before: always;
}
<div class="page">
something to be printed in a whole page
</div>
<div class="page">
something to be printed in a whole page
</div>
<div class="page">
something to be printed in a whole page
</div>

Saving data to a local file using only JavaScript

The set-up in question:
I have a stand alone, offline, kiosk mode instance of Chrome running on a Windows machine. I have full access to the system and any admin rights. I can start Chrome with any flags set or unset.
The task:
I have been asked to create a log file which tracks user activity within the offline app I am coding. It's a simple form of analytics which will append each event to the end of the file separated with a comma. The file will then be sent to a server once a day via a scheduled task. (None of this is my idea so please don't troll me)
Ruled out:
Any server side code - I have lobbied for Node, PHP etc but as this will be distributed to many different installations so we cannot guarantee this will be installed.
Flash/ActiveX/Java - ideally would like to avoid this (even though these will be installed by default)
Possible solutions:
File API - I have looked at this but AFAIK if opens dialogue boxes to save the data to each file and this needs to happen in the background.
Security - I have read in other SO Questions that this can be achieved if the security settings are reduced but no-one goes on to explain which ones. Is there a simple flag which allows it?
How to enable local file system read write access from Google chrome? - similar question!
Ideal result: (something akin to PHP)
$file = 'log.txt';
$current = file_get_contents($file);
$current .= ",clicked:link";
file_put_contents($file, $current);
Possible ideal side result: proving this isn't possible and forcing PHP/Node/Java to be used ;)
In reply to those suggesting local storage : I'm not storing unique key/value pairs and that is very much like setting a cookie. Similarily there are file size limits.
To those suggesting web SQL such as SQLite in chrome - there are file size limits if it's not a chrome extension. The only way I see that working is if I were to find the location of the file in the windows directory (C:\Users\%USERNAME%\AppData\Local\Google\Chrome\User Data\Default\databases) and upload that from the schedules task. Perfectly feasible but it is not a desirable answer.
You could use HTML5?
http://diveintohtml5.info/storage.html
var foo = localStorage.getItem("bar");
// ...
localStorage.setItem("bar", foo);
You can use the Chrome Apps File API, you will need to grant access to the file via a user action once, but after that you can get access the file again by using restoreEntry
You can use localStorage to save offline data. It's impossible to access other files using Javascript since it's a violation of the sandbox.
From http://en.wikipedia.org/wiki/JavaScript#Security:
JavaScript and the DOM provide the potential for malicious authors to deliver scripts to run on a client computer via the web. Browser authors contain this risk using two restrictions. First, scripts run in a sandbox in which they can only perform web-related actions, not general-purpose programming tasks like creating files.
You may want to look into Local Storage which is part of the HTML5 spec.
This will only be supported in modern browsers though.
If you need to use older browsers then may still be able to achieve what you're after using dojox.storage
Use HTML5 features like Web Storage or Web SQL database to store your logs.
Whenever needed read logs from the client side storage and send it back to the server & delete the client storage.
Refer http://www.html5rocks.com/en/features/storage.

how to open csv file in IE in by javascript

In my asp page, I have to open a csv file in IE by java script. The code which I am using is as below:
csvWindow = window.open("/com/csv/"+csvFileName, "datacsv", "toolbar=yes,location=no,directories=yes,status=no,menubar=yes,scrollbars=yes,resizable=yes,width=790,height=450,screenX=50,screenY=25,left=50,top=25");
Code is running in IIS server.
When I run this code and open csv file it gives below message
Microsoft Office Excel cannot access the file
"http://192.168.3.228:107/com/csv/CSV_file_1345728.csv". There are several possible reasons:
The file name or path does not exist
the file is being used by another program
the workbook you are trying yo save has the same name as a currently open workbook.
But file is being created.So path is correct and i think that file is also not used by another program
Please help me what should I do
The problem is that when Excel is opened it will attempt to fetch the CSV file itself, this a change in behaviour in office apps since 2007. However since Excel runs in a different process it will not send any cookies that would have been generated during the logon. When the website receives the request it will respond with a 401 status.
There are no easy solutions that I know of with entirely satisfactory results. Here are a number of solutions but all have drawbacks.
Make the authentication cookie persistent, this will allow Offices apps to pick up and send the cookie. The down side being the user remains persistently logged even after a client machine reboot (much like how Stackoverflow appears to work).
Use a standard HTTP authentication protocol like "Basic" or "Negotiate". The down side is that this will cause Excel to display a logon box and the user has to logon again. One exception to this drawback is using "Negotiate" or "NTLM" against an IIS box where the site is registered as part of the IE's Intranet Zone, in which case the HTTP stack used by excel will attempt to use the current user credentials.
Have a server side script that can run anonymously send the csv file and include in the URL some unique ID (such as GUID) which is a one off grant of access. Much more complex to set up.
If you want to open the file with MS Excel, you could try not to serve the file directly, but write an ASP page with Content-Type=application/force-download, the real file name ending with .css and the actual file content. In this case, MSIE will first download the file to the local disk cache and then will feed it to MS Excel.
If you just want to show the CSV text in the browser window, maybe the best is to change its extension or to make some proxy page with Content-Type=text/plain and no mention of CSV at all. The association CSV/Excel seems to be hardcoded in MSIE.

Is it possible to "upload" a file only with client side ? (no server involved)

I am trying to do a simple thing:
Let the user choose a txt file, and save its context to be used on the client side only.
no server side needed.
Is it possible ?
Thanks.
It is possible to do so with HTML5 Files API as explained in these resources:
https://developer.mozilla.org/en-US/docs/Using_files_from_web_applications
http://www.html5rocks.com/en/tutorials/file/dndfiles/
I guess you mean "save its content" and conclude you want to do anything with this content on the client side, e.g. extract some parts to fill a form. Anyway saving the whole file unchanged, on the same machine where it comes from, does not make sense.
So the problem is not how to upload, but how to open/read a file. You can do this with a Java Applet, Flash, Silverlight, ActiveX ... just to name a few.
JavaScript is not an option. It cannot access the file system.
If the html page, that is hosting your javascript, is from a remote server. This script is not trusted to do actions on your local filesystem.
<Obscure solution mode level = 1>
You can give more trust to a page, but this is something your user has to do. If this is an app/web only for use within an enterprise, you can probably do this centrally. And every browser handles this differently. So it is not something you can rely on, when you do not have a limited userbase.
<Obscure solution mode level = high>
If your (enterprise) users are using Internet Explorer, you could also create a HTML Application (simply give your html page an hta extension). These pages have full trust, but can only be started from a trusted location, or require confirmation from the user.
The only way you can acheive this successfully is to build an ActiveX type plugin/component (or java applet) you will have much more control of the client machine.
No. JavaScript cannot access the local filesystem.
However, you could install a webserver on your machine and e.g. run PHP on that one. Then you could do it without ever sending your data over a network connection. That would require you to do your data processing in PHP though.. probably not what you want. Or you could simply send back the data to your javascript.. but that'd be pretty awful to run an upload just to make the data available to JavaScript.

Categories

Resources