I'm building a web application that is primarily ASP.NET MVC / Javascript. The application needs to be able to print certain content to a label printer and other content to a standard printer. I'd prefer for the user to be able to select a default printer for each one rather than having to always explicitly select a printer.
Is there a way to save and reload some sort of default printer settings for multiple printers in such an application. I am also open to using Silverlight for the p;rinting features if there is no way to do it via javascript.
Not via JavaScript, no; JS uses the browser's built-in print mechanism, which in turn defers to the OS's default print mechanism.
I know its been 6 years since this question was posted but since it wasn't answered here is what I believe is the best way to solve this issue.
You still cannot manipulate printers from a web browser, but there is a great choice out there called QZ Tray
You have to install a program that will communicate between javascript from your application and your configured printers, allowing you to send RAW printing commands and also HTML to any printer.
You can also print to multiple printers at once and save all printer configuration and parameters inside your web app, so you have full control over your printers.
Browsers do not allow javascript (or any script) to access information about the available set of printers or offer any means to select even a "prefered" printer.
Simliarly Silverlight does not support access to infomation about the set of printers available and does not allow printing API to select a specific printer to.
Related
I working on website for ticketing system where admins need to print tickets via Boca printer. Problem is that Boca use FGL (Friendly Ghost Language) which is a standard in ticket printing.
Is there some kind "secret" where I can be connected, some javascript, or PHP code with some BASH script what I can use to trigger prnting from web page?
Generaly I have a template in HTML format where I put user informations and barcode dynamicly and that need to be printed.
Thanks.
If your Boca is connected via a serial port you would have to resort to some underlaying mechanism to communicate to this serial port from a webpage; node-serial (or a java applet if you're into obsolete technologies) would be a solution.
The programming manual is available here for printing a simple text and cut the ticket you would pass the following command:
Hello World<p>
(replace <p> by <q> if you don't want it to cut the ticket)
If your Boca is connected via USB you can print on it via the supplied driver. A solution would be to generate a PDF with the correct ticket's dimensions and then print it out (the user would see the OS print dialog).
I'm working on a web application - optimized for Google Chrome - which needs write access on the client's PC.
Detailed, it's a Laravel app (but i don't think it's important) which has a button to print fiscal receipt/ticket and the procedure is, that the printer has it's own (windows based) software which runs in resident mode (checking periodically in "C:\tickets\cash.inp" file) - thereby i need somehow to write that file - without prompting the user to save that file.
Possible solutions:
jQuery and Javascript - not possible
HTML5 Filesystem API - not possible
Chrome extension / packaged app - not possible, only writes in LocalStorage (or something like this), not in C:\tickets\
ActiveX - i think it's only for IE
Client App - listening a protocol (like MagnetLink) - is this possible?
Any other ideas? Thanks in advance!
For security reasons it's impossible to write on the user's disk directly. I think the best way to accomplish something like this with an client-side app.
Yes as you have already pointed out you need some utility that can do this for you whenever required.
So, either you can create some small java based utility or .NET to read write the file on user's system and connection to utility using web-socket when required.
I am developing a web application which is displaying pdf files in web browser and i want to put restrictions on printing this document.Is there any way to stop printing to file as i need to print through physical printer only.
Since PDF can be downloaded to computer and than opened with any PDF reader, it means you can't prevent certain functionality of ALL readers.
You still can have your own interface that allows or disallows some functions, but I think printing to file is also browser stuff that can't be controlled using JS.
go through css3 media queries in MDN. You must find print media type in the page. It has some restrictions on page printing. https://developer.mozilla.org/en-US/docs/Web/CSS/#media or https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_started/Media
I have to develop a web page that have a button to print the current web page. How can I achieve this through JavaScript? Or Is there any other scripting language or framework to achieve this easily?
UPDATE
I have to pass some data from my server or my browser memory to the printer driver so that I can use these data to print in a formatted way.
Just call window.print(). That is same as the user pressing e.g. Ctrl + P on windows.
I am developing a web-based POS. Unfortunately, POS must print through a thermal receipt printer (TM-T88IV, Epson). The web application is based on Django. Is there any idea on how the system could automatically print a receipt whenever a user clicks a control in the web application?
I was thinking of creating other services in python for that purpose, but that would defeat the purpose of having a web application, where all you need is a browser, without any extra installation.
The printer is connected to the client by the way, and the printing should be "silently" triggered, which means that there is no need for human intervention. Once the transaction is finalized, the printing should starts.
Any suggestion is welcomed!
I see two ways to accomplish it:
First method - Configure your browser
Notes
Good solution if you have one printer for every client (because you can use the default printer only). Keep in mind that you can remove your print server (useful for very resource limited devices) making a script that the browser should automatically execute for open your file. You can use something like this:
#!/bin/bash
printer="/dev/usb/lp0"
encoding_needed=true #false
if $encoding_needed; then
iconv -c -t 437 $1 > $printer
else
cat $1 > $printer
fi
Firefox
Manual setup:
Open about:config
Create a new boolean value called print.always_print_silent and set it to True
Create a new boolean value called print.show_print_progress and set it to False
Use an extension, like: https://addons.mozilla.org/en-us/firefox/addon/attendprint/
Keep in mind that there are other extensions for making kiosks, for example:
https://addons.mozilla.org/en-us/firefox/addon/r-kiosk/
https://addons.mozilla.org/en-us/firefox/addon/mkiosk/
Chrome
You can start it with those options: --kiosk --kiosk-printing
Internet Explorer
For kiosk mode see: http://support.microsoft.com/kb/154780
Second method - Server handles every printer
Notes
Good solution if:
You have more clients than printers (few money or faulty printers)
More printers than clients (different printers or paper colors for different needs)
Clients that can't print directly (PDA/smartphones)
You want to know the printer status
How to do
Connect printers (to the clients and/or to the server)
Share printers connected to clients over the network
Manage every printer from your Django server
Two options here: print an html page or provide a PDF file.
Note: it was not clear initially that prints should be automatic, which means the answer is not directly useful to OP.
HTML + "Print Me"
Show the receipt as an html page, then create a media="print" CSS stylesheet which the browser will use when printing the receipt. There's a lot to say about CSS print style sheets, but what's important is that you should remove all navigation elements and images that are going to be expensive to print.
When you do this, the user will simply have to print the page himself. You can also add a "Print Me" button which is going to show your user a printer dialog. This is done via JavaScript:
Print this page
(This is a bit obstrusive for your clients who don't have JS, check this tutorial about JS printing for a better way.)
PDF
Generate a PDF in Django, and show it to the user. He will be free to print it or save it on his computer later. Most web sites do this since it's far easier to control the layout of a PDF file, and it will be easier to make it look like a real receipt.
XSL-FO can help you do this (it translates an XML to a PDF with a "stylesheet").
A more Pythonic way seems to be explained in the Django docs
The above pages lists alternatives such as xhtml2pdf (Pisa) which seems to be used a lot on StackOverflow
If using raw/esc/p try jzebra on google code.