"Silent" Printing in a Web Application

76,337

Solution 1

Here’s what you need to do to enable Firefox immediately print without showing the print preferences dialog box.

  1. Type about:config at Firefox’s location bar and hit Enter.

  2. Right click at anywhere on the page and select New > Boolean

  3. Enter the preference name as print.always_print_silent and click OK.


I found that somewhere and it helped me

Solution 2

As @Axel wrote, Firefox has the print.always_print_silent option.

For Chrome, use the --kiosk-printing option to skip the Print Preview dialog:

Edit the shortcut you use to start Chrome and add "--kiosk-printing" then restart Chrome.

Note: If it doesn't work it is most likely because you did not completely stop Chrome, logging out and back in will surely do the trick.

Solution 3

We struggled with a similar problem. We needed to print checks to a check printer, labels to a label printer, and customer invoices to an invoice printer for retail store embrasse-moi. We have dummy computers, nooks, ipads, iphones with no printing capabilities. The printing an invoice feature was basically a silent print. A pdf was written to the server, and a shell script was used locally to retrieve it and print.

We used the following for a perfect solution with minimal libraries:

  1. use TCPDF in PHP to create PDF. Store the PDF on the server. Put it in a 'Print Queue' Folder. Kudos for TCPDF, a bit difficult to learn, but SICK SICK SICK. Note we are printing 80 labels per page using avery 5167 with a bar code with perfect accuracy. We have a labels, check, and invoice print queue. Different folders basically for different printers.

  2. Use the included shell script to connect to the server via FTP, download the PDF, delete the PDF off the server, send the PDF to the printer, and again, delete the PDF.

  3. Using a local computer attached to the printer, run the script in terminal. obviously modify your printers and paths.

  4. Because you always want this running, and because you use a MAC, create an 'app' using automator. Start automator, put the script in a 'run shell script' and save. Then stick that app in a login item. See the script below the shell script if you want to see the 'output' window on the MAC.

BAM - works sick.

Here is the shell script

#!/bin/bash

# Get a remote directory Folder
# List the contents every second
# Copy the files to a local folder
# delete the file from server
# send the file to a printer
# delete the file
# compliments of embrasse-moi.com


clear               # clear terminal window

echo "##########################################"
echo "Embrasse-Moi's Remote Print Queue Script"
echo "##########################################"

#Local Print Queue Directory
COPY_TO_DIRECTORY=/volumes/DATA/test/
echo "Local Directory: $COPY_TO_DIRECTORY"
#Priter
PRINTER='Brother_MFC_7820N'
echo "Printer Name: $PRINTER"

#FTP Info
USER="user"
PASS="pass"
HOST="ftp.yourserver.com"
#remote path
COPY_REMOTE_DIRECTORY_FILES=/path
echo "Remote Print Queue Directory: $HOST$COPY_REMOTE_DIRECTORY_FILES"

echo 'Entering Repeating Loop'
while true;  do

    #make the copy to directory if not exist
    echo "Making Directory If it Does Not Exist"
    mkdir -p $COPY_TO_DIRECTORY
    cd $COPY_TO_DIRECTORY

    ######################### WGET ATTEMPTS ############################################
    #NOTE wget will need to be installed
    echo "NOT Using wget to retrieve remote files..."

    # wget --tries=45 -o log --ftp-user=$USER --ftp-password=$PASS ftp://ftp.yourserver.com$COPY_REMOTE_DIRECTORY_FILES/*.pdf

    ######################### FTP ATTEMPTS ############################################
    echo "NOT Using ftp to retrieve and delete remote files..."
    #This seems to fail at mget, plus not sure how to delete file or loop through files
    ftp -n $HOST <<END_SCRIPT
    quote USER $USER
    quote PASS $PASS
    cd $COPY_REMOTE_DIRECTORY_FILES
    ls
    prompt
    mget *
    mdel *
END_SCRIPT


    echo "Examining Files in $COPY_TO_DIRECTORY"
    for f in $COPY_TO_DIRECTORY/*.pdf
    do
      # take action on each file. $f store current file name      
      #print
      echo "Printing File: $f To: $PRINTER"
      lpr -P $PRINTER $f

      # This will remove the file.....
      echo "Deleting File: $f"
      rm "$f"
    done
    echo "Script Complete... now repeat until killed..."
    sleep 5
done

and the automator script if you want to see output, keep the app with the script choose a run apple script option:

on run {input, parameters}

    tell application "Finder" to get folder of (path to me) as Unicode text
    set workingDir to POSIX path of result
    tell application "Terminal"
            do script "sh " & "'" & workingDir & "script1.sh" & "'"

    end tell

    return input
end run

Solution 4

Here are two code samples you can try:

1:

<script>
function Print() {
  alert ("THUD.. another tree bites the dust!")
  if (document.layers)
  {
    window.print();
  }
  else if (document.all)
  {
    WebBrowser1.ExecWB(6, 1);
    //use 6, 1 to prompt the print dialog or 6, 6 to omit it
    //some websites also indicate that 6,2 should be used to omit the box
    WebBrowser1.outerHTML = "";
  }
}
</script>
<object ID="WebBrowser1" WIDTH="0" HEIGHT="0"
CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2">
</object>

2:

if (navigator.appName == "Microsoft Internet Explorer")
{ 
  var PrintCommand = '<object ID="PrintCommandObject" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>';
  document.body.insertAdjacentHTML('beforeEnd', PrintCommand); 
  PrintCommandObject.ExecWB(6, -1); PrintCommandObject.outerHTML = ""; 
} 
else { 
  window.print();
} 

You may need to add the site/page you are testing on to you local intranet zone.

Solution 5

I know this is an older thread, but it's still the top Google search for 'silent printing' so I'll add my findings for the benefit of anyone coming across this now.

We had a similar issue with printing labels of various types to various printers for a stocksystem. It took some trial and error, but we got around it by having the system create a pdf of the labels, with printer name and page qty's encoded in the pdf. All you then have to do is: IN IE, go to Internet Options >> Security >> Trusted Sites >> Sites Clear 'Require server verification (https:) for all sites in this zone' add "http://[yoururl]" and the pdf will print out automatically.

When we originally set this up we were using Chrome as the default browser, but in September 2015, Chrome dropped the ability to run NPAPI plugins. This meant that you could no longer select the Adobe pdf plugin as the default pdf handler, and the built in pdf plugin does not handle silent printing :-( It does still work in Internet Explorer (IE11 at time of writing) but I've not tried any other browsers.

HTH Cheers, Nige

Share:
76,337

Related videos on Youtube

Bill
Author by

Bill

(your about me is currently blank)

Updated on February 16, 2020

Comments

  • Bill
    Bill over 4 years

    I'm working on a web application that needs to prints silently -- that is without user involvement. What's the best way to accomplish this? It doesn't like it can be done with strictly with Javascript, nor Flash and/or AIR. The closest I've seen involves a Java applet.

    I can understand why it would a Bad Idea for just any website to be able to do this. This specific instance is for an internal application, and it's perfectly acceptable if the user needs to add the URL to a trusted site list, install an addon, etc.

    • noamtm
      noamtm over 12 years
      What's the solution that worked for you?
    • Bill
      Bill over 12 years
      We ended up using a Java applet. It was a nightmare. Normally it would have been awful, but as this was for the 2008 Beijing Olympics, the added distance & language differences made it a nightmare. In the end, it worked "enough." But again, nightmare. I would not recommend it.
    • tresf
      tresf about 8 years
      If you've stumbled here only to find the Java applet route doesn't work very well any longer, here's a good discussion about it: stackoverflow.com/questions/27057816
    • shareef
      shareef over 7 years
      i need when opens a pdf in browser prints automatically any ideas
  • Bill
    Bill over 15 years
    No, it's an internal application in the sense that it's available to the general public, but it will be at places like various retail chains, etc.
  • aron
    aron about 12 years
    This works! Thanks. Anyone know if you can do this is any other browser too?
  • Admin
    Admin about 9 years
    What about IE and chrome?
  • timbrown
    timbrown about 9 years
    you have to make sure all chrome processes are killed (hangouts, etc..) This one always tripped me up when I couldn't figure out why my start-up flags weren't getting recognized. --disable-print-preview is another way to bypass the chrome preview window and get the default system print dialog options by default.
  • mmu36478
    mmu36478 about 7 years
    Does developer.chrome.com/extensions/printerProvider offers a solution to print silently in chrome?
  • pmiguelpinto
    pmiguelpinto over 5 years
    to restart chrome put chrome://restart in the url bar and hit enter
  • Simant
    Simant over 4 years
    In my Firefox browser, it's now not showing the Print dialog. Thank you so much. However, it's showing me to enter "File name" in Save As dialog. Any idea how to fix that? :)
  • Simant
    Simant over 4 years
    How to achieve this on the Microsoft Edge browser?