Bulk print in javascript/php? - javascript

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>

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

Is it possible to using web api and open a local folder? [duplicate]

We are currently looking at porting a enterprise silverlight application over to html5. The major roadblock that we have hit is the ability to open files from the user's local disk. Currently they have a document library which just links to files on their computer that they can open from within the app and view or print out. All that I read is that you can only access the local sandbox of the web app with the html5 file api's. We want to load these files from code.
Does anyone know of any workarounds to this?
Thanks
There is no way for html5 to access local file without user selection. But FSO: FileSystemObject works for IE and MAYBE could be regarded as a work around. But still there are some requirements to meet.
It is possible to use chrome's filesystem API to access files on a users local filesytem. So you'd have to be willing to make this a chrome only application.
Using java you can create a "Signed" applet which has access to the local filesystem. (if the applet is signed you can request filesystm permissions)
then there is a tutorial for accessing methods of your java code directly from javascript here: http://docs.oracle.com/javase/tutorial/deployment/applet/invokingAppletMethodsFromJavaScript.html
you should be able to perform something similar from silverlight.
There is no workaround in pure HTML5/Javascript. You need the use of plugins, such as Java or Silverlight (maybe you shouldn't port it after all). As for workarounds, HTML5 gives you an easy way drag and drop multiple files that you could transfer on the server and then display back to your users. Another workaround would be to install a custom agent (a software with only a tray icon) that would send the information about the current user "document library" to server and then again, you could display it back to the user.
Note: I've heard somewhere that browsers will eventually stop supporting plugins. http://www.howtogeek.com/179213/why-browser-plug-ins-are-going-away-and-whats-replacing-them/
Ya, I agree with Markain. However, if you were to limit your audience solely to chrome users, I daresay, you would most likely use some of your users. If Huazhihao is right, then your number of leaving customers should decrease but users who regularly use firefox won't be happy. Overall, I think that this will not work. Otherwise, there would be too many websites that trashed your hard driver (or at least wherever you have the rights to edit/delete files). I think it would be best if your product was setup to synchronize the file whenever an internet connection was detected and a change was made to the file. That way the user would not need to visit the website whenever the file was uploaded. If this is some kind of an error file, then it would be most beneficial if you were to make a link in the application that when clicked, would upload the file to the website and the website were to do whatever was necessary. If this is a purely online thing, then I don't see what business you would have looking through other peoples' files =-). Hope I helped!

How to ensure that JavaScript page does not communicate

I created a small JavaScript application for which I reused some (quite large) JavaScript resources that I downloaded from the internet.
My application runs in the browser like other interactive web applications but works entirely offline.
However, I intend to enter some private information in the application which it shall visualize. Since I cannot ultimately trust the JavaScript pieces that I downloaded, I wonder if there is a JavaScript option to make sure that no data is downloaded and, in particular, uploaded to the web.
Note that I am aware that I can cutoff the local internet connection or perhaps change browser settings or use an application firewall, but this would not be a solution that suits my needs. You may assume that the isolation of a browser instance is save, that is no other, possibly malicious, web sites can access my offline JavaScript application or the user data I enter. If there is a secure way to (automatically) review the code of the downloaded resources (e.g. because communication is possible only via a few dedicated JavaScript commands that I can search for) that would be an acceptable solution too.
You should take a look at the Content Security Policy (CSP) (see here and here). This basically blocks every connection from your browser to any other hosts, unless explicitely allowed. Be aware that not all browsers support CSP, which leads to potential security problems.
Reviewing the library code might be difficult because there are many ways to mask such code pieces.
Find it yourself by watching your browser's network activity while your application is in action.
There are more than enough tools to do this. Also, if you know how to use netstat command line tool, it is readily shipped with windows.
Here is one cool chrome extension which watches the traffic of the current tab.
https://chrome.google.com/webstore/detail/http-trace/idladlllljmbcnfninpljlkaoklggknp
And, here is another extension which can modify the selected traffic.
https://chrome.google.com/webstore/detail/tamper-chrome-extension/hifhgpdkfodlpnlmlnmhchnkepplebkb?hl=en
You can set the filters and modify all requests/responses happening in your page.
If you want to write an extension to block requests yourself, check this answer out.

Direct Print RDLC report on client PC in ASP.NET

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.

Least complicated way to get full file paths with Javascript

This has been asked a lot of times already: I need to get the full file path via a web-page. The use case is an application running on the same machine as the browser (i.e. the application starts a local HTTP server and fires up the browser.) File-paths are of course valid and the same for both client/server now. The use case it that the user selects a file and then the server process does some computation on it, and the input files are typically large (read: several GiB in size.)
The easiest thing would be to directly access the path using , but for security reasons, this is disabled. I'm looking now for the least intrusive workaround to this problem. The target browser in question is Chrome. I'm fine if the user has to click "accept" once on some security warning, as long as I can ensure that it won't appear again.
Do I have to write an extension, NSPlugin, can I use some special header magic to mark my page as "local", is there some security setting I can set? The less the client has to do the better, and I would prefer some "click here to allow access ..." solution above everything else. Can I directly install an extension from the server process that would do this (after the user clicks accept?)
Is it possible to do this with a Java applet/Flash? That would be the easiest solution, and clients are guaranteed to have Flash installed (as it is bundled in Chrome...)
You can create Java applet for tasks like this and self-sign it. User will have to allow it to run, but then you will be able to access applet's function that will return file path string via Javascript.
Clearly file io on the client's system is forbidden from JavaScript. If this wasn't the case it would be absolutely trivial to hack every web browser that visits your website.
Battlefiled 3 is controlled though the browser. To do this EA wrote a browser extension for the top three browsers. But that's resource intensive. If you just care about chrome you can use an addon, and for that i suggest using the NPAPI.
And as MOleYArd said, Java is a good solution and probably more common than an extension or addon.

Categories

Resources