📜 ⬆️ ⬇️

Terminal Server Scan Free

At work, we set the task of transferring several employees to a terminal server so that everything is done on it, including scanning from a local scanner. The user is working in Windows. It would be possible to forward USB, but drivers for Windows Server did not have this model of scanner.

I searched the network for Scan over RDP, found programs like Scan Redirector RDP Edition, TSX Scan, etc., for which they want around a hundred or so bucks for 1 license, it seems they have even seen for 800 bucks.

I do not like unlicensed software, so I decided to implement myself:
')


Here you see the main page for managing a remote scanner. The advantage of my decision is that there is absolutely no need to install anything on the terminal server (or any other computer from which you want to scan), you just need a browser.

If you click New JPG scan, you will see the following:

image

And then:

image

The picture can be saved by the right button. Click New PDF scan:

image

Click a couple of times Scan PDF next page:



By clicking on the picture we see it in full screen:



Click Delete page 2:



Click Make PDF:



Click Browse images:



Here you can view everything that was scanned before. Somehow it works. Any TWAIN-compatible scanner is supported. Tested in Chrome.

I have little experience in development, so the code is probably written in the worst traditions of all. Kick in the comments.

Security is minimal: so that the scanner is not used by an outsider, the file is called scan57578.php (the name can be changed to something else). And in index.php write "Access denied".

What should I install on a computer with a scanner?

As you may have guessed, we need a web server. I used Denwer , which in this case is from a gun on sparrows, but you can use any other with PHP support. At the same time, it will be necessary to correct the code accordingly, since it uses the Denver paths (the Z: drive, etc.).

What else is needed: the CmdTwain program, which actually scans from the command line, and the console utility jpeg2pfg . Install CmdTwain, run CmdTwain \ Select Source from Start, and select our scanner. Install Denver, agree with everything by default.

Then, on the Z drive, you need to find php.ini and set the parameter max_execution_time = 130. Select the value, measuring how long one scan takes on your scanner. Then Restart Denwer. We take the Start Denwer shortcut from the desktop and throw it into autoload. We set the computer a static IP.

Create a folder in the Z: \ home folder with the name equal to the IP of the computer. In my case, the folder is called 10.74.0.98. In it we create a folder www, and in it a folder in which scans will lie. In my case, it is called scans. The full path looks like this: Z: \ home \ 10.74.0.98 \ www \ scans.

The web server is configured. Next, create a folder Z: \ jpeg2pdf. In it, copy the jpeg2pdf.exe that you downloaded from the link I gave above. And also create a file makepdf.bat in it with the following contents:

@echo off z: cd z:\home\10.74.0.98\www\scans\%1 z:\jpeg2pdf\jpeg2pdf.exe -z none *.jpg -o %1.pdf move *.pdf .. 

Fix the IP on the desired one. This file creates a PDF from a set of JPG. As a parameter, it is passed the name of the folder with this set.

In the Z: \ home \ 10.74.0.98 \ www folder, place index57578.php (or whatever you want to call it) with the following content:

 <?php $ip = '10.74.0.98'; $pagename = 'scan57578.php'; $folder = 'scans'; $jpeg2pdf = 'z:\\jpeg2pdf\\makepdf.bat'; ?> <html> <script> function $_GET(key) { var s = window.location.search; s = s.match(new RegExp(key + '=([^&=]+)')); return s ? s[1] : false; } function gettime() { var d = new Date(); var curr_date = d.getDate(); if (curr_date < 10) curr_date = '0'+curr_date; var curr_month = d.getMonth() + 1; if (curr_month < 10) curr_month = '0'+curr_month; var curr_year = d.getFullYear(); var curr_hour = d.getHours(); if (curr_hour < 10) curr_hour = '0'+curr_hour; var curr_min = d.getMinutes(); if (curr_min < 10) curr_min = '0'+curr_min; var curr_sec = d.getSeconds(); if (curr_sec < 10) curr_sec = '0'+curr_sec; return curr_year+'-'+curr_month+'-'+curr_date+'-'+curr_hour+'-'+curr_min+'-'+curr_sec; } function jpgclick() { document.getElementById('scanprogress').style.display = 'block'; document.getElementById('scanjpg').href='/<?=$pagename?>?scantype=jpg&time='+gettime(); } function pdfclick() { document.getElementById('scanprogress').style.display = 'block'; document.getElementById('scanpdf').href='/<?=$pagename?>?scantype=pdf&time='+gettime(); } function pdfnextclick() { document.getElementById('scanprogress').style.display = 'block'; document.getElementById('pdfnext').href='/<?=$pagename?>?scantype=pdf&time='+$_GET('time'); } </script> <body> <div style="font-size: 150%">     <a id="scanpdf" href="#" style="color: #00C" onclick="pdfclick()">New PDF scan</a>        <a id="pdfnext" href="#" style="display: none; color: #00C" onclick="pdfnextclick()">Scan PDF next page</a>        <a id="makepdf" href="/<?=$pagename?>?scantype=makepdf&time=<?=$_GET['time']?>" style="color: #000; display: none">Make PDF</a><br /><br />     <a id="scanjpg" href="#" style="color: #00C" onclick="jpgclick()">New JPG scan</a><br /><br />     <a href="/<?=$folder?>/" target="_blank" style="color: #090">Browse images</a> </div> <br /><br /> <div id="scanprogress" style="position: absolute; left: 0; top: 0; width: 100%; height: 100%; background: white; display: none"> <h1 style="position: absolute; left: 20%; top: 30%">Scanning in progress. Don't close browser tab.</h1> </div> <?php if($_GET['scantype']=='jpg') { $filename = 'Z:\\home\\'.$ip.'\\www\\'.$folder.'\\'.$_GET['time'].'.jpg'; if(!is_file($filename)){ $cmd = '"C:\Program Files\GssEziSoft\CmdTwain\CmdTwain.exe" "'.$filename.'"'; system($cmd); } echo ('<a href="/'.$folder.'/'.$_GET['time'].'.jpg"><img style="height: 80%" src="/'.$folder.'/'.$_GET['time'].'.jpg" alt="Picture" /></a>'); } if($_GET['scantype']=='pdf') { if($_GET['delete']!='') { $i = -2; $files = scandir($folder.'/'.$_GET['time']); foreach($files as $filename) { $i++; if ($filename[0] == '.') continue; if ($_GET['delete'] == $i) system('del '.'Z:\\home\\'.$ip.'\\www\\'.$folder.'\\'.$_GET['time'].'\\'.$filename); } } else { if (!is_dir($folder.'/'.$_GET['time'])) { system('md Z:\\home\\'.$ip.'\\www\\'.$folder.'\\'.$_GET['time']); $filename = 'Z:\\home\\'.$ip.'\\www\\'.$folder.'\\'.$_GET['time'].'\\0001.jpg'; $cmd = '"C:\Program Files\GssEziSoft\CmdTwain\CmdTwain.exe" "'.$filename.'"'; system($cmd); } else { $n = 1; $files = scandir($folder.'/'.$_GET['time']); foreach($files as $filename) { if ($filename[0] == '.') continue; $t = substr($filename, 0, -4)+0; if ($t > $n) $n = $t; } $n++; $fn = str_pad($n, 4, "0", STR_PAD_LEFT).'.jpg'; $filename = 'Z:\\home\\'.$ip.'\\www\\'.$folder.'\\'.$_GET['time'].'\\'.$fn; $cmd = '"C:\Program Files\GssEziSoft\CmdTwain\CmdTwain.exe" "'.$filename.'"'; system($cmd); } } $i = -2; $files = scandir($folder.'/'.$_GET['time']); foreach($files as $filename) { $i++; if ($filename[0] == '.') continue; echo "<table style='float: left' width='19%'><tr><td><a href='#' onclick='document.getElementById(\"preview\").style.display=\"block\"; document.getElementById(\"prepic\").src=\"/".$folder."/".$_GET['time']."/".$filename."\"'><img alt='Picture' style='width: 100%' src='/".$folder."/".$_GET['time']."/".$filename."' /></a></td></tr><tr><td align='center'><a href='/".$pagename."?scantype=pdf&time=".$_GET['time']."&delete=".$i."'>Delete page ".$i."</a><br /><br /></td></tr></table>"; } if ($i == 0) echo '<div style="position: absolute; left: 0; top: 0; width: 100%; height: 100%; background: white"><br /><br /><br /><center><h1><a href="/'.$pagename.'"> </a></h1></center></div>'; } if($_GET['scantype']=='makepdf') { $cmd = $jpeg2pdf.' '.$_GET['time']; echo '<span style="display: none">'; system($cmd); echo "</span><h1><a href='scans/".$_GET['time'].".pdf'>Download PDF</a></h1>"; } ?> <div id="preview" style="position: absolute; left: 0; top: 0; width: 100%; height: 100%; background: black; color: white; display: none"><img id="prepic" style="position: relative; left: 23%; height: 100%" src="" alt="Picture" /><div style="position: absolute; top: 0; right: 0; color: #FFF"><a href="#" onclick="document.getElementById('preview').style.display='none'; return false" style="text-decoration: none; font-size: 250%; color: white; font-family: arial">X </a></div></div> </body> <script> if ($_GET('scantype') == 'pdf') document.getElementById('pdfnext').style.display = 'inline'; if ($_GET('scantype') == 'pdf') document.getElementById('makepdf').style.display = 'inline'; </script> </html> 

At the top, 4 parameters are specified: IP of the computer with the scanner, php file name, name of the folder with scans, path to makepdf.bat.

Cons: you can not set the quality of the scan - always scans in 200 DPI and in color. It can somehow change the parameters (for example, in the registry), but they are suitable for office tasks.

And yes, I know that the gettime () function can be written shorter and more beautiful. Offer the most beautiful options in the comments.

Added later (thanks to Faramant ):
Scan options can be specified on the command line. Examples from the documentation:
C: \> CmdTwain –c "PAPER LETTER DPI 300 GRAY" ...
or (parameters in from file):
C: \> type map.txt
PAPER A3
DPI 300
COLOR
BR 200.0
C: \> CmdTwain –c map .txt 75 scan.jpg

Thanks for attention!

Source: https://habr.com/ru/post/315160/


All Articles