"Silent" Printing in a Web Application - browser

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.

Here’s what you need to do to enable Firefox immediately print without showing the print preferences dialog box.
Type about:config at Firefox’s location bar and hit Enter.
Right click at anywhere on the page and select New > Boolean
Enter the preference name as print.always_print_silent and click OK.
I found that somewhere and it helped me

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.

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.

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:
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.
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.
Using a local computer attached to the printer, run the script in terminal. obviously modify your printers and paths.
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

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

I wrote a python tsr that polled the server every so often (it pulled its polling frequency from the server) and would print out to label printer. Was relatively nice.
Once written in python, I used py2exe on it, then inno setup compiler, then put on intranet and had user install it.
It was not great, but it worked. Users would launch it in the morning, and the program would receive the kill switch from the server at night.

I have it working all day long using a simple JSP page and the Java PDF Renderer library (https://pdf-renderer.dev.java.net). This works because Java prints using the OS and not the browser. Supposedly "silent printing" is considered a browser vulnerability/exploit and was patched after IE 6 so good luck getting it to work via Javascript or Active X. Maybe its possible but I couldn't get it to work without Java.

I have to be honest, I am kinda thinking out loud here.. But could it not be done with an applet or some sort (be it Java or whatever) that is given trusted permissions (such as that within the Intranet zone) or something?
May be worth investigating what permissions can be given to each zone?
Following a Google, I think you definately have a challenge, so far most of the articles I have seen involve printing to printers connected to the server.
If its internal, would it be possible to route printing from the server to department/user printers or something?

If it is just an internal application, then you can avoid printing from the browser, and send a printout directly from the server to the nearest printer to the user.

I'm on the same issue here, this is what i learn so far.
A.: You need to setup an IPP PrintServer
You have multiple print server implementations you may try.
Hardware IPP print server: like DLINK DPR-1020 or similar, some printer have this functionality builtin.
Linux server with CUPPS : http://www.howtoforge.com/ipp_based_print_server_cups
XP-Pro server with ISS: http://www.michaelphipps.com/ipp-print-server-windows-xp-solution
B.: You need to make your WebApp a client of this IPP Server so you pick-process-send every user's print request to the PrintServer.
PHP::PRINT::IPP is a php lib you may try (it's well tested on cups servers).

You should have a look at PrintNode. They provide a silent remote printing services for web applications. You install a piece of software on the desktop which syncs to their servers. You can then send printjobs using an json request and they are instantly printed out.

Related

Log-in only once using wget multiple times on same ftp-server

Basically, I am using wget on a file containing multiple URLs. I notice that for each line the command I use:
wget -i list_of_urls
and for each row in "list_of_urls" wget does a log-in step to the FTP server that I'm downloading from. It does the log-in step automatically, without me entering any username and password. Each line produces the output
Connecting to ftp.ncbi.nlm.nih.gov (ftp.ncbi.nlm.nih.gov)|130.14.250.13|.21... connected.
Logging in as anonymous ... Logged in!
followed by the file downloading.
Is there any way to log in only for the first row and then using that login to download all the following rows? Since the URLs point to the same FTP server, only different files, it feels like logging in for each row is wasteful.
Edit: changed from "website" to "FTP server" since that was what I actually meant, thanks. Added a sample output of the log-in message.
After some fiddling around I think using the rsync protocol solved the problem. This works in this case since the file host has both ftp and rsync servers containing the same files. I then simply (for small file sizes) use
rsync $(tr '\n' ' ' <list_of_urls) /usrpath/
which was much faster than using wget on the ftps. I had to include the $(tr '\n' ' ' <list_of_urls) since the list of urls had end of line separation, but rsync takes space-separated files in the command line. It seems like the rsync protocol in this case only logs on once and then downloads all files, since it went much faster.
Another problem arises with this method when list_of_urls is very long, which I haven't solved yet.

Load a certain line from a .txt into html

How do I load a certain line from a text document (for example line 546) into a website?
Do it with PHP. Use the fopen(), fread() and fclose() methods. To get a specific line of txt is relative, because the formatting of .txt
Start with w3schools and PHP manual. The best way to figured it out is to try and documentations. In my case it was helpful all the way.
I propose this solution using old technology because you asked to make this work for an old file format (html)! So here it goes! Don't be scared! What we are going to do is use Server Side Includes (SSI) to embed the results of a Common Gateway Interface (CGI) program into a static HTML document by using the "#exec cgi" directive. It sounds complicated but it's pretty simple. We only have to create two files and then make sure the web server is properly configured. Three simple steps! I'll guide you step by step:
1. Create Your HTML File
Your HTML file content would be just this (simply copy and paste into an HTML file on your server using a simple text editor):
<HTML>
<TITLE>Load a certain line from a .txt into html</TITLE>
Here's the content of line 546 in filename.txt:
<!--#exec cgi="/cgi-bin/perl-print-line.pl 546 filename.txt"-->
</HTML>
2. Create Your PERL Script File
The above won't work yet. It depends on a simple program to output your line number. It is perl-print-line.pl by Alvin Alexander, and you can simply create this file by copying and pasting the PERL code below into a text editor too (be sure to place it inside your cgi-bin directory):
#!/usr/bin/perl
# purpose: print a specific line from a text file
# usage: perl-print-line.pl line-number input-file
# use perl argv to verify the number of command line arguments
#ARGV == 2 or die "Usage: print-specific-line.pl line-number input-file\n";
$desired_line_number = $ARGV[0];
$filename = $ARGV[1];
# use perl open function to open the file (or die trying)
open(FILE, $filename) or die "Could not read from $filename, program halting.";
# loop through the file with a perl while loop, stopping when you get to the desired record
$count = 1;
while (<FILE>)
{
if ($count == $desired_line_number)
{
# print line, then get out of here
print $_;
close FILE;
exit;
}
$count++;
}
close FILE;
print "Sorry, I think the line number you entered is greater than the number of lines in the file.\n";
3. Configure SSI On Your Web Server
Now, all of the above will not work unless your web server is first configured to process SSI. All popular web servers can still do it, but you must first make sure it is configured. Per the PerlScriptsJavaScripts.com site,
If your server is a unix/linux server, you can be pretty sure it
supports SSI. SI requires the use of Apache Server software. Most
unix/linux server use Apache. Some Windows server also use Apache, but
most of them use IIS (Internet Information Server). The server
software is not something you can change, and because it runs th
entire server (including other people's web sites) your host will also
refuse to change it for you. They may instead be kind enough to move
your site to anther one of their servers which does use Apache.
Most people will tell you that to use SSI, you must name the page with
a "shtml" extension. While that may be the case initially, you can set
the server to also accept and parse regular "htm" or "html" files.
If you have a Windows server instead of a UNIX/Linux server, then you might find this article by Robert McMurray useful. Most importantly he states,
SSI is not enabled by default on IIS 6. To enable SSI on IIS 6, set
the status for the Server Side Includes web service extension to
Allowed in the Internet Information Services (IIS) Manager.
SSI is not installed by default on IIS 7. To install SSI on IIS 7, see
the Server Side Include topic.
The cmd directive for #exec is disabled by default in IIS 5 and IIS 6.
To enable the cmd directive, see Microsoft KB article 233969.
The cmd directive for #exec is now disabled for SSI files in IIS 7;
you can only use the cgi directive.
Finally, if you are dealing with IIS 7.5 and your SSI directives inside your *.html files aren't being automatically preprocessed, try reading this post.

SSH Keys for the Common User. cannot establish key chain. RaspBerry pi 2 model B

I try to establish passwords-less communication between mpi of my notes by using some video tutorial. However, at some point what I saw at the screen of the tutorial differ from from what I saw on my screen. As a result I fault to establish needed connection. I guess is that video tutorial missed some steps therefore I didn't get expected result. Let me guide you through the steps.
White screen will be screen of the tutor and black will be mine.
So I successfully establish connection between mpiu of notes I can enter exit ssh ls -la and do other things between my notes and mpiu of the notes. However, each time when I enter to the mpiu the system ask me the passwd so this step I wanna get rid of. For that matter:
I generate RSA key for the rpi0 ( my first note ) and ssh-copy it to the rpi1 ( my second note )
I checked that RSA key located on the both notes for mpiu#rpi1 it will be authorized_key file (as far as i'm understand )
for the mpiu#rpi0 it will be files id_rsa and id_rsa_pub
Now I need to make changes in rpi0 .bashrc file to establish key chain ( here problems begun )
3.1. So I went to home directory, I used vim in order to to edit file
3.2. Here I notice some difference in the file of tutor and mine - the tutor said that in the very end I should add some logic. However, in my file there are two fi , the tutor .bashrc file has only one fi at the end.
3.3. So I added logic after the second fi ( I saw that fi it states from finish => } - so probably it is true end )
3.4. that tutor enter command to apply the changes to the system
3.5. the tutor got this everything ok
but I got this
( take a look at the White-tutor---done-----black---mine-.pdf )
My first thought was I just need to download from the given website ( funtoo.org ) needed program and put it in the needed directory. However, the system deny my copy-past procedure by saying that I I have not rights.
So what should I do ? May be I should install the contain of the zip file to my note ( rpi0 ) by using some Linux command through the terminal ?
[RSA-Check-and-bashrc-files-.pdf][1]
[White-tutor---done-----black---mine-.pdf][2]
Everybody thx for attention. I solved the problem by installing needed programs through the terminal as I thought.

Code Behind RStudio Server Export Function

I am currently using RStudio-server on Linux redhat. One nice feature of RStudio-server is that I can export from the server to my Windows desktop. Does anyone know the code behind the export drop-down?
The export function can be found via the Files tab:
(More >> Export...)
I would like use code to automate the exporting of objects. I figured I should be able to perform this export using the system function, but I am having trouble.
Thanks for any help.
I think this post might help you,
Spacedman explains that you can trigger the export by the use of the R function "browseURL", with the URL parameter replaced by the ftp path to the file.
If you absolutely want to trigger this export with a system command, perhaps you could create an R script taking as parameter the file to export and launch that script with the system() function =) Although I can't see clearly the advantages of such a process.
[edit] : After having tried it today, I realise my answer wasn't complete :
If you try the function browseURL on files such as "whateverRscript.r", it will display it in a tab of your browser, rather than trigger the download.
In order to actually make your browser download this kind of file, maybe you can zip it first.
To complete the automation process, just change the parameters of your browser such that it won't "ask everytimes where to stock the downloaded files"
This is what worked for me: run it on Server side. Working browser is required (I used Chrome)
my_data_file_name <- "data.RData"
# set file name
save(Data, file=my_data_file_name)
# save data to file
current_dir <- getwd()
# capture current working directory on server
my_export_file_path <- paste0(current_dir, '/', my_data_file_name)
# create a path for file to export
browseURL(my_export_file_path)
# export to local disk using browser's capabilities

Reproducing the blocked exe "unblock" option in file properties in windows 2003

When I download my program from my website to my windows 2003 machine, it has a block on it and you have to right click on the exe, then properties, then select the button "Unblock".
I would like to add detection in my installer for when the file is blocked and hence doesn't have enough permissions.
But I can't eaisly reproduce getting my exe in this state where it needs to be unblocked.
How can I get the unblock to appear on my exe so I can test this functionality?
This is done using NTFS File Streams. There is a stream named "Zone.Identifier" added to downloaded files. When IE7 downloads certain types of file that stream contains:
[ZoneTransfer]
ZoneId=3
The simplest way to set it is to create a text file with those contents in it, and use more to add it to the alternate stream.
Zone.Identifier.txt:
[ZoneTransfer]
ZoneId=3
Command:
more Zone.Identifier.txt > file.exe:Zone.Identifier
Then, the way for you to check it would be to try to open the Zone.Identifier stream and look for ZoneId=3, or simply assume that if the stream exists at all that your user will receive that warning.
It's also important to note that this has nothing to do with permissions. Administrators see the same warning; it's to do entirely with the source and type of file. The entire stream goes away when users uncheck the "Always ask before opening this file" box and then click Run.
There is a supported API for this, documented on MSDN. Search on MSDN for "Persistent Zone Identifier Object". Basically you CoCreateInstance with CLSID_PersistentZoneIdentifier and request an IPersistFile interface. You then call IPersistFile::Load with the name of the file in question. Next, QI for an IZoneIdentifier interface and use IZoneIdentifier::GetId to obtain the zone of the file. If there was no "mark of the web", you should get URLZONE_LOCAL_MACHINE. The ZoneId of 3 mentioned in the other reply is URLZONE_INTERNET. (The enumeration is called URLZONE and is also documented on MSDN, or see sdk\inc\urlmon.h.) You can remove or change the "mark of the web" by calling IZoneIdentifier::Remove or IZoneIdentifier::SetId and then call IPersistFile::Save. There are more details about all of this on MSDN. Good luck!
Thanks for this it helped me a lot.
You can make the process even easier if you create a batch file with the contents.
echo [ZoneTransfer] > Zone.Identifier
echo ZoneId=3 >> Zone.Identifier
more Zone.Identifier > %1:Zone.Identifier
This will generate the Zone.Identifier for you and mark the file accordingly.
To run it just supply the file name e.g. if the file is called mark.bat
mark.bat myfile.txt

Resources